Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d057548
Problem 14 and 15
arnavk23 Nov 3, 2025
3eef3eb
documentation
arnavk23 Nov 3, 2025
ab4800f
changes made acc. to review
arnavk23 Nov 4, 2025
49c9731
Update variational.jl
arnavk23 Nov 4, 2025
c956fb5
variational
arnavk23 Nov 4, 2025
4ac69d2
PureJuMP
arnavk23 Nov 4, 2025
edd428c
variational changes
arnavk23 Nov 4, 2025
ceaa624
boundary needing Float64 starts to match ADNLPProblems.boundary.
arnavk23 Nov 4, 2025
c2434a7
Fix variational/h080: use NonlinearExpr-only JuMP API; remove JuMP.re…
arnavk23 Nov 5, 2025
0a2b2e3
doc
arnavk23 Nov 5, 2025
7ef626b
variational problem using JuMP and ADNLProblems.jl
arnavk23 Nov 5, 2025
86d1fbf
Apply suggestions from code review
arnavk23 Nov 5, 2025
9301b1c
Update boundary.jl
arnavk23 Nov 5, 2025
8b167d0
Update boundary.jl
arnavk23 Nov 5, 2025
f8a3dd7
edits to variational
arnavk23 Nov 5, 2025
94532e8
JuliaFormatter
arnavk23 Nov 5, 2025
bc42c32
Apply suggestions from code review
arnavk23 Nov 6, 2025
f4f3cf4
Problem 15 correction
arnavk23 Nov 6, 2025
4b66e94
fixing variational problems and boundary problem
arnavk23 Nov 6, 2025
4b5ba91
variational
arnavk23 Nov 7, 2025
35db7cb
fix
arnavk23 Nov 7, 2025
17e3754
JuliaFormatted commit
arnavk23 Nov 7, 2025
b1c6dd9
just trying
arnavk23 Nov 7, 2025
aaacc0a
Update variational.jl
arnavk23 Nov 9, 2025
a896e54
Apply suggestions from code review
arnavk23 Nov 11, 2025
41f6aaa
variational Problem - reviewed changes
arnavk23 Nov 11, 2025
f380516
passing failing checks for variational problems
arnavk23 Nov 11, 2025
7cd697f
JuliaFormatter
arnavk23 Nov 11, 2025
7af470e
fixing float32 issue in variational problems
arnavk23 Nov 11, 2025
0befccc
going back to working version
arnavk23 Nov 11, 2025
5c9006b
Apply suggestions from code review
tmigot Nov 12, 2025
3b96935
Apply suggestions from code review
tmigot Nov 12, 2025
3d76a65
Update src/ADNLPProblems/variational.jl
tmigot Nov 12, 2025
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
46 changes: 46 additions & 0 deletions src/ADNLPProblems/boundary.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export boundary

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

