-
Notifications
You must be signed in to change notification settings - Fork 48
AMPGO multivariate implementation #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arnavk23
wants to merge
6
commits into
JuliaSmoothOptimizers:main
Choose a base branch
from
arnavk23:fix/ampgo-test-set-issue-236
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cacd031
Add AMPGO multivariate test functions (Ackley, Rastrigin, Griewank, S…
arnavk23 0a64e74
Add Meta and PureJuMP implementations for AMPGO multivariate functions
arnavk23 c38d708
Apply suggestions from code review
arnavk23 daa7ad2
Update rastrigin.jl
arnavk23 49dc51a
adding Random to Project.toml
arnavk23 249fb6d
updating griewank
arnavk23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| export ackley | ||
| using Random | ||
|
|
||
| function ackley(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| rng = get(kwargs, :rng, Random.MersenneTwister(0)) | ||
| function f(x) | ||
| n = length(x) | ||
| sum1 = sum(x[i]^2 for i = 1:n) | ||
| sum2 = sum(cos(2 * T(π) * x[i]) for i = 1:n) | ||
| return -20 * exp(-T(0.2) * sqrt(sum1 / n)) - exp(sum2 / n) + 20 + T(ℯ) | ||
| end | ||
| x0 = T[-32 + 64 * rand(rng, T) for _ = 1:n] | ||
| lvar = fill(T(-32.768), n) | ||
| uvar = fill(T(32.768), n) | ||
| return ADNLPModels.ADNLPModel(f, x0; lvar = lvar, uvar = uvar, name = "ackley", kwargs...) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| export griewank | ||
|
|
||
| function griewank(; n::Int = default_nvar, type::Type{T} = Float64, x0::Union{Nothing, AbstractVector{T}} = nothing, kwargs...) where {T} | ||
| function f(x) | ||
| n = length(x) | ||
| sum_term = sum(x[i]^2 for i = 1:n) / 4000 | ||
| prod_term = prod(cos(x[i] / sqrt(T(i))) for i = 1:n) | ||
| return sum_term - prod_term + 1 | ||
| end | ||
| x0_local = isnothing(x0) ? zeros(T, n) : x0 | ||
| return ADNLPModels.ADNLPModel(f, x0_local, name = "griewank"; kwargs...) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| export rastrigin | ||
|
|
||
| function rastrigin(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x) | ||
| n = length(x) | ||
| return 10 * n + sum(x[i]^2 - 10 * cos(2 * T(π) * x[i]) for i = 1:n) | ||
| end | ||
| x0 = zeros(T, n) | ||
| lvar = T[-5.12 for _ = 1:n] | ||
| uvar = T[5.12 for _ = 1:n] | ||
| return ADNLPModels.ADNLPModel(f, x0, lvar = lvar, uvar = uvar, name = "rastrigin"; kwargs...) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| export sphere | ||
|
|
||
| function sphere(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x) | ||
| return sum(x[i]^2 for i = 1:length(x)) | ||
| end | ||
| x0 = zeros(T, n) | ||
| lvar = fill(T(-5.12), n) | ||
| uvar = fill(T(5.12), n) | ||
| return ADNLPModels.ADNLPModel(f, x0; lvar = lvar, uvar = uvar, name = "sphere", kwargs...) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| ackley_meta = Dict( | ||
| :nvar => 100, | ||
| :variable_nvar => true, | ||
| :ncon => 0, | ||
| :variable_ncon => false, | ||
| :minimize => true, | ||
| :name => "ackley", | ||
| :has_equalities_only => false, | ||
| :has_inequalities_only => false, | ||
| :has_bounds => true, | ||
| :has_fixed_variables => false, | ||
| :objtype => :other, | ||
| :contype => :unconstrained, | ||
| :best_known_lower_bound => 0.0, | ||
| :best_known_upper_bound => 0.0, | ||
| :is_feasible => true, | ||
| :defined_everywhere => missing, | ||
| :origin => :unknown, | ||
| ) | ||
| get_ackley_nvar(; n::Integer = default_nvar, kwargs...) = n | ||
| get_ackley_ncon(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_ackley_nlin(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_ackley_nnln(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_ackley_nequ(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_ackley_nineq(; n::Integer = default_nvar, kwargs...) = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| griewank_meta = Dict( | ||
| :nvar => 100, | ||
| :variable_nvar => true, | ||
| :ncon => 0, | ||
| :variable_ncon => false, | ||
| :minimize => true, | ||
| :name => "griewank", | ||
| :has_equalities_only => false, | ||
| :has_inequalities_only => false, | ||
| :has_bounds => true, | ||
| :has_fixed_variables => false, | ||
| :objtype => :other, | ||
| :contype => :unconstrained, | ||
| :best_known_lower_bound => 0.0, | ||
| :best_known_upper_bound => 0.0, | ||
| :is_feasible => true, | ||
| :defined_everywhere => missing, | ||
| :origin => :unknown, | ||
| ) | ||
| get_griewank_nvar(; n::Integer = default_nvar, kwargs...) = n | ||
| get_griewank_ncon(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_griewank_nlin(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_griewank_nnln(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_griewank_nequ(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_griewank_nineq(; n::Integer = default_nvar, kwargs...) = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| rastrigin_meta = Dict( | ||
| :nvar => 100, | ||
| :variable_nvar => true, | ||
| :ncon => 0, | ||
| :variable_ncon => false, | ||
| :minimize => true, | ||
| :name => "rastrigin", | ||
| :has_equalities_only => false, | ||
| :has_inequalities_only => false, | ||
| :has_bounds => true, | ||
| :has_fixed_variables => false, | ||
| :objtype => :other, | ||
| :contype => :unconstrained, | ||
| :best_known_lower_bound => 0.0, | ||
| :best_known_upper_bound => 0.0, | ||
| :is_feasible => true, | ||
| :defined_everywhere => missing, | ||
| :origin => :unknown, | ||
| ) | ||
| get_rastrigin_nvar(; n::Integer = default_nvar, kwargs...) = n | ||
| get_rastrigin_ncon(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_rastrigin_nlin(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_rastrigin_nnln(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_rastrigin_nequ(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_rastrigin_nineq(; n::Integer = default_nvar, kwargs...) = 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| sphere_meta = Dict( | ||
| :nvar => 100, | ||
| :variable_nvar => true, | ||
| :ncon => 0, | ||
| :variable_ncon => false, | ||
| :minimize => true, | ||
| :name => "sphere", | ||
| :has_equalities_only => false, | ||
| :has_inequalities_only => false, | ||
| :has_bounds => true, | ||
| :has_fixed_variables => false, | ||
| :objtype => :other, | ||
| :contype => :unconstrained, | ||
| :best_known_lower_bound => 0.0, | ||
| :best_known_upper_bound => 0.0, | ||
| :is_feasible => true, | ||
| :defined_everywhere => missing, | ||
| :origin => :unknown, | ||
| ) | ||
| get_sphere_nvar(; n::Integer = default_nvar, kwargs...) = n | ||
| get_sphere_ncon(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_sphere_nlin(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_sphere_nnln(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_sphere_nequ(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_sphere_nineq(; n::Integer = default_nvar, kwargs...) = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Ackley test function | ||
| # | ||
| # A multivariate multimodal optimization problem from the | ||
| # AMPGO test set. | ||
| # | ||
| # Problem Ackley in | ||
| # http://infinity77.net/global_optimization/test_functions_nd_A.html | ||
| # Andrea Gavana | ||
| # | ||
| # f(x) = -20*exp(-0.2*sqrt(sum(x_i^2)/n)) - exp(sum(cos(2*pi*x_i))/n) + 20 + e | ||
| # | ||
| # Global minimum: f(0,...,0) = 0 | ||
| # Bounds: x_i in [-32, 32] for all i | ||
|
|
||
| export ackley | ||
|
|
||
| "Ackley multimodal minimization problem" | ||
| function ackley(args...; n::Int = default_nvar, kwargs...) | ||
| n < 1 && @warn("ackley: number of variables must be ≥ 1") | ||
| n = max(1, n) | ||
|
|
||
| nlp = Model() | ||
|
|
||
| x0 = [-32 + 64 * rand() for i = 1:n] | ||
| @variable(nlp, -32 <= x[i = 1:n] <= 32, start = x0[i]) | ||
| nlp.ext[:has_bounds] = true | ||
|
|
||
| @objective( | ||
| nlp, | ||
| Min, | ||
| -20 * exp(-0.2 * sqrt(sum(x[i]^2 for i = 1:n) / n)) - | ||
| exp(sum(cos(2 * π * x[i]) for i = 1:n) / n) + | ||
| 20 + | ||
| exp(1) | ||
| ) | ||
|
|
||
| return nlp | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Griewank test function | ||
| # | ||
| # A multivariate multimodal optimization problem from the | ||
| # AMPGO test set. | ||
| # | ||
| # Problem Griewank in | ||
| # http://infinity77.net/global_optimization/test_functions_nd_G.html | ||
| # Andrea Gavana | ||
| # | ||
| # f(x) = sum(x_i^2)/4000 - prod(cos(x_i/sqrt(i))) + 1 | ||
| # | ||
| # Global minimum: f(0,...,0) = 0 | ||
| # Bounds: x_i in [-600, 600] for all i | ||
|
|
||
| export griewank | ||
|
|
||
| "Griewank multimodal minimization problem" | ||
| function griewank(args...; n::Int = default_nvar, x0::Union{Nothing,AbstractVector} = nothing, kwargs...) | ||
| n < 1 && @warn("griewank: number of variables must be ≥ 1") | ||
| n = max(1, n) | ||
|
|
||
| nlp = Model() | ||
|
|
||
| if x0 === nothing | ||
| x0 = zeros(n) | ||
| elseif length(x0) != n | ||
| throw(ArgumentError("griewank: length(x0) = $(length(x0)) must equal n = $n")) | ||
| end | ||
| @variable(nlp, -600 <= x[i = 1:n] <= 600, start = x0[i]) | ||
|
|
||
| @objective( | ||
| nlp, | ||
| Min, | ||
| sum(x[i]^2 for i = 1:n) / 4000 - prod(cos(x[i] / sqrt(i)) for i = 1:n) + 1 | ||
| ) | ||
|
|
||
| return nlp | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Rastrigin test function | ||
| # | ||
| # A multivariate highly multimodal optimization problem from the | ||
| # AMPGO test set. | ||
| # | ||
| # Problem Rastrigin in | ||
| # http://infinity77.net/global_optimization/test_functions_nd_R.html | ||
| # Andrea Gavana | ||
| # | ||
| # f(x) = 10*n + sum(x_i^2 - 10*cos(2*pi*x_i)) | ||
| # | ||
| # Global minimum: f(0,...,0) = 0 | ||
| # Bounds: x_i in [-5.12, 5.12] for all i | ||
|
|
||
| export rastrigin | ||
|
|
||
| "Rastrigin multimodal minimization problem" | ||
| function rastrigin(args...; n::Int = default_nvar, kwargs...) | ||
| n < 1 && @warn("rastrigin: number of variables must be ≥ 1") | ||
| n = max(1, n) | ||
|
|
||
| nlp = Model() | ||
|
|
||
| x0 = [0.0 for i = 1:n] | ||
| @variable(nlp, x[i = 1:n], lower_bound = -5.12, upper_bound = 5.12, start = x0[i]) | ||
|
|
||
| @objective(nlp, Min, 10 * n + sum(x[i]^2 - 10 * cos(2 * π * x[i]) for i = 1:n)) | ||
|
|
||
| return nlp | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Sphere test function | ||
| # | ||
| # A simple multivariate convex optimization problem from the | ||
| # AMPGO test set. | ||
| # | ||
| # Problem Sphere in | ||
| # http://infinity77.net/global_optimization/test_functions_nd_S.html | ||
| # Andrea Gavana | ||
| # | ||
| # f(x) = sum(x_i^2) | ||
| # | ||
| # Global minimum: f(0,...,0) = 0 | ||
| # Bounds: x_i in [-1, 1] for all i | ||
|
|
||
| export sphere | ||
|
|
||
| "Sphere convex minimization problem" | ||
| function sphere(args...; n::Int = default_nvar, kwargs...) | ||
| n < 1 && @warn("sphere: number of variables must be ≥ 1") | ||
| n = max(1, n) | ||
|
|
||
| nlp = Model() | ||
|
|
||
| x0 = zeros(n) | ||
| @variable(nlp, -1 <= x[i = 1:n] <= 1, start = x0[i]) | ||
|
|
||
| @objective(nlp, Min, sum(x[i]^2 for i = 1:n)) | ||
|
|
||
| return nlp | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.