mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Add with_lhs argument
This commit is contained in:
@@ -166,8 +166,10 @@ class FeaturesExtractor:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
with_sa: bool = True,
|
with_sa: bool = True,
|
||||||
|
with_lhs: bool = True,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.with_sa = with_sa
|
self.with_sa = with_sa
|
||||||
|
self.with_lhs = with_lhs
|
||||||
|
|
||||||
def extract(
|
def extract(
|
||||||
self,
|
self,
|
||||||
@@ -183,6 +185,7 @@ class FeaturesExtractor:
|
|||||||
features.constraints = solver.get_constraints(
|
features.constraints = solver.get_constraints(
|
||||||
with_static=with_static,
|
with_static=with_static,
|
||||||
with_sa=self.with_sa,
|
with_sa=self.with_sa,
|
||||||
|
with_lhs=self.with_lhs,
|
||||||
)
|
)
|
||||||
features.constraints_old = solver.get_constraints_old(
|
features.constraints_old = solver.get_constraints_old(
|
||||||
with_static=with_static,
|
with_static=with_static,
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ class GurobiSolver(InternalSolver):
|
|||||||
self,
|
self,
|
||||||
with_static: bool = True,
|
with_static: bool = True,
|
||||||
with_sa: bool = True,
|
with_sa: bool = True,
|
||||||
|
with_lhs: bool = True,
|
||||||
) -> ConstraintFeatures:
|
) -> ConstraintFeatures:
|
||||||
model = self.model
|
model = self.model
|
||||||
assert model is not None
|
assert model is not None
|
||||||
@@ -187,6 +188,7 @@ class GurobiSolver(InternalSolver):
|
|||||||
if with_static:
|
if with_static:
|
||||||
rhs = tuple(model.getAttr("rhs", gp_constrs))
|
rhs = tuple(model.getAttr("rhs", gp_constrs))
|
||||||
senses = tuple(model.getAttr("sense", gp_constrs))
|
senses = tuple(model.getAttr("sense", gp_constrs))
|
||||||
|
if with_lhs:
|
||||||
lhs_l: List = [None for _ in gp_constrs]
|
lhs_l: List = [None for _ in gp_constrs]
|
||||||
for (i, gp_constr) in enumerate(gp_constrs):
|
for (i, gp_constr) in enumerate(gp_constrs):
|
||||||
expr = model.getRow(gp_constr)
|
expr = model.getRow(gp_constr)
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ class InternalSolver(ABC, EnforceOverrides):
|
|||||||
self,
|
self,
|
||||||
with_static: bool = True,
|
with_static: bool = True,
|
||||||
with_sa: bool = True,
|
with_sa: bool = True,
|
||||||
|
with_lhs: bool = True,
|
||||||
) -> ConstraintFeatures:
|
) -> ConstraintFeatures:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ class BasePyomoSolver(InternalSolver):
|
|||||||
self,
|
self,
|
||||||
with_static: bool = True,
|
with_static: bool = True,
|
||||||
with_sa: bool = True,
|
with_sa: bool = True,
|
||||||
|
with_lhs: bool = True,
|
||||||
) -> ConstraintFeatures:
|
) -> ConstraintFeatures:
|
||||||
model = self.model
|
model = self.model
|
||||||
assert model is not None
|
assert model is not None
|
||||||
@@ -162,13 +163,19 @@ class BasePyomoSolver(InternalSolver):
|
|||||||
senses.append("=")
|
senses.append("=")
|
||||||
rhs.append(float(c.upper()))
|
rhs.append(float(c.upper()))
|
||||||
|
|
||||||
|
if with_lhs:
|
||||||
# Extract LHS
|
# Extract LHS
|
||||||
lhsc = []
|
lhsc = []
|
||||||
expr = c.body
|
expr = c.body
|
||||||
if isinstance(expr, SumExpression):
|
if isinstance(expr, SumExpression):
|
||||||
for term in expr._args_:
|
for term in expr._args_:
|
||||||
if isinstance(term, MonomialTermExpression):
|
if isinstance(term, MonomialTermExpression):
|
||||||
lhsc.append((term._args_[1].name, float(term._args_[0])))
|
lhsc.append(
|
||||||
|
(
|
||||||
|
term._args_[1].name,
|
||||||
|
float(term._args_[0]),
|
||||||
|
)
|
||||||
|
)
|
||||||
elif isinstance(term, _GeneralVarData):
|
elif isinstance(term, _GeneralVarData):
|
||||||
lhsc.append((term.name, 1.0))
|
lhsc.append((term.name, 1.0))
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user