-
Notifications
You must be signed in to change notification settings - Fork 49
Problem 14 and 15 #385
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
Merged
tmigot
merged 33 commits into
JuliaSmoothOptimizers:main
from
arnavk23:luksan/add-problems-5-12
Nov 13, 2025
+194
−0
Merged
Problem 14 and 15 #385
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
d057548
Problem 14 and 15
arnavk23 3eef3eb
documentation
arnavk23 ab4800f
changes made acc. to review
arnavk23 49c9731
Update variational.jl
arnavk23 c956fb5
variational
arnavk23 4ac69d2
PureJuMP
arnavk23 edd428c
variational changes
arnavk23 ceaa624
boundary needing Float64 starts to match ADNLPProblems.boundary.
arnavk23 c2434a7
Fix variational/h080: use NonlinearExpr-only JuMP API; remove JuMP.re…
arnavk23 0a2b2e3
doc
arnavk23 7ef626b
variational problem using JuMP and ADNLProblems.jl
arnavk23 86d1fbf
Apply suggestions from code review
arnavk23 9301b1c
Update boundary.jl
arnavk23 8b167d0
Update boundary.jl
arnavk23 f8a3dd7
edits to variational
arnavk23 94532e8
JuliaFormatter
arnavk23 bc42c32
Apply suggestions from code review
arnavk23 f4f3cf4
Problem 15 correction
arnavk23 4b66e94
fixing variational problems and boundary problem
arnavk23 4b5ba91
variational
arnavk23 35db7cb
fix
arnavk23 17e3754
JuliaFormatted commit
arnavk23 b1c6dd9
just trying
arnavk23 aaacc0a
Update variational.jl
arnavk23 a896e54
Apply suggestions from code review
arnavk23 41f6aaa
variational Problem - reviewed changes
arnavk23 f380516
passing failing checks for variational problems
arnavk23 7cd697f
JuliaFormatter
arnavk23 7af470e
fixing float32 issue in variational problems
arnavk23 0befccc
going back to working version
arnavk23 5c9006b
Apply suggestions from code review
tmigot 3b96935
Apply suggestions from code review
tmigot 3d76a65
Update src/ADNLPProblems/variational.jl
tmigot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = [(i * h) * (1 - i * h) for i = 1:n] | ||
tmigot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| function f(x) | ||
| term1 = zero(T) | ||
| for i = 1:n | ||
| xi = x[i] | ||
| xip = (i < n) ? x[i + 1] : zero(T) | ||
| term1 += xi * (xi - xip) / h | ||
| end | ||
|
|
||
| term2 = zero(T) | ||
| for j = 0:n | ||
| a = (j == 0) ? zero(T) : x[j] | ||
| b = (j == n) ? zero(T) : x[j + 1] | ||
| term2 += (exp(b) - exp(a)) / (b - a) | ||
| end | ||
|
|
||
| return 2 * (term1 + n * (h / 2) * term2) | ||
tmigot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| return ADNLPModels.ADNLPModel(f, x0, name = "variational"; kwargs...) | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 => false, | ||
| :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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] + i * h + 1)^3 | ||
| )^2 for i = 1:n | ||
| ) | ||
| ) | ||
| return model | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # 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 = [(i * h) * (1 - i * h) for i = 1:n] | ||
| model = Model() | ||
| @variable(model, x[i = 1:n], start = x0[i]) | ||
|
|
||
| @objective( | ||
arnavk23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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) * | ||
tmigot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ( | ||
| (exp(x[1]) - exp(0)) / (x[1] - 0) + | ||
| sum((exp(x[j + 1]) - exp(x[j])) / (x[j + 1] - x[j]) for j ∈ 1:(n - 1)) + | ||
| (exp(0) - exp(x[n])) / (0 - x[n]) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| return model | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.