Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions src/stats.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export AbstractExecutionStats,
GenericExecutionStats,
set_status!,
get_status,
set_solution!,
set_objective!,
set_residuals!,
Expand Down Expand Up @@ -454,11 +455,12 @@ The keyword arguments may contain:
- `elapsed_time::Float64 = 0.0`: current elapsed time (default: `0.0`);
- `iter::Integer = 0`: current number of iterations (default: `0`);
- `optimal::Bool = false`: `true` if the problem reached an optimal solution (default: `false`);
- `small_residual::Bool = false`: `true` if the nonlinear least squares problem reached a solution with small residual (default: `false`);
- `infeasible::Bool = false`: `true` if the problem is infeasible (default: `false`);
- `parameter_too_large::Bool = false`: `true` if the parameters are loo large (default: `false`);
- `unbounded::Bool = false`: `true` if the problem is unbounded (default: `false`);
- `stalled::Bool = false`: `true` if the algorithm is stalling (default: `false`);
- `max_eval::Integer`: limit on the number of evaluations of objective and constraints (default: `typemax(Int)`);
- `max_eval::Integer`: limit on the number of evaluations defined by `eval_fun` (default: `typemax(Int)`);
- `max_time::Float64 = Inf`: limit on the time (default: `Inf`);
- `max_iter::Integer`: limit on the number of iterations (default: `typemax(Int)`).
"""
Expand All @@ -467,16 +469,20 @@ function get_status(
elapsed_time::Float64 = 0.0,
iter::Integer = 0,
optimal::Bool = false,
small_residual::Bool = false,
infeasible::Bool = false,
parameter_too_large::Bool = false,
unbounded::Bool = false,
stalled::Bool = false,
exception::Bool = false,
max_eval::Integer = typemax(Int),
max_time::Float64 = Inf,
max_iter::Integer = typemax(Int),
)
if optimal
:first_order
elseif small_residual
:small_residual
elseif infeasible
:infeasible
elseif unbounded
Expand All @@ -485,13 +491,17 @@ function get_status(
:stalled
elseif iter > max_iter
:max_iter
elseif neval_obj(nlp) + neval_cons(nlp) > max_eval ≥ 0
elseif eval_fun(nlp) > max_eval ≥ 0
:max_eval
elseif elapsed_time > max_time
:max_time
elseif parameter_too_large
:stalled
elseif exception
:exception
else
:unknown
end
end

eval_fun(nlp::AbstractNLPModel) = neval_obj(nlp) + neval_cons(nlp)
18 changes: 18 additions & 0 deletions test/test_stats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,21 @@ function test_stats()
end

test_stats()

@testset "Test get_status" begin
nlp = ADNLPModel(x -> sum(x), ones(2))
@test get_status(nlp, optimal = true) == :first_order
@test get_status(nlp, small_residual = true) == :small_residual
@test get_status(nlp, infeasible = true) == :infeasible
@test get_status(nlp, unbounded = true) == :unbounded
@test get_status(nlp, stalled = true) == :stalled
@test get_status(nlp, iter = 8, max_iter = 5) == :max_iter
for i=1:2
increment!(nlp, :neval_obj)
end
@test get_status(nlp, max_eval = 1) == :max_eval
@test get_status(nlp, elapsed_time = 60.0, max_time = 1.0) == :max_time
@test get_status(nlp, parameter_too_large = true) == :stalled
@test get_status(nlp, exception = true) == :exception
@test get_status(nlp) == :unknown
end