Skip to content

Commit

Permalink
Add watson (#258)
Browse files Browse the repository at this point in the history
* Add `watson`
  • Loading branch information
tmigot authored Apr 12, 2023
1 parent ad26910 commit 03a07d7
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/ADNLPProblems/watson.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export watson

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

function watson(::Val{:nlp}; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T}
n = min(max(n, 2), 31)
function f(x; n = n)
Ti = eltype(x)
return 1 // 2 * sum((
sum((j - 1) * x[j] * (Ti(i) / 29)^(j-2) for j=2:n) - sum(x[j] * (Ti(i) / 29)^(j-1) for j=1:n)^2 - 1
)^2 for i=1:29) + 1 // 2 * (sum((j - 1) * x[j] * x[1]^(j-2) for j=2:n) - sum(x[j] * x[1]^(j-1) for j=1:n)^2 - 1)^2 + 1 // 2 * (sum((j - 1) * x[j] * (x[2] - x[1]^2 - 1)^(j-2) for j=2:n) - sum(x[j] * (x[2] - x[1]^2 - 1)^(j-1) for j=1:n)^2 - 1)
end
x0 = zeros(T, n)
return ADNLPModels.ADNLPModel(f, x0, name = "watson"; kwargs...)
end

function watson(::Val{:nls}; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T}
n = min(max(n, 2), 31)
function F!(r, x; n = n)
Ti = eltype(x)
for i=1:29
r[i] = sum((j - 1) * x[j] * (Ti(i) / 29)^(j-2) for j=2:n) - sum(x[j] * (Ti(i) / 29)^(j-1) for j=1:n)^2 - 1
end
r[30] = sum((j - 1) * x[j] * x[1]^(j-2) for j=2:n) - sum(x[j] * x[1]^(j-1) for j=1:n)^2 - 1
r[31] = sum((j - 1) * x[j] * (x[2] - x[1]^2 - 1)^(j-2) for j=2:n) - sum(x[j] * (x[2] - x[1]^2 - 1)^(j-1) for j=1:n)^2 - 1
return r
end
x0 = zeros(T, n)
return ADNLPModels.ADNLSModel!(F!, x0, 31, name = "watson-nls"; kwargs...)
end
26 changes: 26 additions & 0 deletions src/Meta/watson.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
watson_meta = Dict(
:nvar => 31,
:variable_nvar => true,
:ncon => 0,
:variable_ncon => false,
:minimize => true,
:name => "watson",
: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_watson_nvar(; n::Integer = default_nvar, kwargs...) = min(max(n, 2), 31)
get_watson_ncon(; n::Integer = default_nvar, kwargs...) = 0
get_watson_nlin(; n::Integer = default_nvar, kwargs...) = 0
get_watson_nnln(; n::Integer = default_nvar, kwargs...) = 0
get_watson_nequ(; n::Integer = default_nvar, kwargs...) = 0
get_watson_nineq(; n::Integer = default_nvar, kwargs...) = 0
get_watson_nls_nequ(; n::Integer = default_nvar, kwargs...) = 31
36 changes: 36 additions & 0 deletions src/PureJuMP/watson.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Watson problem in varaible dimension ( 2 <= n <= 31 ).
# This function is a nonlinear least squares with 31 groups.
#
# Source: problem 20 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 128 (p. 100) in
# A.R. Buckley,
# "Test functions for unconstrained minimization",
# TR 1989CS-3, Mathematics, statistics and computing centre,
# Dalhousie University, Halifax (CDN), 1989.
#
# SUR2-AN-V-0

export watson

function watson(args...; n::Int = default_nvar, kwargs...)
n = min(max(n, 2), 31)
m = 31

nlp = Model()

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

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

return nlp
end

0 comments on commit 03a07d7

Please sign in to comment.