Skip to content

Commit ef0805e

Browse files
authored
Merge pull request #3 from Doing-The-Math/bz-constraint-idx
Return -1 if constraint not found
2 parents 3fb7268 + 754c774 commit ef0805e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

mip/highs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,11 @@ def remove_constrs(self: "SolverHighs", constrsList: List[int]):
13371337

13381338
def constr_get_index(self: "SolverHighs", name: str) -> int:
13391339
idx = ffi.new("int *")
1340-
self._lib.Highs_getRowByName(self._model, name.encode("utf-8"), idx)
1340+
status = self._lib.Highs_getRowByName(self._model, name.encode("utf-8"), idx)
1341+
if status == STATUS_ERROR:
1342+
# This means that no constraint with that name was found. Unfortunately,
1343+
# Highs: getRowByName doesn't assign a value to idx in that case.
1344+
return -1
13411345
return idx[0]
13421346

13431347
# Variable-related getters/setters

0 commit comments

Comments
 (0)