-
Notifications
You must be signed in to change notification settings - Fork 48
Add problems 5-13 except 9,10 #375
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
Changes from 14 commits
7d950c5
0243327
68460ee
ccc6b20
a70e7f5
c893535
7c5f406
9c5c090
7163faa
1fc23d9
31e74f3
c2ce1ba
9661813
9e1d4f0
9c79bd9
1c169ec
56dc762
76f9e9b
fa11e18
82e2fe6
ce63619
aafedce
3526af4
7d06b5e
bccf9ff
11e9015
734a28e
f8a84f3
9ee9737
0a4bca7
a3cdf38
7fce265
930f079
8079928
e63ab1e
b4840da
e0b70d4
bbc687e
ccd1d04
fdd1503
9c57ccd
32afb3c
2af4718
f68e258
76c8462
1024b3e
945f075
a14f598
aad39a9
5139449
173a8e4
7257220
9a2f7eb
0bd40a8
405ffe7
275c7b6
09064a6
5d3e551
cce8815
9671fc9
2436b24
046ef5a
4629ee7
a4a1d3c
52b88a5
3ab4917
4ad0719
14b6acf
e6b5aea
9f159b2
8438c54
98f7cfc
99d9e8a
d5ae2c9
ef363fd
b301427
c695b37
9aab84b
db62cf5
1d89d83
3dec1df
59a36a0
7e2f98d
5996d0d
eff9b55
8492676
03cd941
ddfdca0
2f697ee
d9a82af
b987ab1
e2a953f
2078516
14759d0
e2b9dbd
dcc91dc
60f7615
9b82d82
09e1ac7
ed2fdd8
0f7a50e
c305223
c54dcca
49f682e
dc2916d
d1c06f9
4c5115f
ae0a0eb
ad66a20
0216f26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| export auglag | ||
|
|
||
| function auglag(; use_nls::Bool = false, kwargs...) | ||
| model = use_nls ? :nls : :nlp | ||
| return auglag(Val(model); kwargs...) | ||
| end | ||
|
|
||
| function auglag(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function F!(r, x; n = length(x)) | ||
| # simple residual for placeholder: r = x - 1 | ||
| for i in 1:n | ||
| r[i] = x[i] - one(T) | ||
|
arnavk23 marked this conversation as resolved.
Outdated
|
||
| end | ||
| return r | ||
| end | ||
| x0 = zeros(T, n) | ||
| return ADNLPModels.ADNLSModel!(F!, x0, n, name = "auglag-nls"; kwargs...) | ||
| end | ||
|
|
||
| function auglag(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x; n = length(x)) | ||
| # Placeholder augmented Lagrangian style objective | ||
|
arnavk23 marked this conversation as resolved.
Outdated
|
||
| return sum((x[i] - 1)^2 for i = 1:n) | ||
| end | ||
| x0 = zeros(T, n) | ||
| return ADNLPModels.ADNLPModel(f, x0, name = "auglag"; kwargs...) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| export browngen | ||
|
arnavk23 marked this conversation as resolved.
Outdated
|
||
| function browngen(; use_nls::Bool = false, kwargs...) | ||
| model = use_nls ? :nls : :nlp | ||
| return browngen(Val(model); kwargs...) | ||
| end | ||
|
|
||
| function browngen(::Val{:nlp}; n::Int = default_nvar, type::Type = Float64, kwargs...) | ||
| T = type | ||
|
arnavk23 marked this conversation as resolved.
Outdated
|
||
| function f(x; n = length(x)) | ||
| # Placeholder for generalized Brown function (precision-safe) | ||
|
arnavk23 marked this conversation as resolved.
Outdated
|
||
| s = zero(T) | ||
| for i in 1:n | ||
| t = x[i] - T(0.5) | ||
|
arnavk23 marked this conversation as resolved.
Outdated
|
||
| s += t * t | ||
| end | ||
| return s | ||
| end | ||
| x0 = ones(T, n) .* T(0.5) | ||
| return ADNLPModels.ADNLPModel(f, x0, name = "browngen"; kwargs...) | ||
| end | ||
|
|
||
| function browngen(::Val{:nls}; n::Int = default_nvar, type::Type = Float64, kwargs...) | ||
| T = type | ||
| h = T(0.5) | ||
| function F!(r, x) | ||
| @inbounds begin | ||
| rr = r | ||
| xx = x | ||
| for i in 1:n | ||
| rr[i] = xx[i] - h | ||
| end | ||
| end | ||
| return r | ||
| end | ||
| x0 = ones(T, n) .* T(0.5) | ||
| return ADNLPModels.ADNLSModel!(F!, x0, n, name = "browngen-nls"; kwargs...) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| export broyden7d | ||
|
|
||
| function broyden7d(; use_nls::Bool = false, kwargs...) | ||
| model = use_nls ? :nls : :nlp | ||
| return broyden7d(Val(model); kwargs...) | ||
| end | ||
|
|
||
| function broyden7d(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x; n = length(x)) | ||
|
arnavk23 marked this conversation as resolved.
Outdated
|
||
| s = zero(T) | ||
| @inbounds for i = 1:n | ||
| s += x[i]^2 | ||
| end | ||
| return T(0.5) * s | ||
| end | ||
| x0 = -ones(T, n) | ||
| return ADNLPModels.ADNLPModel(f, x0, name = "broyden7d"; kwargs...) | ||
| end | ||
|
|
||
| function broyden7d(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| # Provide an in-place residual F! for least-squares-style testing. | ||
| function F!(r, x; n = length(x)) | ||
| @inbounds for i = 1:n | ||
| r[i] = x[i] | ||
| end | ||
| return r | ||
| end | ||
| x0 = -ones(T, n) | ||
| return ADNLPModels.ADNLSModel!(F!, x0, n, name = "broyden7d-nls"; kwargs...) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| export chainwoo | ||
|
|
||
| function chainwoo(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function chainwoo(; use_nls::Bool = false, kwargs...) | ||
| model = use_nls ? :nls : :nlp | ||
| return chainwoo(Val(model); kwargs...) | ||
| end | ||
|
|
||
| function chainwoo(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| (n % 4 == 0) || @warn("chainwoo: number of variables adjusted to be a multiple of 4") | ||
| n = 4 * max(1, div(n, 4)) | ||
| function f(x; n = length(x)) | ||
|
|
@@ -16,3 +21,22 @@ function chainwoo(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) w | |
| x0 = vcat([-3, -1, -3, -1], -2 * ones(T, n - 4)) | ||
| return ADNLPModels.ADNLPModel(f, x0, name = "chainwoo"; kwargs...) | ||
| end | ||
|
|
||
| function chainwoo(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| (n % 4 == 0) || @warn("chainwoo: number of variables adjusted to be a multiple of 4") | ||
| n = 4 * max(1, div(n, 4)) | ||
| function F!(r, x; n = length(x)) | ||
|
arnavk23 marked this conversation as resolved.
|
||
| # construct typical residuals corresponding to each pair block | ||
| for i = 1:(div(n, 2) - 1) | ||
|
arnavk23 marked this conversation as resolved.
Outdated
|
||
| idx = 2 * i - 1 | ||
| r[idx] = 1 - x[idx] | ||
| r[idx + 1] = x[idx + 1] - x[idx]^2 | ||
| # second pair | ||
| r[idx + 2] = 1 - x[idx + 2] | ||
| r[idx + 3] = x[idx + 3] - x[idx + 2]^2 | ||
| end | ||
| return r | ||
| end | ||
|
Comment on lines
+28
to
+42
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just doesn't make sense at all. Do you want me to explain you further the link between F and f ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please explain
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. f(x) = sum(F(x)[i].^2) so we should see all the terms that are squared in the function F(x) for the NLS-variant, like you did for the others |
||
| x0 = vcat([-3, -1, -3, -1], -2 * ones(T, n - 4)) | ||
| return ADNLPModels.ADNLSModel!(F!, x0, n, name = "chainwoo-nls"; kwargs...) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| export genbroyden | ||
|
arnavk23 marked this conversation as resolved.
Outdated
|
||
|
|
||
| """ | ||
| Generalized Broyden tridiagonal problem (variable dimension). | ||
|
|
||
| This implementation follows the style of `broyden3d` but exposes a | ||
| parameter `alpha` to generalize the diagonal nonlinearity. It's provided | ||
| as both an ADNLPModel (objective) and an ADNLSModel (residual form). | ||
| """ | ||
| function genbroyden(; use_nls::Bool = false, kwargs...) | ||
| model = use_nls ? :nls : :nlp | ||
| return genbroyden(Val(model); kwargs...) | ||
| end | ||
|
|
||
| function genbroyden(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, alpha::Real = 2.0, kwargs...) where {T} | ||
| a = T(alpha) | ||
| function f(x; n = length(x)) | ||
| # Generalized form similar to Broyden tridiagonal: r_i = (3 - a*x_i)*x_i - x_{i-1} - 2*x_{i+1} + 1 | ||
| # Objective is 1/2 * sum r_i^2 | ||
| return T(0.5) * ( | ||
| ((3 - a * x[1]) * x[1] - 2 * x[2] + 1)^2 + | ||
| sum(((3 - a * x[i]) * x[i] - x[i - 1] - 2 * x[i + 1] + 1)^2 for i = 2:(n - 1)) + | ||
| ((3 - a * x[n]) * x[n] - x[n - 1] + 1)^2 | ||
| ) | ||
| end | ||
| x0 = -ones(T, n) | ||
| return ADNLPModels.ADNLPModel(f, x0, name = "genbroyden"; kwargs...) | ||
| end | ||
|
|
||
| function genbroyden(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, alpha::Real = 2.0, kwargs...) where {T} | ||
| a = T(alpha) | ||
| function F!(r, x; n = length(x)) | ||
| r[1] = (3 - a * x[1]) * x[1] - 2 * x[2] + 1 | ||
| r[n] = (3 - a * x[n]) * x[n] - x[n - 1] + 1 | ||
| for i = 2:(n - 1) | ||
| r[i] = (3 - a * 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 = "genbroyden-nls"; kwargs...) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| export genbroydenb | ||
|
|
||
| function genbroydenb(; use_nls::Bool = false, kwargs...) | ||
|
arnavk23 marked this conversation as resolved.
|
||
| model = use_nls ? :nls : :nlp | ||
| return genbroydenb(Val(model); kwargs...) | ||
| end | ||
|
|
||
| function genbroydenb(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, ml::Int = 5, mu::Int = 1, beta::Real = 5.0, kwargs...) where {T} | ||
| b = T(beta) | ||
| function f(x; n = length(x)) | ||
| s = zero(T) | ||
| for i = 1:n | ||
| diag = x[i] * (T(2) + b * x[i]^2) + one(T) | ||
| neigh = zero(T) | ||
| for j = max(1, i - ml):min(n, i + mu) | ||
| if j != i | ||
| neigh += x[j] * (one(T) + x[j]) | ||
|
arnavk23 marked this conversation as resolved.
Outdated
|
||
| end | ||
| end | ||
| s += (diag - neigh)^2 | ||
| end | ||
| return T(0.5) * s | ||
| end | ||
| x0 = -ones(T, n) | ||
| return ADNLPModels.ADNLPModel(f, x0, name = "genbroydenb"; kwargs...) | ||
| end | ||
|
|
||
| function genbroydenb(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, ml::Int = 5, mu::Int = 1, beta::Real = 5.0, kwargs...) where {T} | ||
| b = T(beta) | ||
| function F!(r, x; n = length(x)) | ||
| for i = 1:n | ||
| diag = x[i] * (T(2) + b * x[i]^2) + one(T) | ||
| neigh = zero(T) | ||
| for j = max(1, i - ml):min(n, i + mu) | ||
| if j != i | ||
| neigh += x[j] * (one(T) + x[j]) | ||
|
arnavk23 marked this conversation as resolved.
Outdated
|
||
| end | ||
| end | ||
| r[i] = diag - neigh | ||
| end | ||
| return r | ||
| end | ||
| x0 = -ones(T, n) | ||
| return ADNLPModels.ADNLSModel!(F!, x0, n, name = "genbroydenb-nls"; kwargs...) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| export nazareth | ||
|
|
||
| function nazareth(; use_nls::Bool = false, kwargs...) | ||
| model = use_nls ? :nls : :nlp | ||
| return nazareth(Val(model); kwargs...) | ||
| end | ||
|
|
||
| function nazareth(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x; n = length(x)) | ||
| s = zero(T) | ||
| @inbounds for i = 1:n | ||
| t = sin(x[i]) - T(0.1) | ||
| s += t * t | ||
| end | ||
| return s | ||
| end | ||
| x0 = zeros(T, n) | ||
| return ADNLPModels.ADNLPModel(f, x0, name = "nazareth", minimize = true; kwargs...) | ||
| end | ||
|
|
||
| function nazareth(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function F!(r, x; n = length(x)) | ||
| @inbounds for i = 1:n | ||
| r[i] = sin(x[i]) - T(0.1) | ||
| end | ||
|
arnavk23 marked this conversation as resolved.
|
||
| return r | ||
| end | ||
| x0 = zeros(T, n) | ||
| return ADNLPModels.ADNLSModel!(F!, x0, n, name = "nazareth"; kwargs...) | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| export toint | ||
|
|
||
| function toint(; n::Int = default_nvar, kwargs...) | ||
| return toint(Val(:nlp); n = n, kwargs...) | ||
| end | ||
|
|
||
| function toint(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x; n = length(x)) | ||
| return sum((cos(x[i]) - x[i]^2)^2 for i ∈ 1:n) | ||
| end | ||
| x0 = zeros(T, n) | ||
| return ADNLPModels.ADNLPModel(f, x0, name = "toint", minimize = true, kwargs...) | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export trig | ||
|
|
||
| function trig(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x; n = length(x)) | ||
| return sum((sin(x[i]) + 0.5 * x[i])^2 for i = 1:n) | ||
| end | ||
| x0 = zeros(T, n) | ||
| return ADNLPModels.ADNLPModel(f, x0, name = "trig"; kwargs...) | ||
| end |
Uh oh!
There was an error while loading. Please reload this page.