Skip to content

Commit 5e5c9ed

Browse files
committed
fix: only gather solution/obj.val. if OPTIMAL | FEASIBLE
This is assert in test test_maximize_single_continuous_or_integer_variable_with_default_bounds, with an unbounded problem.
1 parent f36001c commit 5e5c9ed

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

mip/highs.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,11 @@ def optimize(
372372
status = self._lib.Highs_run(self._model)
373373

374374
# store solution values for later access
375-
if self._has_primal_solution():
375+
opt_status = self.get_status()
376+
if opt_status in (
377+
mip.OptimizationStatus.OPTIMAL,
378+
mip.OptimizationStatus.FEASIBLE,
379+
):
376380
# TODO: also handle primal/dual rays?
377381
n, m = self.num_cols(), self.num_rows()
378382
col_value = ffi.new("double[]", n)
@@ -388,10 +392,12 @@ def optimize(
388392
if self._has_dual_solution():
389393
self._pi = [row_dual[i] for i in range(m)]
390394

391-
return self.get_status()
395+
return opt_status
392396

393397
def get_objective_value(self: "SolverHighs") -> numbers.Real:
394-
return self._lib.Highs_getObjectiveValue(self._model)
398+
# only give value if we have stored a solution
399+
if self._x:
400+
return self._lib.Highs_getObjectiveValue(self._model)
395401

396402
def get_log(
397403
self: "SolverHighs",

0 commit comments

Comments
 (0)