-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The keyword option `use_only_objgrad` is also included models without individual `obj` functions.
- Loading branch information
1 parent
c09754a
commit 75f36c7
Showing
3 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,37 @@ | ||
@testset "objgrad on tron" begin | ||
struct MyProblem <: AbstractNLPModel | ||
meta :: NLPModelMeta | ||
counters :: Counters | ||
end | ||
|
||
function MyProblem() | ||
meta = NLPModelMeta( | ||
2, # nvar | ||
x0 = [0.1; 0.1], | ||
lvar=zeros(2), | ||
uvar=ones(2) | ||
) | ||
MyProblem(meta, Counters()) | ||
end | ||
|
||
function NLPModels.objgrad!(:: MyProblem, x :: AbstractVector, g:: AbstractVector) | ||
f = (x[1] - 1)^2 + 100 * (x[2] - x[1]^2)^2 | ||
g[1] = 2 * (x[1] - 1) - 400 * x[1] * (x[2] - x[1]^2) | ||
g[2] = 200 * (x[2] - x[1]^2) | ||
f, g | ||
end | ||
|
||
function NLPModels.hprod!(:: MyProblem, x :: AbstractVector, v :: AbstractVector, Hv :: AbstractVector; obj_weight=1.0) | ||
Hv[1] = obj_weight * (2 - 400 * (x[2] - x[1]^2) + 800 * x[1]^2) * v[1] - 400obj_weight * x[1] * v[2] | ||
Hv[2] = 200obj_weight * v[2] - 400obj_weight * x[1] * v[1] | ||
Hv | ||
end | ||
|
||
nlp = MyProblem() | ||
output = tron(nlp, use_only_objgrad=true) | ||
@test isapprox(output.solution, ones(2), rtol=1e-4) | ||
@test output.dual_feas < 1e-4 | ||
@test output.objective< 1e-4 | ||
|
||
@test_throws MethodError tron(nlp, use_only_objgrad=false) | ||
end |
This file contains 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 |
---|---|---|
|
@@ -23,3 +23,5 @@ for solver in [trunk] | |
solver(nlp, max_eval=20) | ||
reset!(nlp) | ||
end | ||
|
||
include("objgrad-on-tron.jl") |