jump-dev / HiGHS.jl

A Julia interface to the HiGHS solver
https://highs.dev
MIT License
103 stars 14 forks source link

_OPTIMIZE_WARNED status? #105

Closed grahamgill closed 2 years ago

grahamgill commented 2 years ago

I find it a bit heavy that model.solution.status is set to _OPTIMIZE_ERRORED for any nonzero return value of Highs_run, at https://github.com/jump-dev/HiGHS.jl/blob/8e39503c2f75ca66446e4559ba3f920f4165dafa/src/MOI_wrapper.jl#L1556. Highs_run return value of 1 indicates a warning, -1 indicates an error.

Locally I've made the change below, adding an _OPTIMIZE_WARNED status to the _OptimizeStatus enum. In the case of a Highs_run warning, this lets me see more easily the MOI.TerminationStatus and MOI.RawStatusString, and act on the result. In my use case, I'm frequently encountering an optimal solution but with a warning. I'd like to know there's a warning and see the solver result rather than have it be shunted into MOI.OTHER_ERROR.

diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl
index e485382..4aff9d3 100644
--- a/src/MOI_wrapper.jl
+++ b/src/MOI_wrapper.jl
@@ -162,7 +162,7 @@ function _set(c::_ConstraintInfo)
     end
 end

-@enum(_OptimizeStatus, _OPTIMIZE_NOT_CALLED, _OPTIMIZE_OK, _OPTIMIZE_ERRORED)
+@enum(_OptimizeStatus, _OPTIMIZE_NOT_CALLED, _OPTIMIZE_OK, _OPTIMIZE_ERRORED, _OPTIMIZE_WARNED)

 """
     _Solution
@@ -1553,7 +1553,7 @@ Get the solution from a run of HiGHS.
 """
 function _store_solution(model::Optimizer, ret::HighsInt)
     x = model.solution
-    x.status = ret == 0 ? _OPTIMIZE_OK : _OPTIMIZE_ERRORED
+    x.status = ret == kHighsStatusOk ? _OPTIMIZE_OK : ret == kHighsStatusWarning ? _OPTIMIZE_WARNED : _OPTIMIZE_ERRORED
     x.primal_solution_status = kHighsSolutionStatusNone
     x.dual_solution_status = kHighsSolutionStatusNone
     x.has_dual_ray = false