Skip to content
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

Add problems argtrig, bard, biggs5, brownal and broyden3d #255

Merged
merged 5 commits into from
Apr 8, 2023
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
13 changes: 13 additions & 0 deletions src/ADNLPProblems/argtrig.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export argtrig

function argtrig(
;n::Int = default_nvar,
type::Val{T} = Val(Float64),
kwargs...,
) where {T}
function f(x; n = length(x))
return n - sum(cos(x[j]) + j * (1 - cos(x[j])) - sin(x[j]) for j=1:n)
end
x0 = 1 // n * ones(T, n)
return ADNLPModels.ADNLPModel(f, x0, name = "argtrig"; kwargs...)
end
27 changes: 27 additions & 0 deletions src/ADNLPProblems/bard.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export bard

function bard(;use_nls::Bool = false, kwargs...)
model = use_nls ? :nls : :nlp
return bard(Val(model); kwargs...)
end

function bard(::Val{:nlp}; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T}
y = Rational{Int}[0.14 0.18 0.22 0.25 0.29 0.32 0.35 0.39 0.37 0.58 0.73 0.16 1.34 2.10 4.39 ];
function f(x)
return 1 // 2 * sum(y[i] - (x[1] + i / ((16 - i) * x[2] + min(i, 16 - i) * x[3])) for i = 1:15)
end
x0 = ones(T, 3)
return ADNLPModels.ADNLPModel(f, x0, name = "bard"; kwargs...)
end

function bard(::Val{:nls}; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T}
y = Rational{Int}[0.14 0.18 0.22 0.25 0.29 0.32 0.35 0.39 0.37 0.58 0.73 0.16 1.34 2.10 4.39 ];
function F!(r, x, y = y)
for i=1:15
r[i] = y[i] - (x[1] + i / ((16 - i) * x[2] + min(i, 16 - i) * x[3]))
end
return r
end
x0 = ones(T, 3)
return ADNLPModels.ADNLSModel!(F!, x0, 15, name = "bard-nls"; kwargs...)
end
22 changes: 22 additions & 0 deletions src/ADNLPProblems/biggs5.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export biggs5

