diff --git a/src/ADNLPProblems/hs117.jl b/src/ADNLPProblems/hs117.jl index 5da9ccf0d..88ba88d86 100644 --- a/src/ADNLPProblems/hs117.jl +++ b/src/ADNLPProblems/hs117.jl @@ -1,24 +1,28 @@ export hs117 function hs117(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} - a = Rational{Int}[-16 2 0 1 0; - 0 -2 0 4 2; - -7 // 2 0 2 0 0; - 0 -2 0 -4 -1; - 0 -9 -2 1 -14 // 5; - 2 0 -4 0 0; - -1 -1 -1 -1 -1; - -1 -2 -3 -2 -1; - 1 2 3 4 5; - 1 1 1 1 1] + a = Rational{Int}[ + -16 2 0 1 0; + 0 -2 0 4 2; + -7 // 2 0 2 0 0; + 0 -2 0 -4 -1; + 0 -9 -2 1 -14 // 5; + 2 0 -4 0 0; + -1 -1 -1 -1 -1; + -1 -2 -3 -2 -1; + 1 2 3 4 5; + 1 1 1 1 1 + ] b = [-40, -2, -25 // 100, -4, -4, -1, -40, -60, 5, 1] - c = [ 30 -20 -10 32 -10; - -20 39 -6 -31 32; - -10 -6 10 -6 -10; - 32 -31 -6 39 -20; - -10 32 -10 -20 30] + c = [ + 30 -20 -10 32 -10; + -20 39 -6 -31 32; + -10 -6 10 -6 -10; + 32 -31 -6 39 -20; + -10 32 -10 -20 30 + ] d = [4, 8, 10, 6, 2] diff --git a/src/ADNLPProblems/hs119.jl b/src/ADNLPProblems/hs119.jl index c6b74393d..730521323 100644 --- a/src/ADNLPProblems/hs119.jl +++ b/src/ADNLPProblems/hs119.jl @@ -1,15 +1,271 @@ export hs119 function hs119(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} - Q_rows = [1, 2, 2, 3, 1, 4, 5, 5, 6, 1, 2, 3, 4, 7, 1, 6, 8, 3, 9, 2, 3, 5, 8, 10, 4, 7, 11, 5, 9, 12, 7, 11, 13, 3, 10, 12, 13, 14, 4, 6, 8, 15, 1, 5, 9, 16] - Q_cols = [1, 2, 3, 3, 4, 4, 5, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16] + Q_rows = [ + 1, + 2, + 2, + 3, + 1, + 4, + 5, + 5, + 6, + 1, + 2, + 3, + 4, + 7, + 1, + 6, + 8, + 3, + 9, + 2, + 3, + 5, + 8, + 10, + 4, + 7, + 11, + 5, + 9, + 12, + 7, + 11, + 13, + 3, + 10, + 12, + 13, + 14, + 4, + 6, + 8, + 15, + 1, + 5, + 9, + 16, + ] + Q_cols = [ + 1, + 2, + 3, + 3, + 4, + 4, + 5, + 6, + 6, + 7, + 7, + 7, + 7, + 7, + 8, + 8, + 8, + 9, + 9, + 10, + 10, + 10, + 10, + 10, + 11, + 11, + 11, + 12, + 12, + 12, + 13, + 13, + 13, + 14, + 14, + 14, + 14, + 14, + 15, + 15, + 15, + 15, + 16, + 16, + 16, + 16, + ] - clinrows = [1, 2, 3, 4, 7, 1, 3, 4, 6, 8, 1, 2, 4, 6, 8, 1, 2, 4, 5, 7, 8, 1, 2, 3, 5, 6, 8, 1, 3, 4, 5, 6, 1, 2, 4, 5, 6, 7, 8, 1, 3, 5, 6, 8, 1, 7, 2, 3, 4, 5, 6, 7, 8] - clincols = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 10, 11, 12, 13, 14, 15, 16] - clinvals = T[0.22, -1.46, 1.29, -1.1, 1.12, 0.2, -0.89, -1.06, -1.72, 0.45, 0.19, -1.3, 0.95, -0.33, 0.26, 0.25, 1.82, -0.54, -1.43, 0.31, -1.1, 0.15, -1.15, -1.16, 1.51, 1.62, 0.58, 0.11, -0.96, -1.78, 0.59, 1.24, 0.12, 0.8, -0.41, -0.33, 0.21, 1.12, -1.03, 0.13, -0.49, -0.43, -0.26, 0.1, 1.0, -0.36, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] + clinrows = [ + 1, + 2, + 3, + 4, + 7, + 1, + 3, + 4, + 6, + 8, + 1, + 2, + 4, + 6, + 8, + 1, + 2, + 4, + 5, + 7, + 8, + 1, + 2, + 3, + 5, + 6, + 8, + 1, + 3, + 4, + 5, + 6, + 1, + 2, + 4, + 5, + 6, + 7, + 8, + 1, + 3, + 5, + 6, + 8, + 1, + 7, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + ] + clincols = [ + 1, + 1, + 1, + 1, + 1, + 2, + 2, + 2, + 2, + 2, + 3, + 3, + 3, + 3, + 3, + 4, + 4, + 4, + 4, + 4, + 4, + 5, + 5, + 5, + 5, + 5, + 5, + 6, + 6, + 6, + 6, + 6, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 8, + 8, + 8, + 8, + 8, + 9, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + ] + clinvals = T[ + 0.22, + -1.46, + 1.29, + -1.1, + 1.12, + 0.2, + -0.89, + -1.06, + -1.72, + 0.45, + 0.19, + -1.3, + 0.95, + -0.33, + 0.26, + 0.25, + 1.82, + -0.54, + -1.43, + 0.31, + -1.1, + 0.15, + -1.15, + -1.16, + 1.51, + 1.62, + 0.58, + 0.11, + -0.96, + -1.78, + 0.59, + 1.24, + 0.12, + 0.8, + -0.41, + -0.33, + 0.21, + 1.12, + -1.03, + 0.13, + -0.49, + -0.43, + -0.26, + 0.1, + 1.0, + -0.36, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ] function f(x; rows = Q_rows, cols = Q_cols) - return sum((x[rows[k]]^2 + x[rows[k]] + 1) * (x[cols[k]]^2 + x[cols[k]] + 1) for k in 1:46) + return sum((x[rows[k]]^2 + x[rows[k]] + 1) * (x[cols[k]]^2 + x[cols[k]] + 1) for k = 1:46) end x0 = 10 * ones(T, 16) @@ -35,5 +291,17 @@ function hs119(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) wher 36.8, -24, ] - return ADNLPModels.ADNLPModel(f, x0, lvar, uvar, clinrows, clincols, clinvals, lcon, ucon, name = "hs119"; kwargs...) + return ADNLPModels.ADNLPModel( + f, + x0, + lvar, + uvar, + clinrows, + clincols, + clinvals, + lcon, + ucon, + name = "hs119"; + kwargs..., + ) end diff --git a/src/ADNLPProblems/lincon.jl b/src/ADNLPProblems/lincon.jl index 178371b48..e4d18007a 100644 --- a/src/ADNLPProblems/lincon.jl +++ b/src/ADNLPProblems/lincon.jl @@ -6,7 +6,8 @@ function lincon(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) whe clinrows = [5, 6, 5, 6, 8, 9, 10, 3, 2, 11, 11, 4, 4, 4, 7, 7, 1] clincols = [1, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] - clinvals = T[1.0, 3.0, 2.0, 4.0, 9.0, 12.0, 15.0, 4.0, -2.0, 5.0, 6.0, 1.0, 2.0, 3.0, 1.0, -1.0, 15.0] + clinvals = + T[1.0, 3.0, 2.0, 4.0, 9.0, 12.0, 15.0, 4.0, -2.0, 5.0, 6.0, 1.0, 2.0, 3.0, 1.0, -1.0, 15.0] lcon = T[22.0, -1.0, 1.0, 1.0, -5.0, -6.0, -Inf, -Inf, -Inf, -Inf, -11.0] ucon = T[22.0, -1.0, 1.0, Inf, Inf, Inf, 16.0, 1.0, 2.0, 3.0, 9.0] diff --git a/src/ADNLPProblems/toint.jl b/src/ADNLPProblems/toint.jl index 6812d5b5a..84cdec13e 100644 --- a/src/ADNLPProblems/toint.jl +++ b/src/ADNLPProblems/toint.jl @@ -1,40 +1,40 @@ 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) - jmin = max(1, i - 2) - jmax = min(n, i + 2) - for j ∈ jmin:jmax - 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 + function f(x; n = length(x)) + s = zero(T) + for i ∈ 1:n + ci = 1 + (i // 10) + jmin = max(1, i - 2) + jmax = min(n, i + 2) + for j ∈ jmin:jmax + 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) - half = n ÷ 2 - j1 = i + half - if 1 <= j1 <= n && (j1 < jmin || j1 > jmax) - aij = 5 * (1 + mod(i, 5) + mod(j1, 5)) - bij = (i + j1) // 10 - cj = 1 + j1 // 10 - s += aij * sin(bij + ci * x[i] + cj * x[j1]) - end - j2 = i - half - if 1 <= j2 <= n && j2 != j1 && (j2 < jmin || j2 > jmax) - aij = 5 * (1 + mod(i, 5) + mod(j2, 5)) - bij = (i + j2) // 10 - cj = 1 + j2 // 10 - s += aij * sin(bij + ci * x[i] + cj * x[j2]) - end - end - end - return s / n - end + if iseven(n) + half = n ÷ 2 + j1 = i + half + if 1 <= j1 <= n && (j1 < jmin || j1 > jmax) + aij = 5 * (1 + mod(i, 5) + mod(j1, 5)) + bij = (i + j1) // 10 + cj = 1 + j1 // 10 + s += aij * sin(bij + ci * x[i] + cj * x[j1]) + end + j2 = i - half + if 1 <= j2 <= n && j2 != j1 && (j2 < jmin || j2 > jmax) + aij = 5 * (1 + mod(i, 5) + mod(j2, 5)) + bij = (i + j2) // 10 + cj = 1 + j2 // 10 + s += aij * sin(bij + ci * x[i] + cj * x[j2]) + end + 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 diff --git a/src/ADNLPProblems/trig.jl b/src/ADNLPProblems/trig.jl index c2c519052..7d1de0ab8 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 jmin = max(1, i - 2) jmax = min(n, i + 2) - for j in jmin:jmax + for j = jmin:jmax 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/hs117.jl b/src/PureJuMP/hs117.jl index 722a4398f..7bbf6599e 100644 --- a/src/PureJuMP/hs117.jl +++ b/src/PureJuMP/hs117.jl @@ -33,11 +33,13 @@ function hs117(args...; kwargs...) b = [-40, -2, -0.25, -4, -4, -1, -40, -60, 5, 1] - c = Float64[ 30 -20 -10 32 -10; - -20 39 -6 -31 32; - -10 -6 10 -6 -10; - 32 -31 -6 39 -20; - -10 32 -10 -20 30] + c = Float64[ + 30 -20 -10 32 -10; + -20 39 -6 -31 32; + -10 -6 10 -6 -10; + 32 -31 -6 39 -20; + -10 32 -10 -20 30 + ] d = [4, 8, 10, 6, 2] diff --git a/src/PureJuMP/toint.jl b/src/PureJuMP/toint.jl index e864109e0..00914da93 100644 --- a/src/PureJuMP/toint.jl +++ b/src/PureJuMP/toint.jl @@ -24,7 +24,7 @@ function toint(args...; n::Int = default_nvar, kwargs...) jmin = max(1, i - 2) jmax = min(n, i + 2) - for j in jmin:jmax + for j = jmin:jmax aij = 5 * (1 + mod(i, 5) + mod(j, 5)) bij = (i + j) // 10 cj = 1 + j // 10 diff --git a/src/PureJuMP/trig.jl b/src/PureJuMP/trig.jl index 98250977f..eb7a9e194 100644 --- a/src/PureJuMP/trig.jl +++ b/src/PureJuMP/trig.jl @@ -19,13 +19,12 @@ function trig(args...; n::Int = default_nvar, kwargs...) model, Min, (1 / n) * sum( - i * (1 - cos(x[i])) + - ( + i * (1 - cos(x[i])) + ( begin jmin = max(1, i - 2) jmax = min(n, i + 2) s = zero(Float64) - for j in jmin:jmax + for j = jmin:jmax 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/trigb.jl b/src/PureJuMP/trigb.jl index 782564dbb..37ce6a375 100644 --- a/src/PureJuMP/trigb.jl +++ b/src/PureJuMP/trigb.jl @@ -19,8 +19,7 @@ function trigb(args...; n::Int = default_nvar, kwargs...) model, Min, sum( - i * - ((1 - cos(x[i])) + ((i == 1) ? sin(0) : sin(x[i - 1])) - ((i == n) ? 0 : sin(x[i + 1]))) + i * ((1 - cos(x[i])) + ((i == 1) ? sin(0) : sin(x[i - 1])) - ((i == n) ? 0 : sin(x[i + 1]))) for i = 1:n ) )