Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Jan 28, 2025
1 parent 89a8073 commit 4e03c2b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/optimizer_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ end
model::GenericModel;
allow_local::Bool = true,
allow_almost::Bool = false,
allow_time_limit::Bool = false,
dual::Bool = false,
result::Int = 1,
)
Expand All @@ -818,8 +819,6 @@ index `result` and the [`termination_status`](@ref) is one of the following:
* [`OPTIMAL`](@ref) (the solver found a global optimum)
* [`LOCALLY_SOLVED`](@ref) (the solver found a local optimum, which may also be
the global optimum, but the solver could not prove so)
* [`TIME_LIMIT`](@ref) (the solver stopped after a user-specified computation
time).
If this function returns `false`, use [`termination_status`](@ref),
[`result_count`](@ref), [`primal_status`](@ref) and [`dual_status`](@ref) to
Expand All @@ -839,6 +838,12 @@ be [`ALMOST_OPTIMAL`](@ref) or [`ALMOST_LOCALLY_SOLVED`](@ref) (if `allow_local`
and the [`primal_status`](@ref) and [`dual_status`](@ref) may additionally be
[`NEARLY_FEASIBLE_POINT`](@ref).
### `allow_time_limit`
If `allow_time_limit = true`, then the [`termination_status`](@ref) may
additionally be [`TIME_LIMIT`](@ref) (the solver stopped after a user-specified
computation time).
### `dual`
If `dual`, additionally check that an optimal dual solution is available via
Expand Down Expand Up @@ -866,15 +871,16 @@ function is_solved_and_feasible(
dual::Bool = false,
allow_local::Bool = true,
allow_almost::Bool = false,
allow_time_limit::Bool = false,
result::Int = 1,
)
status = termination_status(model)
ret =
(status == OPTIMAL) ||
(allow_local && (status == LOCALLY_SOLVED)) ||
(allow_local && (status == TIME_LIMIT)) ||
(allow_almost && (status == ALMOST_OPTIMAL)) ||
(allow_almost && allow_local && (status == ALMOST_LOCALLY_SOLVED))
(allow_almost && allow_local && (status == ALMOST_LOCALLY_SOLVED)) ||
(allow_time_limit && (status == TIME_LIMIT))
if ret
primal = primal_status(model; result)
ret &=
Expand Down
4 changes: 3 additions & 1 deletion test/test_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ function test_is_solved_and_feasible()
MOI.OTHER_ERROR,
]
_global = term == MOI.OPTIMAL
has_local = _global || (term in (MOI.LOCALLY_SOLVED, MOI.TIME_LIMIT))
has_local = _global || (term == MOI.LOCALLY_SOLVED)
_almost_global = _global || (term == MOI.ALMOST_OPTIMAL)
_almost_local =
has_local || _almost_global || (term == MOI.ALMOST_LOCALLY_SOLVED)
Expand All @@ -1273,6 +1273,8 @@ function test_is_solved_and_feasible()
MOI.set(mock, MOI.PrimalStatus(), primal)
MOI.set(mock, MOI.DualStatus(), dual)
@test is_solved_and_feasible(model) == (has_local && _primal)
@test is_solved_and_feasible(model; allow_time_limit = true) ==
(has_local && _primal) || (term == MOI.TIME_LIMIT)
@test is_solved_and_feasible(model; dual = true) ==
(has_local && _primal && _dual)
@test is_solved_and_feasible(model; allow_local = false) ==
Expand Down

0 comments on commit 4e03c2b

Please sign in to comment.