Skip to content

Commit 3a4bd7b

Browse files
committed
fix SolverHighs.set_objective
1 parent 1649c75 commit 3a4bd7b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

mip/highs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,18 @@ def set_start(self: "SolverHighs", start: List[Tuple["mip.Var", numbers.Real]]):
10351035
self._lib.Highs_setSolution(self._model, cval, ffi.NULL, ffi.NULL, ffi.NULL)
10361036

10371037
def set_objective(self: "SolverHighs", lin_expr: "mip.LinExpr", sense: str = ""):
1038+
# first reset old objective (all 0)
1039+
n = self.num_cols()
1040+
costs = ffi.new("double[]", n) # initialized to 0
1041+
check(
1042+
self._lib.Highs_changeColsCostByRange(
1043+
self._model,
1044+
0, # from_col
1045+
n - 1, # to_col
1046+
costs,
1047+
)
1048+
)
1049+
10381050
# set coefficients
10391051
for var, coef in lin_expr.expr.items():
10401052
check(self._lib.Highs_changeColCost(self._model, var.idx, coef))

0 commit comments

Comments
 (0)