Skip to content

Commit

Permalink
add no_start_opt_check + opt0 not a vector
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot committed Oct 27, 2020
1 parent 5734794 commit f8b23e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/Stopping/GenericStoppingmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,19 @@ end
"""
start!: update the Stopping and return a boolean true if we must stop.
`start!(:: AbstractStopping; kwargs...)`
`start!(:: AbstractStopping; no_start_opt_check :: Bool = false, kwargs...)`
Purpose is to know if there is a need to even perform an optimization algorithm
or if we are at an optimal solution from the beginning.
or if we are at an optimal solution from the beginning. Set *no\\_start\\_opt\\_check*
to *true* to avoid checking optimality.
The function *start!* successively calls: *\\_domain\\_check*, *\\_optimality\\_check*,
*\\_null\\_test*
Note: - *start!* initialize the start\\_time (if not done before) and *meta.optimality0*.
- Keywords argument are sent to the *\\_optimality\\_check!* call.
"""
function start!(stp :: AbstractStopping; kwargs...)
function start!(stp :: AbstractStopping; no_start_opt_check :: Bool = false, kwargs...)

stt_at_x = stp.current_state
x = stt_at_x.x
Expand All @@ -141,11 +142,11 @@ function start!(stp :: AbstractStopping; kwargs...)
end

stp.meta.domainerror = _domain_check(stp.current_state)
if !stp.meta.domainerror
if !stp.meta.domainerror && !no_start_opt_check
# Optimality check
optimality0 = _optimality_check(stp; kwargs...)
stp.meta.optimality0 = optimality0
if isnan(optimality0)
stp.meta.optimality0 = norm(optimality0, Inf)
if (true in isnan.(optimality0))
stp.meta.domainerror = true
end

Expand Down
8 changes: 4 additions & 4 deletions test/examples/run-optimsolver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ include("activeset.jl")

printstyled("Constrained optimization: active-set algorithm tutorial.\n", color = :green)
x0 = 1.5*ones(6);x0[6]=1.0
nlp_bnd = ADNLPModel(rosenbrock, x0,
lvar = fill(-10.0,size(x0)), uvar = fill(1.5,size(x0)))
nlp_bnd = ADNLPModel(rosenbrock, x0, fill(-10.0,size(x0)), fill(1.5,size(x0)))

nlp_bnd_at_x = NLPAtX(x0)
stop_nlp_c = NLPStopping(nlp_bnd, max_iter = 10)
Expand All @@ -141,9 +140,10 @@ include("penalty.jl")
printstyled("Constrained optimization: quadratic penalty tutorial.\n", color = :green)
x0 = 1.5*ones(6)
c(x) = [sum(x)]
# ADNLPModel(f, x0, lvar, uvar, c, lcon, ucon)
nlp2 = ADNLPModel(rosenbrock, x0,
lvar = fill(-10.0,size(x0)), uvar = fill(10.0,size(x0)),
y0 = [0.0], c = c, lcon = [-Inf], ucon = [5.])
fill(-10.0,size(x0)), fill(10.0,size(x0)),
c, [-Inf], [5.])

nlp_at_x_c = NLPAtX(x0, zeros(nlp2.meta.ncon))
stop_nlp_c = NLPStopping(nlp2, nlp_at_x_c, atol = 1e-3,
Expand Down

0 comments on commit f8b23e4

Please sign in to comment.