mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-10 11:28:51 -06:00
Lazy: Simplify method signature; switch to AbstractModel
This commit is contained in:
@@ -28,6 +28,7 @@ class GurobiModel(AbstractModel):
|
||||
self.lazy_enforce = lazy_enforce
|
||||
self.inner = inner
|
||||
self.lazy_constrs_: Optional[List[Any]] = None
|
||||
self.where = "default"
|
||||
|
||||
def add_constrs(
|
||||
self,
|
||||
@@ -53,6 +54,14 @@ class GurobiModel(AbstractModel):
|
||||
stats["Added constraints"] = 0
|
||||
stats["Added constraints"] += nconstrs
|
||||
|
||||
def add_constr(self, constr: Any) -> None:
|
||||
if self.where == "lazy":
|
||||
self.inner.cbLazy(constr)
|
||||
elif self.where == "cut":
|
||||
self.inner.cbCut(constr)
|
||||
else:
|
||||
self.inner.addConstr(constr)
|
||||
|
||||
def extract_after_load(self, h5: H5File) -> None:
|
||||
"""
|
||||
Given a model that has just been loaded, extracts static problem
|
||||
@@ -132,9 +141,11 @@ class GurobiModel(AbstractModel):
|
||||
assert self.lazy_constrs_ is not None
|
||||
assert self.lazy_enforce is not None
|
||||
if where == GRB.Callback.MIPSOL:
|
||||
self.where = "lazy"
|
||||
violations = self.lazy_separate(self)
|
||||
self.lazy_constrs_.extend(violations)
|
||||
self.lazy_enforce(self, violations, "cb")
|
||||
self.lazy_enforce(self, violations)
|
||||
self.where = "default"
|
||||
|
||||
if self.lazy_enforce is not None:
|
||||
self.inner.Params.lazyConstraints = 1
|
||||
|
||||
Reference in New Issue
Block a user