function boundary(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
h = 1 // (n + 1)
function f(x; n = length(x))
s = zero(T)
for i = 1:n
xm = (i == 1) ? zero(T) : x[i - 1]
xp = (i == n) ? zero(T) : x[i + 1]
s += (2 * x[i] - xm - xp + (h^2 / 2) * (x[i] + i * h + 1)^3)^2
end
return s
end

x0 = Vector{T}(undef, n)
for i = 1:n
x0[i] = i * h * (1 - i * h)
end

return ADNLPModels.ADNLPModel(f, x0, name = "boundary", minimize = true; kwargs...)
end

function boundary(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
h = 1 // (n + 1)

function F!(r, x; n = length(x))
@inbounds for i = 1:n
xm = (i == 1) ? zero(T) : x[i - 1]
xp = (i == n) ? zero(T) : x[i + 1]
r[i] = 2 * x[i] - xm - xp + (h^2 / 2) * (x[i] + i * h + 1)^3
end
return r
end

x0 = Vector{T}(undef, n)
for i = 1:n
x0[i] = i * h * (1 - i * h)
end

return ADNLPModels.ADNLSModel!(F!, x0, n, name = "boundary-nls"; kwargs...)
end
26 changes: 26 additions & 0 deletions src/ADNLPProblems/variational.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export variational

function variational(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
h = 1 // (n + 1)
x0 = [begin
ih = i * h
convert(T, ih * (1 - ih))
end for i = 1:n]
f =
x -> begin
xext = vcat(zero(eltype(x)), x, zero(eltype(x)))
term1 = sum(x[i] * (x[i] - xext[i + 2]) / convert(eltype(x), h) for i = 1:n)
term2 = sum(
if eltype(x) <: AbstractFloat
d = xext[j + 2] - xext[j + 1]
abs(d) <= eps(eltype(x)) ? exp(xext[j + 1]) : (exp(xext[j + 2]) - exp(xext[j + 1])) / d
else
d = xext[j + 2] - xext[j + 1]
exp(xext[j + 1]) * expm1(d) / d
end for j = 0:n
)
return 2 * (term1 + n * (convert(eltype(x), h) / 2) * term2)
end

return ADNLPModels.ADNLPModel(f, x0, name = "variational", minimize = true; kwargs...)
end
27 changes: 27 additions & 0 deletions src/Meta/boundary.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
boundary_meta = Dict(
:nvar => 100,
:variable_nvar => true,
:ncon => 0,
:variable_ncon => false,
:minimize => true,
:name => "boundary",
: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 => Inf,
:is_feasible => true,
:defined_everywhere => missing,
:origin => :academic,
)

get_boundary_nvar(; n::Integer = default_nvar, kwargs...) = n
get_boundary_ncon(; n::Integer = default_nvar, kwargs...) = 0
get_boundary_nlin(; n::Integer = default_nvar, kwargs...) = 0
get_boundary_nnln(; n::Integer = default_nvar, kwargs...) = 0
get_boundary_nequ(; n::Integer = default_nvar, kwargs...) = 0
get_boundary_nineq(; n::Integer = default_nvar, kwargs...) = 0
get_boundary_nls_nequ(; n::Integer = default_nvar, kwargs...) = n
27 changes: 27 additions & 0 deletions src/Meta/variational.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
variational_meta = Dict(
:nvar => 100,
:variable_nvar => true,
:ncon => 0,
:variable_ncon => false,
:minimize => true,
:name => "variational",
: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 => Inf,
:is_feasible => true,
:defined_everywhere => missing,
:origin => :academic,
)

get_variational_nvar(; n::Integer = default_nvar, kwargs...) = n
get_variational_ncon(; n::Integer = default_nvar, kwargs...) = 0
get_variational_nlin(; n::Integer = default_nvar, kwargs...) = 0
get_variational_nnln(; n::Integer = default_nvar, kwargs...) = 0
get_variational_nequ(; n::Integer = default_nvar, kwargs...) = 0
get_variational_nineq(; n::Integer = default_nvar, kwargs...) = 0
get_variational_nls_nequ(; n::Integer = default_nvar, kwargs...) = 0
29 changes: 29 additions & 0 deletions src/PureJuMP/boundary.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Discrete boundary value problem
#
# Problem 14 in
# L. Luksan, C. Matonoha and J. Vlcek
# Sparse Test Problems for Unconstrained Optimization,
# Technical Report 1064,
# Institute of Computer Science,
# Academy of Science of the Czech Republic
#
# https://www.researchgate.net/publication/325314400_Sparse_Test_Problems_for_Unconstrained_Optimization
export boundary

function boundary(; n::Int = default_nvar, kwargs...)
h = 1 // (n + 1)
model = Model()
x0 = [i * h * (1 - i * h) for i = 1:n]
@variable(model, x[i = 1:n], start = x0[i])
@objective(
model,
Min,
sum(
(
2 * x[i] - (i == 1 ? 0 : x[i - 1]) - (i == n ? 0 : x[i + 1]) +
(h^2 / 2) * (x[i] + Float64(i) * h + 1)^3
)^2 for i = 1:n
)
)
return model
end
46 changes: 46 additions & 0 deletions src/PureJuMP/variational.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Discretization of a variational problem
#
# Problem 15 in
# L. Luksan, C. Matonoha and J. Vlcek
# Sparse Test Problems for Unconstrained Optimization,
# Technical Report 1064,
# Institute of Computer Science,
# Academy of Science of the Czech Republic
#
# https://www.researchgate.net/publication/325314400_Sparse_Test_Problems_for_Unconstrained_Optimization
export variational

function variational(; n::Int = default_nvar, kwargs...)
h = 1 // (n + 1)
x0 = [begin
ih = i * h
convert(Float64, ih * (1 - ih))
end for i = 1:n]
model = Model()
@variable(model, x[i = 1:n], start = x0[i])

@objective(
model,
Min,
2 * (
(sum(x[i] * (x[i] - x[i + 1]) / h for i = 1:(n - 1)) + x[n] * x[n] / h) +
n *
(h / 2) *
(
(1 + x[1]/2 + x[1]^2/6 + x[1]^3/24 + x[1]^4/120) +
sum(
exp(x[j]) * (
1 +
(x[j + 1] - x[j]) / 2 +
(x[j + 1] - x[j])^2 / 6 +
(x[j + 1] - x[j])^3 / 24 +
(x[j + 1] - x[j])^4 / 120
) for j = 1:(n - 1)
) +
exp(x[n]) * (1 + (0 - x[n]) / 2 + (0 - x[n])^2 / 6 + (0 - x[n])^3 / 24 + (0 - x[n])^4 / 120)
)
)
)

return model
end