Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/ADNLPProblems/clplatea.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
28 changes: 18 additions & 10 deletions src/ADNLPProblems/clplateb.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
37 changes: 23 additions & 14 deletions src/ADNLPProblems/clplatec.jl
Original file line number Diff line number Diff line change
@@ -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...)
Expand Down
25 changes: 14 additions & 11 deletions src/ADNLPProblems/fminsrf2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
2 changes: 0 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)()"))
Expand Down Expand Up @@ -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)

Expand Down