diff --git a/src/ADNLPProblems/clplatea.jl b/src/ADNLPProblems/clplatea.jl index 3ca816db..b6c21d7c 100644 --- a/src/ADNLPProblems/clplatea.jl +++ b/src/ADNLPProblems/clplatea.jl @@ -1,20 +1,29 @@ export clplatea -function clplatea(; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T} +function clplatea(; + n::Int = default_nvar, + type::Val{T} = Val(Float64), + wght = -0.1, + kwargs..., +) where {T} p = floor(Int, sqrt(n)) p * p != n && @warn("clplatea: number of variables adjusted from $n down to $(p*p)") n = p * p - hp2 = 0.5 * p^2 + hp2 = T(1 / 2) * p^2 function f(x) - return (wght * x[p, p]) + + return (T(wght) * x[p + (p - 1) * p]) + sum( - sum(0.5 * (x[i, j] - x[i, j - 1])^2 + hp2 * (x[i, j] - x[i, j - 1])^4 for j = 2:p) for - i = 2:p + sum( + T(1 / 2) * (x[i + (j - 1) * p] - x[i + (j - 2) * p])^2 + + hp2 * (x[i + (j - 1) * p] - x[i + (j - 2) * p])^4 for j = 2:p + ) for i = 2:p ) + - sum(0.5 * (x[2, j])^2 + hp2 * (x[2, j])^4 for j = 2:p) + + sum(T(1 / 2) * (x[2 + (j - 1) * p])^2 + hp2 * (x[2 + (j - 1) * p])^4 for j = 2:p) + sum( - sum(0.5 * (x[i, j] - x[i - 1, j])^2 + hp2 * (x[i, j] - x[i - 1, j])^4 for j = 2:p) for - i = 3:p + sum( + T(1 / 2) * (x[i + (j - 1) * p] - x[i - 1 + (j - 1) * p])^2 + + hp2 * (x[i + (j - 1) * p] - x[i - 1 + (j - 1) * p])^4 for j = 2:p + ) for i = 3:p ) end x0 = zeros(T, n) diff --git a/src/ADNLPProblems/clplateb.jl b/src/ADNLPProblems/clplateb.jl index 4fe34dac..7cb8828b 100644 --- a/src/ADNLPProblems/clplateb.jl +++ b/src/ADNLPProblems/clplateb.jl @@ -1,22 +1,30 @@ export clplateb -function clplateb(; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T} +function clplateb(; + n::Int = default_nvar, + type::Val{T} = Val(Float64), + wght = -0.1, + kwargs..., +) where {T} p = floor(Int, sqrt(n)) p * p != n && @warn("clplateb: number of variables adjusted from $n down to $(p*p)") n = p * p - hp2 = 0.5 * p^2 - wght = -T(0.1) - disw = wght / (p - 1) + hp2 = T(1 / 2) * p^2 + disw = T(wght) / (p - 1) function f(x) - return sum(disw * x[p, j] for j = 1:p) + + return sum(disw * x[p + (j - 1) * p] for j = 1:p) + sum( - sum(0.5 * (x[i, j] - x[i, j - 1])^2 + hp2 * (x[i, j] - x[i, j - 1])^4 for j = 2:p) for - i = 2:p + sum( + T(1 / 2) * (x[i + (j - 1) * p] - x[i + (j - 2) * p])^2 + + hp2 * (x[i + (j - 1) * p] - x[i + (j - 2) * p])^4 for j = 2:p + ) for i = 2:p ) + - sum(0.5 * (x[2, j])^2 + hp2 * (x[2, j])^4 for j = 2:p) + + sum(T(1 / 2) * (x[2 + (j - 1) * p])^2 + hp2 * (x[2 + (j - 1) * p])^4 for j = 2:p) + sum( - sum(0.5 * (x[i, j] - x[i - 1, j])^2 + hp2 * (x[i, j] - x[i - 1, j])^4 for j = 2:p) for - i = 3:p + sum( + T(1 / 2) * (x[i + (j - 1) * p] - x[i - 1 + (j - 1) * p])^2 + + hp2 * (x[i + (j - 1) * p] - x[i - 1 + (j - 1) * p])^4 for j = 2:p + ) for i = 3:p ) end x0 = zeros(T, n) diff --git a/src/ADNLPProblems/clplatec.jl b/src/ADNLPProblems/clplatec.jl index ddebc533..3543c61f 100644 --- a/src/ADNLPProblems/clplatec.jl +++ b/src/ADNLPProblems/clplatec.jl @@ -1,27 +1,36 @@ export clplatec -function clplatec(; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T} +function clplatec(; + n::Int = default_nvar, + type::Val{T} = Val(Float64), + wght = -0.1, + r = 0.99, + l = 0.01, + kwargs..., +) where {T} p = floor(Int, sqrt(n)) p * p != n && @warn("clplatec: number of variables adjusted from $n down to $(p*p)") n = p * p - wght = -T(0.1) - r = T(0.99) - l = T(0.01) - hp2 = 0.5 * p^2 - wr = wght * r - wl = wght * l + + hp2 = T(1 / 2) * p^2 + wr = T(wght * r) + wl = T(wght * l) function f(x) - return wr * x[p, p] + - wl * x[p, 1] + + return wr * x[p + (p - 1) * p] + + wl * x[p] + sum( - sum(hp2 * (x[i, j] - x[i, j - 1])^2 + (x[i, j] - x[i, j - 1])^4 for j = 2:p) for - i = 2:p + sum( + hp2 * (x[i + (j - 1) * p] - x[i + (j - 2) * p])^2 + + (x[i + (j - 1) * p] - x[i + (j - 2) * p])^4 for j = 2:p + ) for i = 2:p ) + sum( - sum(0.5 * (x[i, j] - x[i - 1, j])^2 + (x[i, j] - x[i - 1, j])^4 for j = 2:p) for - i = 3:p + sum( + T(1 / 2) * (x[i + (j - 1) * p] - x[i - 1 + (j - 1) * p])^2 + + (x[i + (j - 1) * p] - x[i - 1 + (j - 1) * p])^4 for j = 2:p + ) for i = 3:p ) + - sum(0.5 * (x[2, j])^2 + (x[2, j])^4 for j = 2:p) + sum(T(1 / 2) * (x[2 + (j - 1) * p])^2 + (x[2 + (j - 1) * p])^4 for j = 2:p) end x0 = zeros(T, n) return ADNLPModels.ADNLPModel(f, x0, name = "clplatec"; kwargs...) diff --git a/src/ADNLPProblems/fminsrf2.jl b/src/ADNLPProblems/fminsrf2.jl index 5e80c88e..39d2bc91 100644 --- a/src/ADNLPProblems/fminsrf2.jl +++ b/src/ADNLPProblems/fminsrf2.jl @@ -8,9 +8,9 @@ function fminsrf2(; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs.. p * p != n && @warn("fminsrf2: number of variables adjusted from $n down to $(p*p)") n = p * p - h00 = 1.0 - slopej = 4.0 - slopei = 8.0 + h00 = one(T) + slopej = T(4) + slopei = T(8) scale = (p - 1)^2 @@ -20,23 +20,26 @@ function fminsrf2(; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs.. h10 = h00 + slopei mid = div(p, 2) - x0 = zeros(p, p) + x0 = zeros(T, p * p) I = 2:(p - 1) J = 1:p - x0[I, 1] .= (I .- 1) * ston .+ h01 - x0[I, p] .= (I .- 1) * ston .+ h00 - x0[1, J] .= (J .- 1) * wtoe .+ h00 - x0[p, J] .= (J .- 1) * wtoe .+ h10 + x0[I] .= (I .- 1) * ston .+ h01 + x0[I .+ (p .- 1) * p] .= (I .- 1) * ston .+ h00 + x0[1 .+ (J .- 1) * p] .= (J .- 1) * wtoe .+ h00 + x0[p .+ (J .- 1) * p] .= (J .- 1) * wtoe .+ h10 function f(x) n = length(x) return sum( sum( - 100.0 * sqrt( - 0.5 * (p - 1)^2 * ((x[i, j] - x[i + 1, j + 1])^2 + (x[i + 1, j] - x[i, j + 1])^2) + 1.0, + 100 * sqrt( + T(1 / 2) * + (p - 1)^2 * + ((x[i + (j - 1) * p] - x[i + 1 + j * p])^2 + (x[i + 1 + (j - 1) * p] - x[i + j * p])^2) + + 1, ) / scale for i = 1:(p - 1) ) for j = 1:(p - 1) - ) + 100.0 * (x[mid, mid])^2 / n + ) + 100 * (x[mid + (mid - 1) * p])^2 / n end return ADNLPModels.ADNLPModel(f, x0, name = "fminsrf2"; kwargs...) end diff --git a/test/runtests.jl b/test/runtests.jl index 67b8f694..c20f0699 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -43,7 +43,6 @@ for prob in names(PureJuMP) model = prob_fn(ndef) prob == :hs61 && continue #because nlpmodelsjump is not working here https://github.com/JuliaSmoothOptimizers/NLPModelsJuMP.jl/issues/84 - prob in [:clplatea, :clplateb, :clplatec, :fminsrf2] && continue # issue because variable is a matrix nlp_jump = MathOptNLPModel(model) nlp_ad = eval(Meta.parse("ADNLPProblems.$(prob)()")) @@ -72,7 +71,6 @@ end for prob in names(ADNLPProblems) prob == :ADNLPProblems && continue - prob in [:clplatea, :clplateb, :clplatec, :fminsrf2] && continue # issue because variable is a matrix println(prob)