function biggs5(;
n::Int = default_nvar,
type::Val{T} = Val(Float64),
m::Int = 13,
kwargs...,
) where {T}
m = max(6, m)
z = [i // 10 for i = 1:m]
y = T[exp(-zi) - 5 * exp(-10 * zi) + 3 * exp(-4 * zi) for zi in z]
function f(x; m = m, z = z, y = y)
return sum(
x[3] * exp(-x[1] * z[i]) - x[4] * exp(-x[2] * z[i]) + x[6] * exp(-x[5] * z[i]) - y[i] for i = 1:m
)
end
x0 = ones(T, 6)
x0[2] = 2
lvar = vcat(-T(Inf) * ones(T, 5), T(3))
uvar = vcat(T(Inf) * ones(T, 5), T(3))
return ADNLPModels.ADNLPModel(f, x0, lvar, uvar, name = "biggs5"; kwargs...)
end
29 changes: 29 additions & 0 deletions src/ADNLPProblems/brownal.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export brownal

function brownal(;use_nls::Bool = false, kwargs...)
model = use_nls ? :nls : :nlp
return brownal(Val(model); kwargs...)
end

function brownal(::Val{:nlp}; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T}
function f(x; n = length(x))
sj = sum(x[j] for j = 1:n)
pj = prod(x[j] for j = 1:n)
return 1 // 2 * sum((x[i] + sj - (n + 1))^2 for i = 1:(n-1)) + 1 // 2 * (pj - 1)^2
end
x0 = 1 // 2 * ones(T, n)
return ADNLPModels.ADNLPModel(f, x0, name = "brownal"; kwargs...)
end

function brownal(::Val{:nls}; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T}
function F!(r, x; n = length(x))
sj = sum(x[j] for j = 1:n)
for i=1:(n-1)
r[i] = x[i] + sj - (n + 1)
end
r[n] = prod(x[j] for j = 1:n) - 1
return r
end
x0 = 1 // 2 * ones(T, n)
return ADNLPModels.ADNLSModel!(F!, x0, n, name = "brownal-nls"; kwargs...)
end
27 changes: 27 additions & 0 deletions src/ADNLPProblems/broyden3d.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export broyden3d

function broyden3d(;use_nls::Bool = false, kwargs...)
model = use_nls ? :nls : :nlp
return broyden3d(Val(model); kwargs...)
end

function broyden3d(::Val{:nlp}; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T}
function f(x; n = length(x))
return 1 // 2 * sum(((3 - 2 * x[i]) * x[i] - x[i - 1] - 2 * x[i + 1] + 1)^2 for i = 2:(n-1) ) + 1 // 2 * ( (3 - 2 * x[1]) * x[1] - 2 * x[2] + 1)^2 + 1 // 2 * ((3 - 2 * x[n]) * x[n] - x[n - 1] + 1)^2
end
x0 = -ones(T, n)
return ADNLPModels.ADNLPModel(f, x0, name = "broyden3d"; kwargs...)
end

function broyden3d(::Val{:nls}; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T}
function F!(r, x; n = length(x))
r[1] = (3 - 2 * x[1]) * x[1] - 2 * x[2] + 1
r[n] = (3 - 2 * x[n]) * x[n] - x[n - 1] + 1
for i=2:(n-1)
r[i] = (3 - 2 * x[i]) * x[i] - x[i - 1] - 2 * x[i + 1] + 1
end
return r
end
x0 = -ones(T, n)
return ADNLPModels.ADNLSModel!(F!, x0, n, name = "broyden3d-nls"; kwargs...)
end
26 changes: 26 additions & 0 deletions src/Meta/argtrig.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
argtrig_meta = Dict(
:nvar => 100,
:variable_nvar => true,
:ncon => 0,
:variable_ncon => false,
:minimize => true,
:name => "argtrig",
: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_argtrig_nvar(; n::Integer = default_nvar, kwargs...) = 1 * n + 0
get_argtrig_ncon(; n::Integer = default_nvar, kwargs...) = 0
get_argtrig_nlin(; n::Integer = default_nvar, kwargs...) = 0
get_argtrig_nnln(; n::Integer = default_nvar, kwargs...) = 0
get_argtrig_nequ(; n::Integer = default_nvar, kwargs...) = 0
get_argtrig_nineq(; n::Integer = default_nvar, kwargs...) = 0
get_argtrig_nls_nequ(; n::Integer = default_nvar, kwargs...) = 2 * n
26 changes: 26 additions & 0 deletions src/Meta/bard.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
bard_meta = Dict(
:nvar => 3,
:variable_nvar => true,
:ncon => 0,
:variable_ncon => false,
:minimize => true,
:name => "bard",
:has_equalities_only => false,
:has_inequalities_only => false,
:has_bounds => false,
:has_fixed_variables => false,
:objtype => :least_squares,
:contype => :unconstrained,
:best_known_lower_bound => -Inf,
:best_known_upper_bound => 500.0,
:is_feasible => true,
:defined_everywhere => missing,
:origin => :unknown,
)
get_bard_nvar(; n::Integer = default_nvar, kwargs...) = 3
get_bard_ncon(; n::Integer = default_nvar, kwargs...) = 0
get_bard_nlin(; n::Integer = default_nvar, kwargs...) = 0
get_bard_nnln(; n::Integer = default_nvar, kwargs...) = 0
get_bard_nequ(; n::Integer = default_nvar, kwargs...) = 0
get_bard_nineq(; n::Integer = default_nvar, kwargs...) = 0
get_bard_nls_nequ(; n::Integer = default_nvar, kwargs...) = 15
25 changes: 25 additions & 0 deletions src/Meta/biggs5.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
biggs5_meta = Dict(
:nvar => 6,
:variable_nvar => false,
:ncon => 0,
:variable_ncon => false,
:minimize => true,
:name => "biggs5",
:has_equalities_only => false,
:has_inequalities_only => false,
:has_bounds => true,
:has_fixed_variables => true,
:objtype => :other,
:contype => :unconstrained,
:best_known_lower_bound => -Inf,
:best_known_upper_bound => -3.156207810643302,
:is_feasible => true,
:defined_everywhere => missing,
:origin => :unknown,
)
get_biggs5_nvar(; n::Integer = default_nvar, kwargs...) = 6
get_biggs5_ncon(; n::Integer = default_nvar, kwargs...) = 0
get_biggs5_nlin(; n::Integer = default_nvar, kwargs...) = 0
get_biggs5_nnln(; n::Integer = default_nvar, kwargs...) = 0
get_biggs5_nequ(; n::Integer = default_nvar, kwargs...) = 0
get_biggs5_nineq(; n::Integer = default_nvar, kwargs...) = 0
26 changes: 26 additions & 0 deletions src/Meta/brownal.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
brownal_meta = Dict(
:nvar => 100,
:variable_nvar => true,
:ncon => 0,
:variable_ncon => false,
:minimize => true,
:name => "brownal",
:has_equalities_only => false,
:has_inequalities_only => false,
:has_bounds => false,
:has_fixed_variables => false,
:objtype => :least_squares,
:contype => :unconstrained,
:best_known_lower_bound => -Inf,
:best_known_upper_bound => 0.0,
:is_feasible => true,
:defined_everywhere => missing,
:origin => :unknown,
)
get_brownal_nvar(; n::Integer = default_nvar, kwargs...) = 1 * n + 0
get_brownal_ncon(; n::Integer = default_nvar, kwargs...) = 0
get_brownal_nlin(; n::Integer = default_nvar, kwargs...) = 0
get_brownal_nnln(; n::Integer = default_nvar, kwargs...) = 0
get_brownal_nequ(; n::Integer = default_nvar, kwargs...) = 0
get_brownal_nineq(; n::Integer = default_nvar, kwargs...) = 0
get_brownal_nls_nequ(; n::Integer = default_nvar, kwargs...) = 1 * n
26 changes: 26 additions & 0 deletions src/Meta/broyden3d.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
broyden3d_meta = Dict(
:nvar => 100,
:variable_nvar => true,
:ncon => 0,
:variable_ncon => false,
:minimize => true,
:name => "broyden3d",
:has_equalities_only => false,
:has_inequalities_only => false,
:has_bounds => false,
:has_fixed_variables => false,
:objtype => :least_squares,
:contype => :unconstrained,
:best_known_lower_bound => -Inf,
:best_known_upper_bound => 0.0,
:is_feasible => true,
:defined_everywhere => missing,
:origin => :unknown,
)
get_broyden3d_nvar(; n::Integer = default_nvar, kwargs...) = 1 * n + 0
get_broyden3d_ncon(; n::Integer = default_nvar, kwargs...) = 0
get_broyden3d_nlin(; n::Integer = default_nvar, kwargs...) = 0
get_broyden3d_nnln(; n::Integer = default_nvar, kwargs...) = 0
get_broyden3d_nequ(; n::Integer = default_nvar, kwargs...) = 0
get_broyden3d_nineq(; n::Integer = default_nvar, kwargs...) = 0
get_broyden3d_nls_nequ(; n::Integer = default_nvar, kwargs...) = 1 * n
36 changes: 36 additions & 0 deletions src/PureJuMP/argtrig.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Variable dimension trigonometric problem
# This problem is a sum of n least-squares groups, each of
# which has n+1 nonlinear elements. Its Hessian matrix is dense.
#
# Source: problem 26 in
# J.J. More, B.S. Garbow and K.E. Hillstrom,
# "Testing Unconstrained Optimization Software",
# ACM Transactions on Mathematical Software, vol. 7(1), pp. 17-41, 1981.
# Also problem 101 in
# A.R. Buckley,
# "Test functions for unconstrained minimization",
# TR 1989CS-3, Mathematics, statistics and computing centre,
# Dalhousie University, Halifax (CDN), 1989.
#
# classification NOR2-AN-V-V

export argtrig

"Linear function with `n` parameters and `m` observations - full rank"
function argtrig(args...; n::Int = default_nvar, m::Int = 2n, kwargs...)
m < n && @warn("argtrig: must have m ≥ n")
m = max(m, n)

nlp = Model()

@variable(nlp, x[j = 1:n], start = 1 / n)

@NLobjective(
nlp,
Min,
n - sum(cos(x[j]) + j * (1 - cos(x[j])) - sin(x[j]) for j=1:n)
)

return nlp
end
30 changes: 30 additions & 0 deletions src/PureJuMP/bard.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Bard problem in 3 variables.
# This function is a nonlinear least squares with 15 groups.
# Each group has a linear and a nonlinear element.
#
# Source: Problem 8 in
# J.J. More', B.S. Garbow and K.E. Hillstrom,
# "Testing Unconstrained Optimization Software",
# ACM Transactions on Mathematical Software, vol. 7(1), pp. 17-41, 1981.
#
# See also Buckley#16
#
# classification SUR2-AN-3-0

export bard

"Linear function with `n` parameters and `m` observations - full rank"
function bard(args...; n::Int = default_nvar, m::Int = 2n, kwargs...)
y = Rational{Int}[0.14 0.18 0.22 0.25 0.29 0.32 0.35 0.39 0.37 0.58 0.73 0.16 1.34 2.10 4.39 ];
nlp = Model()

@variable(nlp, x[j = 1:3], start = 1.0)

@NLobjective(
nlp,
Min,
0.5 * sum(y[i] - (x[1] + i / ((16 - i) * x[2] + min(i, 16 - i) * x[3])) for i = 1:15)
)

return nlp
end
35 changes: 35 additions & 0 deletions src/PureJuMP/biggs5.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Biggs problem in 5 variables.
# This function is a nonlinear least squares with 13 groups. It is a
# variation on the biggs6 problem where the 6-th variable is fixed to 3.
#
# Source: Inspited by problem 18 in
# J.J. More', B.S. Garbow and K.E. Hillstrom,
# "Testing Unconstrained Optimization Software",
# ACM Transactions on Mathematical Software, vol. 7(1), pp. 17-41, 1981.
# Also problem 74 in
# A.R. Buckley,
# "Test functions for unconstrained minimization",
# TR 1989CS-3, Mathematics, statistics and computing centre,
# Dalhousie University, Halifax (CDN), 1989.
#
# classification SXR2-AN-6-0
export biggs5

function biggs5(args...; n::Int = default_nvar, m::Int = 13, kwargs...)
m = max(6, m)
z = [i / 10 for i = 1:m]
y = [exp(-zi) - 5 * exp(-10 * zi) + 3 * exp(-4 * zi) for zi in z]
nlp = Model()
x0 = [1.0; 2.0; 1.0; 1.0; 1.0; 1.0]
@variable(nlp, x[i = 1:6], start = x0[i])
fix(x[6], 3)
@NLobjective(
nlp,
Min,
sum(
x[3] * exp(-x[1] * z[i]) - x[4] * exp(-x[2] * z[i]) + x[6] * exp(-x[5] * z[i]) - y[i] for
i = 1:m
)
)
return nlp
end
29 changes: 29 additions & 0 deletions src/PureJuMP/brownal.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The Brown almost linear problem in variable dimension. This is a nonlinear
# least-squares problems with n groups.
#
# Source: Problem 27 in
# J.J. More', B.S. Garbow and K.E. Hillstrom,
# "Testing Unconstrained Optimization Software",
# ACM Transactions on Mathematical Software, vol. 7(1), pp. 17-41, 1981.
# Alsso problem 79 in
# A.R. Buckley,
# "Test functions for unconstrained minimization",
# TR 1989CS-3, Mathematics, statistics and computing centre,
# Dalhousie University, Halifax (CDN), 1989.
#
export brownal

"Brownbs Model"
function brownal(args...; n::Int = default_nvar, kwargs...)
nlp = Model()

@variable(nlp, x[i = 1:n], start = 1/2)

@NLobjective(
nlp,
Min,
0.5 * sum((x[i] + sum(x[j] for j = 1:n) - (n + 1))^2 for i = 1:(n-1)) + 0.5 * (prod(x[j] for j = 1:n) - 1)^2
)

return nlp
end
Loading