Skip to content

Commit 499b8ac

Browse files
h-g-sCopilot
andcommitted
cbc: fix isfile import and Cbc_reset before re-solve
Two fixes for newer CBC (cbcbox 2.901): 1. Add missing 'isfile' import from os.path in cbc.py (used in SolverCbc.read() but was not imported, causing NameError in mip_files_test). 2. Call Cbc_reset() before Cbc_solve() to clear stale solution state when re-solving the same model. Newer CBC's Cbc_solve() returns the old objective value without a reset. Cbc_reset() also resets the objective sense to MINIMIZE, so save and restore it around the call. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 62a0ee6 commit 499b8ac

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

mip/cbc.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
from typing import Dict, List, Tuple, Optional, Union
55
from sys import platform, maxsize
6-
from os.path import dirname
6+
from os.path import dirname, isfile
77
import os
88
import multiprocessing as multip
99
import numbers
@@ -1222,6 +1222,12 @@ def cbc_cut_callback(osi_solver, osi_cuts, app_data, depth, npass):
12221222
)
12231223

12241224
self.__clear_sol()
1225+
# Cbc_reset clears previous solve state (required in newer CBC to
1226+
# avoid stale results when re-solving), but also resets objective
1227+
# sense, so we save and restore it.
1228+
_sense = cbclib.Cbc_getObjSense(self._model)
1229+
Cbc_reset(self._model)
1230+
cbclib.Cbc_setObjSense(self._model, _sense)
12251231
cbclib.Cbc_solve(self._model)
12261232

12271233
if cbclib.Cbc_isAbandoned(self._model):

0 commit comments

Comments
 (0)