From 5c33eded36a128a780f04ad81e962edde37021fe Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Tue, 18 Nov 2025 02:53:33 +0530 Subject: [PATCH 01/17] Problem 9 and 10 --- src/ADNLPProblems/toint.jl | 35 +++++++++++++++++++++++++++++ src/ADNLPProblems/trig.jl | 35 +++++++++++++++++++++++++++++ src/Meta/toint.jl | 27 ++++++++++++++++++++++ src/Meta/trig.jl | 27 ++++++++++++++++++++++ src/PureJuMP/toint.jl | 46 ++++++++++++++++++++++++++++++++++++++ src/PureJuMP/trig.jl | 40 +++++++++++++++++++++++++++++++++ 6 files changed, 210 insertions(+) create mode 100644 src/ADNLPProblems/toint.jl create mode 100644 src/ADNLPProblems/trig.jl create mode 100644 src/Meta/toint.jl create mode 100644 src/Meta/trig.jl create mode 100644 src/PureJuMP/toint.jl create mode 100644 src/PureJuMP/trig.jl diff --git a/src/ADNLPProblems/toint.jl b/src/ADNLPProblems/toint.jl new file mode 100644 index 00000000..ccdc9847 --- /dev/null +++ b/src/ADNLPProblems/toint.jl @@ -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) + return ADNLPModels.ADNLPModel(f, x0, name = "toint"; kwargs...) +end diff --git a/src/ADNLPProblems/trig.jl b/src/ADNLPProblems/trig.jl new file mode 100644 index 00000000..622fa6da --- /dev/null +++ b/src/ADNLPProblems/trig.jl @@ -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 + s = zero(T) + for i = 1:n_local + xi = x[i] + term = T(i) * (one(T) - cos(xi)) + + 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 + 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 + + s += term + end + return s / T(n_local) + end + + x0 = fill(1 / n, n) + return ADNLPModels.ADNLPModel(f, x0, name = "trig"; kwargs...) +end diff --git a/src/Meta/toint.jl b/src/Meta/toint.jl new file mode 100644 index 00000000..b01aaa0d --- /dev/null +++ b/src/Meta/toint.jl @@ -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 diff --git a/src/Meta/trig.jl b/src/Meta/trig.jl new file mode 100644 index 00000000..731a7bef --- /dev/null +++ b/src/Meta/trig.jl @@ -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 diff --git a/src/PureJuMP/toint.jl b/src/PureJuMP/toint.jl new file mode 100644 index 00000000..a967cc27 --- /dev/null +++ b/src/PureJuMP/toint.jl @@ -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 diff --git a/src/PureJuMP/trig.jl b/src/PureJuMP/trig.jl new file mode 100644 index 00000000..a135b21f --- /dev/null +++ b/src/PureJuMP/trig.jl @@ -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 From 7cffe7dbbcd1676f78b263171ddd401171a32141 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Tue, 18 Nov 2025 02:57:26 +0530 Subject: [PATCH 02/17] feat(trigb): add banded trigonometric problem (Meta, ADNLP, PureJuMP) --- src/ADNLPProblems/trigb.jl | 24 ++++++++++++++++++++++++ src/Meta/trigb.jl | 27 +++++++++++++++++++++++++++ src/PureJuMP/trigb.jl | 22 ++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 src/ADNLPProblems/trigb.jl create mode 100644 src/Meta/trigb.jl create mode 100644 src/PureJuMP/trigb.jl diff --git a/src/ADNLPProblems/trigb.jl b/src/ADNLPProblems/trigb.jl new file mode 100644 index 00000000..950031b0 --- /dev/null +++ b/src/ADNLPProblems/trigb.jl @@ -0,0 +1,24 @@ +export trigb + +function trigb(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} + # Band-limited trigonometric objective + # F(x) = sum_{i=1}^n i * [ (1 - cos(x_i)) + sin(x_{i-1}) - sin(x_{i+1}) ] + # with boundary values x_0 = x_{n+1} = 0 + + function f(x; n = length(x)) + n_local = n + s = zero(T) + for i in 1:n_local + xi = x[i] + left = (i == 1) ? zero(T) : x[i - 1] + right = (i == n_local) ? zero(T) : x[i + 1] + term = T(i) * ( (one(T) - cos(xi)) + sin(left) - sin(right) ) + s += term + end + return s + end + + # default initial guess: xbar_i = 1 (use type-generic one(T)) + x0 = fill(one(T), n) + return ADNLPModels.ADNLPModel(f, x0, name = "trigb"; kwargs...) +end diff --git a/src/Meta/trigb.jl b/src/Meta/trigb.jl new file mode 100644 index 00000000..8ae0e399 --- /dev/null +++ b/src/Meta/trigb.jl @@ -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 diff --git a/src/PureJuMP/trigb.jl b/src/PureJuMP/trigb.jl new file mode 100644 index 00000000..dd7080b2 --- /dev/null +++ b/src/PureJuMP/trigb.jl @@ -0,0 +1,22 @@ +## Banded trigonometric problem (Problem 16) +## F(x) = sum_{i=1}^n i * [ (1 - cos(x_i)) + sin(x_{i-1}) - sin(x_{i+1}) ] +## boundary: x_0 = x_{n+1} = 0 + +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])) + ) for i = 1:n + ) + ) + + return model +end From efc78aba97f61086579280815e741252df603abf Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Tue, 18 Nov 2025 03:06:37 +0530 Subject: [PATCH 03/17] trigb.jl --- src/ADNLPProblems/trigb.jl | 11 +++-------- src/PureJuMP/trigb.jl | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/ADNLPProblems/trigb.jl b/src/ADNLPProblems/trigb.jl index 950031b0..14472bdd 100644 --- a/src/ADNLPProblems/trigb.jl +++ b/src/ADNLPProblems/trigb.jl @@ -1,24 +1,19 @@ export trigb function trigb(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} - # Band-limited trigonometric objective - # F(x) = sum_{i=1}^n i * [ (1 - cos(x_i)) + sin(x_{i-1}) - sin(x_{i+1}) ] - # with boundary values x_0 = x_{n+1} = 0 - function f(x; n = length(x)) n_local = n s = zero(T) - for i in 1:n_local + for i = 1:n_local xi = x[i] left = (i == 1) ? zero(T) : x[i - 1] right = (i == n_local) ? zero(T) : x[i + 1] - term = T(i) * ( (one(T) - cos(xi)) + sin(left) - sin(right) ) + term = i * (1 - cos(xi) + sin(left) - sin(right)) s += term end return s end - # default initial guess: xbar_i = 1 (use type-generic one(T)) - x0 = fill(one(T), n) + x0 = fill(1, n) return ADNLPModels.ADNLPModel(f, x0, name = "trigb"; kwargs...) end diff --git a/src/PureJuMP/trigb.jl b/src/PureJuMP/trigb.jl index dd7080b2..410de53d 100644 --- a/src/PureJuMP/trigb.jl +++ b/src/PureJuMP/trigb.jl @@ -1,18 +1,26 @@ -## Banded trigonometric problem (Problem 16) -## F(x) = sum_{i=1}^n i * [ (1 - cos(x_i)) + sin(x_{i-1}) - sin(x_{i+1}) ] -## boundary: x_0 = x_{n+1} = 0 - +## 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, + @objective( + model, + Min, sum( i * ( - (1 - cos(x[i])) + - ((i == 1) ? sin(0.0) : sin(x[i - 1])) - + (1 - cos(x[i])) + ((i == 1) ? sin(0.0) : sin(x[i - 1])) - ((i == n) ? sin(0.0) : sin(x[i + 1])) ) for i = 1:n ) From 04c8ad10aa9bb47e5c61524586b15cc4409bb922 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Tue, 18 Nov 2025 15:51:11 +0530 Subject: [PATCH 04/17] Update trig.jl --- src/ADNLPProblems/trig.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ADNLPProblems/trig.jl b/src/ADNLPProblems/trig.jl index 622fa6da..d69fafdd 100644 --- a/src/ADNLPProblems/trig.jl +++ b/src/ADNLPProblems/trig.jl @@ -6,21 +6,21 @@ function trig(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where s = zero(T) for i = 1:n_local xi = x[i] - term = T(i) * (one(T) - cos(xi)) + term = i * (1 - cos(xi)) 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 + aij = 5 * (1 + mod(i, 5) + mod(j, 5)) + bij = (i + j) / 10 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 + aij = 5 * (1 + mod(i, 5) + mod(j, 5)) + bij = (i + j) / 10 term += aij * sin(x[j]) + bij * cos(x[j]) end end From eb71f89aeef23cef133eca0b0700dece377f572b Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Tue, 18 Nov 2025 18:58:37 +0530 Subject: [PATCH 05/17] Apply suggestions from code review Co-authored-by: Tangi Migot --- src/ADNLPProblems/toint.jl | 3 +-- src/ADNLPProblems/trig.jl | 10 +++------- src/ADNLPProblems/trigb.jl | 8 +++----- src/Meta/trigb.jl | 1 - src/PureJuMP/trigb.jl | 4 ++-- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/ADNLPProblems/toint.jl b/src/ADNLPProblems/toint.jl index ccdc9847..a4e9b310 100644 --- a/src/ADNLPProblems/toint.jl +++ b/src/ADNLPProblems/toint.jl @@ -2,7 +2,6 @@ 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] @@ -30,6 +29,6 @@ function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) wher return s / T(n_local) end - x0 = fill(1, n) + x0 = fill(one(T), n) return ADNLPModels.ADNLPModel(f, x0, name = "toint"; kwargs...) end diff --git a/src/ADNLPProblems/trig.jl b/src/ADNLPProblems/trig.jl index d69fafdd..9f5805c4 100644 --- a/src/ADNLPProblems/trig.jl +++ b/src/ADNLPProblems/trig.jl @@ -2,15 +2,11 @@ export trig function trig(; 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] term = i * (1 - cos(xi)) - jlo = max(1, i - 2) - jhi = min(n_local, i + 2) - for j = jlo:jhi + for j = max(1, i - 2):min(n, i + 2) aij = 5 * (1 + mod(i, 5) + mod(j, 5)) bij = (i + j) / 10 term += aij * sin(x[j]) + bij * cos(x[j]) @@ -27,9 +23,9 @@ function trig(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where s += term end - return s / T(n_local) + return s / n end - x0 = fill(1 / n, n) + x0 = fill(one(T) / n, n) return ADNLPModels.ADNLPModel(f, x0, name = "trig"; kwargs...) end diff --git a/src/ADNLPProblems/trigb.jl b/src/ADNLPProblems/trigb.jl index 14472bdd..cd2d63fa 100644 --- a/src/ADNLPProblems/trigb.jl +++ b/src/ADNLPProblems/trigb.jl @@ -2,18 +2,16 @@ export trigb function trigb(; 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] - left = (i == 1) ? zero(T) : x[i - 1] - right = (i == n_local) ? zero(T) : x[i + 1] + xim = (i == 1) ? zero(T) : x[i - 1] + xip = (i == n_local) ? zero(T) : x[i + 1] term = i * (1 - cos(xi) + sin(left) - sin(right)) s += term end return s end - x0 = fill(1, n) + x0 = fill(one(T), n) return ADNLPModels.ADNLPModel(f, x0, name = "trigb"; kwargs...) end diff --git a/src/Meta/trigb.jl b/src/Meta/trigb.jl index 8ae0e399..c648cb7a 100644 --- a/src/Meta/trigb.jl +++ b/src/Meta/trigb.jl @@ -24,4 +24,3 @@ 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 diff --git a/src/PureJuMP/trigb.jl b/src/PureJuMP/trigb.jl index 410de53d..db272be1 100644 --- a/src/PureJuMP/trigb.jl +++ b/src/PureJuMP/trigb.jl @@ -20,8 +20,8 @@ function trigb(args...; n::Int = default_nvar, kwargs...) 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])) + (1 - cos(x[i])) + ((i == 1) ? sin(0) : sin(x[i - 1])) - + ((i == n) ? sin(0) : sin(x[i + 1])) ) for i = 1:n ) ) From 2968284832ef134e4e4246536b826edcb086446b Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Tue, 18 Nov 2025 23:29:26 +0530 Subject: [PATCH 06/17] removing unnecessary variables --- src/ADNLPProblems/toint.jl | 15 ++++++--------- src/ADNLPProblems/trig.jl | 16 +++++++--------- src/ADNLPProblems/trigb.jl | 7 +++---- src/PureJuMP/trigb.jl | 9 ++++----- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/ADNLPProblems/toint.jl b/src/ADNLPProblems/toint.jl index a4e9b310..ce5505e2 100644 --- a/src/ADNLPProblems/toint.jl +++ b/src/ADNLPProblems/toint.jl @@ -3,22 +3,19 @@ export toint function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} function f(x; n = length(x)) s = zero(T) - for i = 1:n_local - xi = x[i] + for i = 1:n ci = 1 + (i / 10) - jlo = max(1, i - 2) - jhi = min(n_local, i + 2) - for j = jlo:jhi + for j = max(1, i - 2):min(n, i + 2) 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 + 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 @@ -26,7 +23,7 @@ function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) wher end end end - return s / T(n_local) + return s / n end x0 = fill(one(T), n) diff --git a/src/ADNLPProblems/trig.jl b/src/ADNLPProblems/trig.jl index 9f5805c4..b4b4b9fd 100644 --- a/src/ADNLPProblems/trig.jl +++ b/src/ADNLPProblems/trig.jl @@ -3,25 +3,23 @@ export trig function trig(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} function f(x; n = length(x)) s = zero(T) - for i = 1:n_local - term = i * (1 - cos(xi)) + for i = 1:n + s += i * (1 - cos(x[i])) for j = max(1, i - 2):min(n, i + 2) aij = 5 * (1 + mod(i, 5) + mod(j, 5)) bij = (i + j) / 10 - term += aij * sin(x[j]) + bij * cos(x[j]) + s += aij * sin(x[j]) + bij * cos(x[j]) end - if iseven(n_local) - j = i + (n_local ÷ 2) - if 1 <= j <= n_local + if iseven(n) + j = i + (n ÷ 2) + if 1 <= j <= n aij = 5 * (1 + mod(i, 5) + mod(j, 5)) bij = (i + j) / 10 - term += aij * sin(x[j]) + bij * cos(x[j]) + s += aij * sin(x[j]) + bij * cos(x[j]) end end - - s += term end return s / n end diff --git a/src/ADNLPProblems/trigb.jl b/src/ADNLPProblems/trigb.jl index cd2d63fa..98339cfa 100644 --- a/src/ADNLPProblems/trigb.jl +++ b/src/ADNLPProblems/trigb.jl @@ -3,11 +3,10 @@ export trigb function trigb(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} function f(x; n = length(x)) s = zero(T) - for i = 1:n_local + for i = 1:n xim = (i == 1) ? zero(T) : x[i - 1] - xip = (i == n_local) ? zero(T) : x[i + 1] - term = i * (1 - cos(xi) + sin(left) - sin(right)) - s += term + xip = (i == n) ? zero(T) : x[i + 1] + s += i * (1 - cos(x[i]) + sin(xim) - sin(xip)) end return s end diff --git a/src/PureJuMP/trigb.jl b/src/PureJuMP/trigb.jl index db272be1..1eb24276 100644 --- a/src/PureJuMP/trigb.jl +++ b/src/PureJuMP/trigb.jl @@ -13,16 +13,15 @@ export trigb function trigb(args...; n::Int = default_nvar, kwargs...) model = Model() - @variable(model, x[i = 1:n], start = 1.0) + @variable(model, x[i = 1:n], start = 1) @objective( model, Min, sum( - i * ( - (1 - cos(x[i])) + ((i == 1) ? sin(0) : sin(x[i - 1])) - - ((i == n) ? sin(0) : sin(x[i + 1])) - ) for i = 1:n + i * + ((1 - cos(x[i])) + ((i == 1) ? sin(0) : sin(x[i - 1])) - ((i == n) ? sin(0) : sin(x[i + 1]))) + for i = 1:n ) ) From 84f4991266eeb3ff04ad0889a133123966d43fe3 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Wed, 19 Nov 2025 00:16:39 +0530 Subject: [PATCH 07/17] fixing remaining mentions of xi variable --- src/ADNLPProblems/toint.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ADNLPProblems/toint.jl b/src/ADNLPProblems/toint.jl index ce5505e2..86c521e0 100644 --- a/src/ADNLPProblems/toint.jl +++ b/src/ADNLPProblems/toint.jl @@ -10,7 +10,7 @@ function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) wher 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]) + s += aij * sin(bij + ci * x[i] + cj * x[j]) end if iseven(n) @@ -19,7 +19,7 @@ function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) wher 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]) + s += aij * sin(bij + ci * x[i] + cj * x[j]) end end end From 71bca05dc9006d29af623dc26797bcf3c120ea4d Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Wed, 19 Nov 2025 01:11:46 +0530 Subject: [PATCH 08/17] removing twice renditions --- src/ADNLPProblems/toint.jl | 10 ---------- src/ADNLPProblems/trig.jl | 9 --------- 2 files changed, 19 deletions(-) diff --git a/src/ADNLPProblems/toint.jl b/src/ADNLPProblems/toint.jl index 86c521e0..f00b5d49 100644 --- a/src/ADNLPProblems/toint.jl +++ b/src/ADNLPProblems/toint.jl @@ -12,16 +12,6 @@ function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) wher 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 end return s / n end diff --git a/src/ADNLPProblems/trig.jl b/src/ADNLPProblems/trig.jl index b4b4b9fd..a5310b51 100644 --- a/src/ADNLPProblems/trig.jl +++ b/src/ADNLPProblems/trig.jl @@ -11,15 +11,6 @@ function trig(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where bij = (i + j) / 10 s += aij * sin(x[j]) + bij * cos(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 - s += aij * sin(x[j]) + bij * cos(x[j]) - end - end end return s / n end From fff0281ced831d43e5d9d5bbd39b4af9acc4588e Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Wed, 19 Nov 2025 01:13:49 +0530 Subject: [PATCH 09/17] meta --- src/Meta/toint.jl | 1 - src/Meta/trig.jl | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Meta/toint.jl b/src/Meta/toint.jl index b01aaa0d..f8122081 100644 --- a/src/Meta/toint.jl +++ b/src/Meta/toint.jl @@ -24,4 +24,3 @@ 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 diff --git a/src/Meta/trig.jl b/src/Meta/trig.jl index 731a7bef..c64a2eca 100644 --- a/src/Meta/trig.jl +++ b/src/Meta/trig.jl @@ -24,4 +24,3 @@ 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 From fbfe1e2673cbe66b9a75cb87308ae959a5b01512 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Wed, 19 Nov 2025 01:17:32 +0530 Subject: [PATCH 10/17] PureJuMP --- src/PureJuMP/toint.jl | 13 +------------ src/PureJuMP/trig.jl | 9 --------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/src/PureJuMP/toint.jl b/src/PureJuMP/toint.jl index a967cc27..f4ef653a 100644 --- a/src/PureJuMP/toint.jl +++ b/src/PureJuMP/toint.jl @@ -21,23 +21,12 @@ function toint(args...; n::Int = default_nvar, kwargs...) (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 + for j = max(1, i - 2):min(n, i + 2) 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) ) diff --git a/src/PureJuMP/trig.jl b/src/PureJuMP/trig.jl index a135b21f..14c3afd7 100644 --- a/src/PureJuMP/trig.jl +++ b/src/PureJuMP/trig.jl @@ -23,15 +23,6 @@ function trig(args...; n::Int = default_nvar, kwargs...) 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 ) ) From 8d5e0905b0dd22d19c5ba6bca978befdfc54bfe4 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Wed, 19 Nov 2025 02:38:30 +0530 Subject: [PATCH 11/17] Update toint.jl --- src/ADNLPProblems/toint.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ADNLPProblems/toint.jl b/src/ADNLPProblems/toint.jl index f00b5d49..18d9805e 100644 --- a/src/ADNLPProblems/toint.jl +++ b/src/ADNLPProblems/toint.jl @@ -8,8 +8,8 @@ function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) wher for j = max(1, i - 2):min(n, i + 2) aij = 5 * (1 + mod(i, 5) + mod(j, 5)) - bij = (i + j) / 10 - cj = (1 + j) / 10 + bij = (i + j) // 10 + cj = (1 + j) // 10 s += aij * sin(bij + ci * x[i] + cj * x[j]) end end From e76e90e6acb6c8322e71a539cf9309ffafbe52fa Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Wed, 19 Nov 2025 02:38:52 +0530 Subject: [PATCH 12/17] Update trig.jl --- src/ADNLPProblems/trig.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ADNLPProblems/trig.jl b/src/ADNLPProblems/trig.jl index a5310b51..6d6f3dd4 100644 --- a/src/ADNLPProblems/trig.jl +++ b/src/ADNLPProblems/trig.jl @@ -8,7 +8,7 @@ function trig(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where for j = max(1, i - 2):min(n, i + 2) aij = 5 * (1 + mod(i, 5) + mod(j, 5)) - bij = (i + j) / 10 + bij = (i + j) // 10 s += aij * sin(x[j]) + bij * cos(x[j]) end end From 5e003e5621c3d39b5564eaab74e2d2ff4cc634cd Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Wed, 19 Nov 2025 03:06:02 +0530 Subject: [PATCH 13/17] Update toint.jl --- src/ADNLPProblems/toint.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ADNLPProblems/toint.jl b/src/ADNLPProblems/toint.jl index 18d9805e..7a45473d 100644 --- a/src/ADNLPProblems/toint.jl +++ b/src/ADNLPProblems/toint.jl @@ -4,7 +4,7 @@ function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) wher function f(x; n = length(x)) s = zero(T) for i = 1:n - ci = 1 + (i / 10) + ci = 1 + (i // 10) for j = max(1, i - 2):min(n, i + 2) aij = 5 * (1 + mod(i, 5) + mod(j, 5)) From e5c988264785ad626d8396c5a9ebc758791367c0 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Mon, 24 Nov 2025 02:28:46 +0530 Subject: [PATCH 14/17] Update src/ADNLPProblems/toint.jl Co-authored-by: Tangi Migot --- src/ADNLPProblems/toint.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ADNLPProblems/toint.jl b/src/ADNLPProblems/toint.jl index 7a45473d..6a6e3c51 100644 --- a/src/ADNLPProblems/toint.jl +++ b/src/ADNLPProblems/toint.jl @@ -9,7 +9,7 @@ function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) wher for j = max(1, i - 2):min(n, i + 2) aij = 5 * (1 + mod(i, 5) + mod(j, 5)) bij = (i + j) // 10 - cj = (1 + j) // 10 + cj = 1 + (j // 10) s += aij * sin(bij + ci * x[i] + cj * x[j]) end end From 8b80602410186f8fe7d356a9fe90f95cacffb2ab Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Wed, 19 Nov 2025 02:11:27 +0530 Subject: [PATCH 15/17] fixing Float64 issue in toint and trig problems --- src/ADNLPProblems/toint.jl | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ADNLPProblems/toint.jl b/src/ADNLPProblems/toint.jl index 6a6e3c51..081f4928 100644 --- a/src/ADNLPProblems/toint.jl +++ b/src/ADNLPProblems/toint.jl @@ -1,21 +1,21 @@ export toint function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} - function f(x; n = length(x)) - s = zero(T) - for i = 1:n - ci = 1 + (i // 10) + function f(x; n = length(x)) + s = zero(T) + for i ∈ 1:n + ci = 1 + (i // 10) - for j = max(1, i - 2):min(n, i + 2) - 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 - return s / n - end + for j ∈ max(1, i-2):min(n, i+2) + 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 + return s / n + end - x0 = fill(one(T), n) - return ADNLPModels.ADNLPModel(f, x0, name = "toint"; kwargs...) + x0 = fill(one(T), n) + return ADNLPModels.ADNLPModel(f, x0, name = "toint"; kwargs...) end From 5f03f4734b7d66026cc265def3106c0a6783a0b5 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Mon, 24 Nov 2025 04:32:27 +0530 Subject: [PATCH 16/17] further changes --- src/ADNLPProblems/toint.jl | 6 +++++- src/PureJuMP/toint.jl | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ADNLPProblems/toint.jl b/src/ADNLPProblems/toint.jl index 081f4928..4efaf232 100644 --- a/src/ADNLPProblems/toint.jl +++ b/src/ADNLPProblems/toint.jl @@ -5,8 +5,12 @@ function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) wher s = zero(T) for i ∈ 1:n ci = 1 + (i // 10) + js = max(1, i-2):min(n, i+2) + if iseven(n) + js = sort(collect(union(collect(js), [j for j in (i + n ÷ 2, i - n ÷ 2) if 1 <= j <= n]))) + end - for j ∈ max(1, i-2):min(n, i+2) + for j ∈ js aij = 5 * (1 + mod(i, 5) + mod(j, 5)) bij = (i + j) // 10 cj = (1 + j) // 10 diff --git a/src/PureJuMP/toint.jl b/src/PureJuMP/toint.jl index f4ef653a..9b69af88 100644 --- a/src/PureJuMP/toint.jl +++ b/src/PureJuMP/toint.jl @@ -21,7 +21,11 @@ function toint(args...; n::Int = default_nvar, kwargs...) (1 / n) * sum(begin ci = 1 + i / 10 s = zero(Float64) - for j = max(1, i - 2):min(n, i + 2) + js = max(1, i - 2):min(n, i + 2) + if iseven(n) + js = sort(collect(union(collect(js), [j for j in (i + n ÷ 2, i - n ÷ 2) if 1 <= j <= n]))) + end + for j in js aij = 5 * (1 + mod(i, 5) + mod(j, 5)) bij = (i + j) / 10 cj = 1 + j / 10 From c626f5f2cd1f9a1d1d671dc0b90298aa30c1f1dc Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Mon, 24 Nov 2025 05:00:50 +0530 Subject: [PATCH 17/17] trig changes --- src/ADNLPProblems/trig.jl | 6 +++++- src/PureJuMP/trig.jl | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ADNLPProblems/trig.jl b/src/ADNLPProblems/trig.jl index 6d6f3dd4..722e449c 100644 --- a/src/ADNLPProblems/trig.jl +++ b/src/ADNLPProblems/trig.jl @@ -6,7 +6,11 @@ function trig(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where for i = 1:n s += i * (1 - cos(x[i])) - for j = max(1, i - 2):min(n, i + 2) + js = max(1, i - 2):min(n, i + 2) + if iseven(n) + js = sort(collect(union(collect(js), [j for j in (i + n ÷ 2, i - n ÷ 2) if 1 <= j <= n]))) + end + for j in js aij = 5 * (1 + mod(i, 5) + mod(j, 5)) bij = (i + j) // 10 s += aij * sin(x[j]) + bij * cos(x[j]) diff --git a/src/PureJuMP/trig.jl b/src/PureJuMP/trig.jl index 14c3afd7..eb7abadc 100644 --- a/src/PureJuMP/trig.jl +++ b/src/PureJuMP/trig.jl @@ -20,9 +20,10 @@ function trig(args...; n::Int = default_nvar, kwargs...) 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) + ( + sum(5 * (1 + mod(i, 5) + mod(j, 5)) * sin(x[j]) + (i + j) / 10 * cos(x[j]) for j in ( + iseven(n) ? sort(collect(union(collect(max(1, i - 2):min(n, i + 2)), [j for j in (i + n ÷ 2, i - n ÷ 2) if 1 <= j <= n]))) : max(1, i - 2):min(n, i + 2) + )) ) for i = 1:n ) )