Skip to content

Commit 099bb88

Browse files
authored
Merge pull request #7 from Doing-The-Math/6-fix-failing-tests-query-variable-integrality
6 fix failing tests query variable integrality
2 parents b683804 + 77e973a commit 099bb88

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mip/highs.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@
678678
def check(status):
679679
if status == STATUS_ERROR:
680680
raise mip.InterfacingError("Unknown error in call to HiGHS.")
681+
return status
681682

682683

683684
class SolverHighs(mip.Solver):
@@ -1431,12 +1432,15 @@ def var_set_obj(self: "SolverHighs", var: "mip.Var", value: numbers.Real):
14311432
check(self._lib.Highs_changeColCost(self._model, var.idx, value))
14321433

14331434
def var_get_var_type(self: "SolverHighs", var: "mip.Var") -> str:
1435+
# Highs_getColIntegrality only works if some variable is not continuous.
1436+
# Since we want this method to always work, we need to catch this case first.
1437+
if self._num_int_vars == 0:
1438+
return mip.CONTINUOUS
1439+
14341440
var_type = ffi.new("int*")
1435-
ret = self._lib.Highs_getColIntegrality(self._model, var.idx, var_type)
1441+
check(self._lib.Highs_getColIntegrality(self._model, var.idx, var_type))
14361442
if var_type[0] not in self._highs_type_map:
1437-
raise ValueError(
1438-
f"Invalid variable type returned by HiGHS: {var_type[0]} (ret={ret})"
1439-
)
1443+
raise ValueError(f"Invalid variable type returned by HiGHS: {var_type[0]}.")
14401444
return self._highs_type_map[var_type[0]]
14411445

14421446
def var_set_var_type(self: "SolverHighs", var: "mip.Var", value: str):

0 commit comments

Comments
 (0)