Skip to content

Commit

Permalink
Add integreq (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot committed Apr 10, 2023
1 parent 20a4c96 commit 82d0b72
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/ADNLPProblems/integreq.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export integreq

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

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

function integreq(
::Val{:nls};
n::Int = default_nvar,
type::Val{T} = Val(Float64),
kwargs...,
) where {T}
function F!(r, x; n = length(x))
h = 1 // (n + 1)
for i = 1:(n - 1)
r[i] = x[i] + h * ((1 - i * h) * sum(j * h * (x[j] + j * h + 1)^3 for j=1:i) + i * h * sum((1 - j * h) * (x[j] + j * h + 1)^3 for j=(i + 1):n)) / 2
end
r[n] = x[n] + h * ((1 - n * h) * sum(j * h * (x[j] + j * h + 1)^3 for j=1:n)) / 2
return r
end
x0 = T[j * (1 / (n + 1)) * (j * (1 / (n + 1)) - 1) for j=1:n]
return ADNLPModels.ADNLSModel!(F!, x0, n, name = "integreq-nls"; kwargs...)
end
26 changes: 26 additions & 0 deletions src/Meta/integreq.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
integreq_meta = Dict(
:nvar => 100,
:variable_nvar => true,
:ncon => 0,
:variable_ncon => false,
:minimize => true,
:name => "integreq",
: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_integreq_nvar(; n::Integer = default_nvar, kwargs...) = 1 * n + 0
get_integreq_ncon(; n::Integer = default_nvar, kwargs...) = 0
get_integreq_nlin(; n::Integer = default_nvar, kwargs...) = 0
get_integreq_nnln(; n::Integer = default_nvar, kwargs...) = 0
get_integreq_nequ(; n::Integer = default_nvar, kwargs...) = 0
get_integreq_nineq(; n::Integer = default_nvar, kwargs...) = 0
get_integreq_nls_nequ(; n::Integer = default_nvar, kwargs...) = n
34 changes: 34 additions & 0 deletions src/PureJuMP/integreq.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# The discrete integral problem.
#
# Source: problem 29 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 165 (p. 74) 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 integreq

"Linear function with `n` parameters and `m` observations - full rank"
function integreq(args...; n::Int = default_nvar, kwargs...)
h = 1 / (n + 1)

nlp = Model()

@variable(nlp, x[j = 1:n], start = 1.0)
x0 = [j * h * (j * h - 1) for j=1:n]
set_start_value.(x, x0)

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

return nlp
end

0 comments on commit 82d0b72

Please sign in to comment.