Skip to content

Commit

Permalink
Support TIME_LIMIT in is_solved_and_feasible
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Jan 28, 2025
1 parent 6e4427a commit 89a8073
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
35 changes: 27 additions & 8 deletions src/optimizer_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -813,24 +813,42 @@ end
)
Return `true` if the model has a feasible primal solution associated with result
index `result` and the [`termination_status`](@ref) is [`OPTIMAL`](@ref) (the
solver found a global optimum) or [`LOCALLY_SOLVED`](@ref) (the solver found a
local optimum, which may also be the global optimum, but the solver could not
prove so).
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
understand what solutions are available (if any).
## Keyword arguments
### `allow_local`
If `allow_local = false`, then this function returns `true` only if the
[`termination_status`](@ref) is [`OPTIMAL`](@ref).
### `allow_almost`
If `allow_almost = true`, then the [`termination_status`](@ref) may additionally
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).
If `dual`, additionally check that an optimal dual solution is available.
### `dual`
If this function returns `false`, use [`termination_status`](@ref),
[`result_count`](@ref), [`primal_status`](@ref) and [`dual_status`](@ref) to
understand what solutions are available (if any).
If `dual`, additionally check that an optimal dual solution is available via
[`dual_status`](@ref). The `allow_` keywords control both the primal and dual
solutions.
### `result`
The index of the result to query. This value is passed to the `result` keyword
arguments of [`primal_status`](@ref) and [`dual_status`](@ref)
## Example
Expand All @@ -854,6 +872,7 @@ function is_solved_and_feasible(
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))
if ret
Expand Down
3 changes: 2 additions & 1 deletion test/test_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1254,9 +1254,10 @@ function test_is_solved_and_feasible()
MOI.ALMOST_OPTIMAL,
MOI.ALMOST_LOCALLY_SOLVED,
MOI.TIME_LIMIT,
MOI.OTHER_ERROR,
]
_global = term == MOI.OPTIMAL
has_local = _global || (term == MOI.LOCALLY_SOLVED)
has_local = _global || (term in (MOI.LOCALLY_SOLVED, MOI.TIME_LIMIT))
_almost_global = _global || (term == MOI.ALMOST_OPTIMAL)
_almost_local =
has_local || _almost_global || (term == MOI.ALMOST_LOCALLY_SOLVED)
Expand Down

0 comments on commit 89a8073

Please sign in to comment.