-
Notifications
You must be signed in to change notification settings - Fork 48
Problem 9,10 and 16 #396
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
17
commits into
JuliaSmoothOptimizers:main
Choose a base branch
from
arnavk23:main
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
Problem 9,10 and 16 #396
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5c33ede
Problem 9 and 10
arnavk23 7cffe7d
feat(trigb): add banded trigonometric problem (Meta, ADNLP, PureJuMP)
arnavk23 efc78ab
trigb.jl
arnavk23 04c8ad1
Update trig.jl
arnavk23 eb71f89
Apply suggestions from code review
arnavk23 2968284
removing unnecessary variables
arnavk23 84f4991
fixing remaining mentions of xi variable
arnavk23 71bca05
removing twice renditions
arnavk23 fff0281
meta
arnavk23 fbfe1e2
PureJuMP
arnavk23 8d5e090
Update toint.jl
arnavk23 e76e90e
Update trig.jl
arnavk23 5e003e5
Update toint.jl
arnavk23 e5c9882
Update src/ADNLPProblems/toint.jl
arnavk23 8b80602
fixing Float64 issue in toint and trig problems
arnavk23 5f03f47
further changes
arnavk23 c626f5f
trig changes
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| export toint | ||
|
|
||
| function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x; n = length(x)) | ||
| n_local = n | ||
| s = zero(T) | ||
| for i = 1:n_local | ||
| xi = x[i] | ||
| ci = 1 + (i / 10) | ||
|
|
||
| jlo = max(1, i - 2) | ||
| jhi = min(n_local, i + 2) | ||
| for j = jlo:jhi | ||
| aij = 5 * (1 + mod(i, 5) + mod(j, 5)) | ||
| bij = (i + j) / 10 | ||
| cj = (1 + j) / 10 | ||
| s += aij * sin(bij + ci * xi + cj * x[j]) | ||
| end | ||
|
|
||
| if iseven(n_local) | ||
| j = i + (n_local ÷ 2) | ||
| if 1 <= j <= n_local | ||
| aij = 5 * (1 + mod(i, 5) + mod(j, 5)) | ||
| bij = (i + j) / 10 | ||
| cj = (1 + j) / 10 | ||
| s += aij * sin(bij + ci * xi + cj * x[j]) | ||
| end | ||
| end | ||
| end | ||
| return s / T(n_local) | ||
| end | ||
|
|
||
| x0 = fill(1, n) | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return ADNLPModels.ADNLPModel(f, x0, name = "toint"; 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,35 @@ | ||
| export trig | ||
|
|
||
| function trig(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x; n = length(x)) | ||
| n_local = n | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| s = zero(T) | ||
| for i = 1:n_local | ||
| xi = x[i] | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| term = i * (1 - cos(xi)) | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| jlo = max(1, i - 2) | ||
| jhi = min(n_local, i + 2) | ||
| for j = jlo:jhi | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| aij = 5 * (1 + mod(i, 5) + mod(j, 5)) | ||
| bij = (i + j) / 10 | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| term += aij * sin(x[j]) + bij * cos(x[j]) | ||
| end | ||
|
|
||
| if iseven(n_local) | ||
| j = i + (n_local ÷ 2) | ||
| if 1 <= j <= n_local | ||
| aij = 5 * (1 + mod(i, 5) + mod(j, 5)) | ||
| bij = (i + j) / 10 | ||
| term += aij * sin(x[j]) + bij * cos(x[j]) | ||
| end | ||
| end | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| s += term | ||
| end | ||
| return s / T(n_local) | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| x0 = fill(1 / n, n) | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return ADNLPModels.ADNLPModel(f, x0, name = "trig"; 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,19 @@ | ||
| export trigb | ||
|
|
||
| function trigb(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x; n = length(x)) | ||
| n_local = n | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| s = zero(T) | ||
| for i = 1:n_local | ||
| xi = x[i] | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| left = (i == 1) ? zero(T) : x[i - 1] | ||
| right = (i == n_local) ? zero(T) : x[i + 1] | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| term = i * (1 - cos(xi) + sin(left) - sin(right)) | ||
| s += term | ||
| end | ||
| return s | ||
| end | ||
|
|
||
| x0 = fill(1, n) | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return ADNLPModels.ADNLPModel(f, x0, name = "trigb"; 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,27 @@ | ||
| toint_meta = Dict( | ||
| :nvar => 100, | ||
| :variable_nvar => true, | ||
| :ncon => 0, | ||
| :variable_ncon => false, | ||
| :minimize => true, | ||
| :name => "toint", | ||
| :has_equalities_only => false, | ||
| :has_inequalities_only => false, | ||
| :has_bounds => false, | ||
| :has_fixed_variables => false, | ||
| :objtype => :other, | ||
| :contype => :unconstrained, | ||
| :best_known_lower_bound => -Inf, | ||
| :best_known_upper_bound => 0.0, | ||
| :is_feasible => true, | ||
| :defined_everywhere => missing, | ||
| :origin => :unknown, | ||
| ) | ||
|
|
||
| get_toint_nvar(; n::Integer = default_nvar, kwargs...) = n | ||
| get_toint_ncon(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_toint_nlin(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_toint_nnln(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_toint_nequ(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_toint_nineq(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_toint_nls_nequ(; n::Integer = default_nvar, kwargs...) = 2 * n |
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,27 @@ | ||
| trig_meta = Dict( | ||
| :nvar => 100, | ||
| :variable_nvar => true, | ||
| :ncon => 0, | ||
| :variable_ncon => false, | ||
| :minimize => true, | ||
| :name => "trig", | ||
| :has_equalities_only => false, | ||
| :has_inequalities_only => false, | ||
| :has_bounds => false, | ||
| :has_fixed_variables => false, | ||
| :objtype => :other, | ||
| :contype => :unconstrained, | ||
| :best_known_lower_bound => -Inf, | ||
| :best_known_upper_bound => 0.0, | ||
| :is_feasible => true, | ||
| :defined_everywhere => missing, | ||
| :origin => :unknown, | ||
| ) | ||
|
|
||
| get_trig_nvar(; n::Integer = default_nvar, kwargs...) = n | ||
| get_trig_ncon(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_trig_nlin(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_trig_nnln(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_trig_nequ(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_trig_nineq(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_trig_nls_nequ(; n::Integer = default_nvar, kwargs...) = 2 * n |
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,27 @@ | ||
| trigb_meta = Dict( | ||
| :nvar => 100, | ||
| :variable_nvar => true, | ||
| :ncon => 0, | ||
| :variable_ncon => false, | ||
| :minimize => true, | ||
| :name => "trigb", | ||
| :has_equalities_only => false, | ||
| :has_inequalities_only => false, | ||
| :has_bounds => false, | ||
| :has_fixed_variables => false, | ||
| :objtype => :other, | ||
| :contype => :unconstrained, | ||
| :best_known_lower_bound => -Inf, | ||
| :best_known_upper_bound => 0.0, | ||
| :is_feasible => true, | ||
| :defined_everywhere => missing, | ||
| :origin => :unknown, | ||
| ) | ||
|
|
||
| get_trigb_nvar(; n::Integer = default_nvar, kwargs...) = n | ||
| get_trigb_ncon(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_trigb_nlin(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_trigb_nnln(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_trigb_nequ(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_trigb_nineq(; n::Integer = default_nvar, kwargs...) = 0 | ||
| get_trigb_nls_nequ(; n::Integer = default_nvar, kwargs...) = 2 * n | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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,46 @@ | ||
| # Toint trigonometric function | ||
| # | ||
| # Problem 10 in | ||
| # L. Luksan, C. Matonoha and J. Vlcek | ||
| # Sparse Test Problems for Unconstrained Optimization, | ||
| # Technical Report 1064, | ||
| # Institute of Computer Science, | ||
| # Academy of Science of the Czech Republic | ||
| # | ||
| # https://www.researchgate.net/publication/325314400_Sparse_Test_Problems_for_Unconstrained_Optimization | ||
| # | ||
| export toint | ||
|
|
||
| function toint(args...; n::Int = default_nvar, kwargs...) | ||
| model = Model() | ||
| @variable(model, x[i = 1:n], start = 1) | ||
|
|
||
| @objective( | ||
| model, | ||
| Min, | ||
| (1 / n) * sum(begin | ||
| ci = 1 + i / 10 | ||
| s = zero(Float64) | ||
| jlo = max(1, i - 2) | ||
| jhi = min(n, i + 2) | ||
| for j = jlo:jhi | ||
| aij = 5 * (1 + mod(i, 5) + mod(j, 5)) | ||
| bij = (i + j) / 10 | ||
| cj = 1 + j / 10 | ||
| s += aij * sin(bij + ci * x[i] + cj * x[j]) | ||
| end | ||
| if iseven(n) | ||
| j = i + (n ÷ 2) | ||
| if 1 <= j <= n | ||
| aij = 5 * (1 + mod(i, 5) + mod(j, 5)) | ||
| bij = (i + j) / 10 | ||
| cj = 1 + j / 10 | ||
| s += aij * sin(bij + ci * x[i] + cj * x[j]) | ||
| end | ||
| end | ||
| s | ||
| end for i = 1:n) | ||
| ) | ||
|
|
||
| return model | ||
| 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,40 @@ | ||
| # Another trigonometric function | ||
| # | ||
| # Problem 9 in | ||
| # L. Luksan, C. Matonoha and J. Vlcek | ||
| # Sparse Test Problems for Unconstrained Optimization, | ||
| # Technical Report 1064, | ||
| # Institute of Computer Science, | ||
| # Academy of Science of the Czech Republic | ||
| # | ||
| # https://www.researchgate.net/publication/325314400_Sparse_Test_Problems_for_Unconstrained_Optimization | ||
| # | ||
| export trig | ||
|
|
||
| function trig(args...; n::Int = default_nvar, kwargs...) | ||
| model = Model() | ||
| @variable(model, x[i = 1:n], start = 1 / n) | ||
|
|
||
| @objective( | ||
| model, | ||
| Min, | ||
| (1 / n) * sum( | ||
| i * (1 - cos(x[i])) + | ||
| sum( | ||
| 5 * (1 + mod(i, 5) + mod(j, 5)) * sin(x[j]) + (i + j) / 10 * cos(x[j]) for | ||
| j = max(1, i - 2):min(n, i + 2) | ||
| ) + | ||
| ( | ||
| iseven(n) ? | ||
| ( | ||
| let j = i + (n ÷ 2); | ||
| (1 <= j <= n) ? | ||
| (5 * (1 + mod(i, 5) + mod(j, 5)) * sin(x[j]) + (i + j) / 10 * cos(x[j])) : 0 | ||
| end | ||
| ) : 0 | ||
| ) for i = 1:n | ||
| ) | ||
| ) | ||
|
|
||
| return model | ||
| 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 @@ | ||
| ## Banded trigonometric problem | ||
| # | ||
| # Problem 16 in | ||
| # L. Luksan, C. Matonoha and J. Vlcek | ||
| # Sparse Test Problems for Unconstrained Optimization, | ||
| # Technical Report 1064, | ||
| # Institute of Computer Science, | ||
| # Academy of Science of the Czech Republic | ||
| # | ||
| # https://www.researchgate.net/publication/325314400_Sparse_Test_Problems_for_Unconstrained_Optimization | ||
| # | ||
| export trigb | ||
|
|
||
| function trigb(args...; n::Int = default_nvar, kwargs...) | ||
| model = Model() | ||
| @variable(model, x[i = 1:n], start = 1.0) | ||
|
|
||
| @objective( | ||
| model, | ||
| Min, | ||
| sum( | ||
| i * ( | ||
| (1 - cos(x[i])) + ((i == 1) ? sin(0.0) : sin(x[i - 1])) - | ||
| ((i == n) ? sin(0.0) : sin(x[i + 1])) | ||
arnavk23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) for i = 1:n | ||
| ) | ||
| ) | ||
|
|
||
| return model | ||
| 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.