Skip to content

Commit cacd031

Browse files
committed
Add AMPGO multivariate test functions (Ackley, Rastrigin, Griewank, Sphere)
Implements four commonly-used multivariate optimization benchmark functions from the AMPGO test set as part of addressing issue #236. These functions are widely used in global optimization and provide good test cases for optimization algorithms. - Ackley: n-dimensional multimodal function with bounds [-32, 32] - Rastrigin: n-dimensional highly multimodal function with bounds [-5.12, 5.12] - Griewank: n-dimensional multimodal function with bounds [-600, 600] - Sphere: simple n-dimensional convex function with bounds [-1, 1] All functions follow the standard ADNLPProblems pattern and support arbitrary dimensions and data types. Closes #236 (partial - adds 4 of 184 multivariate problems)
1 parent 1cee776 commit cacd031

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/ADNLPProblems/ackley.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export ackley
2+
3+
function ackley(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
4+
function f(x)
5+
n = length(x)
6+
sum1 = sum(x[i]^2 for i = 1:n)
7+
sum2 = sum(cos(2 * T(π) * x[i]) for i = 1:n)
8+
return -20 * exp(-T(0.2) * sqrt(sum1 / n)) - exp(sum2 / n) + 20 + T(ℯ)
9+
end
10+
x0 = T[-32 + 64 * rand(T) for _ = 1:n]
11+
return ADNLPModels.ADNLPModel(f, x0, name = "ackley"; kwargs...)
12+
end

src/ADNLPProblems/griewank.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export griewank
2+
3+
function griewank(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
4+
function f(x)
5+
n = length(x)
6+
sum_term = sum(x[i]^2 for i = 1:n) / 4000
7+
prod_term = prod(cos(x[i] / sqrt(T(i))) for i = 1:n)
8+
return sum_term - prod_term + 1
9+
end
10+
x0 = T[-600 + 1200 * rand(T) for _ = 1:n]
11+
return ADNLPModels.ADNLPModel(f, x0, name = "griewank"; kwargs...)
12+
end

src/ADNLPProblems/rastrigin.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export rastrigin
2+
3+
function rastrigin(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
4+
function f(x)
5+
n = length(x)
6+
return 10 * n + sum(x[i]^2 - 10 * cos(2 * T(π) * x[i]) for i = 1:n)
7+
end
8+
x0 = T[-5.12 + 10.24 * rand(T) for _ = 1:n]
9+
return ADNLPModels.ADNLPModel(f, x0, name = "rastrigin"; kwargs...)
10+
end

src/ADNLPProblems/sphere.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export sphere
2+
3+
function sphere(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
4+
function f(x)
5+
return sum(x[i]^2 for i = 1:length(x))
6+
end
7+
x0 = T[-1 + 2 * rand(T) for _ = 1:n]
8+
return ADNLPModels.ADNLPModel(f, x0, name = "sphere"; kwargs...)
9+
end

0 commit comments

Comments
 (0)