mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-10 11:28:51 -06:00
Make cuts component compatible with Pyomo+Gurobi
This commit is contained in:
@@ -16,6 +16,8 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _gurobi_callback(model: AbstractModel, gp_model: gp.Model, where: int) -> None:
|
||||
assert isinstance(gp_model, gp.Model)
|
||||
|
||||
# Lazy constraints
|
||||
if model.lazy_separate is not None:
|
||||
assert model.lazy_enforce is not None
|
||||
@@ -58,6 +60,16 @@ def _gurobi_add_constr(gp_model: gp.Model, where: str, constr: Any) -> None:
|
||||
gp_model.addConstr(constr)
|
||||
|
||||
|
||||
def _gurobi_set_required_params(model: AbstractModel, gp_model: gp.Model) -> None:
|
||||
# Required parameters for lazy constraints
|
||||
if model.lazy_enforce is not None:
|
||||
gp_model.setParam("PreCrush", 1)
|
||||
gp_model.setParam("LazyConstraints", 1)
|
||||
# Required parameters for user cuts
|
||||
if model.cuts_enforce is not None:
|
||||
gp_model.setParam("PreCrush", 1)
|
||||
|
||||
|
||||
class GurobiModel(AbstractModel):
|
||||
_supports_basis_status = True
|
||||
_supports_sensitivity_analysis = True
|
||||
@@ -188,14 +200,7 @@ class GurobiModel(AbstractModel):
|
||||
def callback(_: gp.Model, where: int) -> None:
|
||||
_gurobi_callback(self, self.inner, where)
|
||||
|
||||
# Required parameters for lazy constraints
|
||||
if self.lazy_enforce is not None:
|
||||
self.inner.setParam("PreCrush", 1)
|
||||
self.inner.setParam("LazyConstraints", 1)
|
||||
|
||||
# Required parameters for user cuts
|
||||
if self.cuts_enforce is not None:
|
||||
self.inner.setParam("PreCrush", 1)
|
||||
_gurobi_set_required_params(self, self.inner)
|
||||
|
||||
if self.lazy_enforce is not None or self.cuts_enforce is not None:
|
||||
self.inner.optimize(callback)
|
||||
|
||||
Reference in New Issue
Block a user