mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
ConvertTight: Detect and fix sub-optimality
This commit is contained in:
@@ -162,6 +162,12 @@ class GurobiSolver(InternalSolver):
|
||||
"Warm start value": self._extract_warm_start_value(log),
|
||||
}
|
||||
|
||||
def get_sense(self):
|
||||
if self.model.modelSense == 1:
|
||||
return "min"
|
||||
else:
|
||||
return "max"
|
||||
|
||||
def get_solution(self):
|
||||
self._raise_if_callback()
|
||||
|
||||
@@ -179,9 +185,12 @@ class GurobiSolver(InternalSolver):
|
||||
def is_infeasible(self):
|
||||
return self.model.status in [self.GRB.INFEASIBLE, self.GRB.INF_OR_UNBD]
|
||||
|
||||
def get_farkas_dual(self, cid):
|
||||
def get_dual(self, cid):
|
||||
c = self.model.getConstrByName(cid)
|
||||
return c.farkasDual
|
||||
if self.is_infeasible():
|
||||
return c.farkasDual
|
||||
else:
|
||||
return c.pi
|
||||
|
||||
def _get_value(self, var):
|
||||
if self.cb_where == self.GRB.Callback.MIPSOL:
|
||||
|
||||
@@ -200,11 +200,20 @@ class InternalSolver(ABC):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_farkas_dual(self, cid):
|
||||
def get_dual(self, cid):
|
||||
"""
|
||||
If the model is infeasible, returns a portion of the infeasibility certificate
|
||||
corresponding to the given constraint. If the model is feasible, calling this
|
||||
function raises an error.
|
||||
If the model is feasible and has been solved to optimality, returns the optimal
|
||||
value of the dual variable associated with this constraint. If the model is infeasible,
|
||||
returns a portion of the infeasibility certificate corresponding to the given constraint.
|
||||
|
||||
Solve must be called prior to this method.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_sense(self):
|
||||
"""
|
||||
Returns the sense of the problem (either "min" or "max").
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@@ -267,5 +267,8 @@ class BasePyomoSolver(InternalSolver):
|
||||
def is_infeasible(self):
|
||||
raise Exception("Not implemented")
|
||||
|
||||
def get_farkas_dual(self, cid):
|
||||
def get_dual(self, cid):
|
||||
raise Exception("Not implemented")
|
||||
|
||||
def get_sense(self):
|
||||
raise Exception("Not implemented")
|
||||
Reference in New Issue
Block a user