mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
Merge pull request #3 from GregorCH/dev-robust-gap
Make gap computation robust against missing upper/lower bounds
This commit is contained in:
@@ -74,6 +74,14 @@ class BenchmarkRunner:
|
|||||||
for (solver_name, solver) in self.solvers.items():
|
for (solver_name, solver) in self.solvers.items():
|
||||||
solver.fit(training_instances)
|
solver.fit(training_instances)
|
||||||
|
|
||||||
|
def computeGap(self, ub, lb):
|
||||||
|
# solver did not find a solution and/or bound, use maximum gap possible
|
||||||
|
if lb is None or ub is None or lb * ub < 0:
|
||||||
|
return 1.0
|
||||||
|
else:
|
||||||
|
# divide by max(abs(ub),abs(lb)) to ensure gap <= 1
|
||||||
|
return (ub - lb) / max(abs(ub), abs(lb))
|
||||||
|
|
||||||
def _push_result(self, result, solver, solver_name, instance):
|
def _push_result(self, result, solver, solver_name, instance):
|
||||||
if self.results is None:
|
if self.results is None:
|
||||||
self.results = pd.DataFrame(
|
self.results = pd.DataFrame(
|
||||||
@@ -93,7 +101,8 @@ class BenchmarkRunner:
|
|||||||
)
|
)
|
||||||
lb = result["Lower bound"]
|
lb = result["Lower bound"]
|
||||||
ub = result["Upper bound"]
|
ub = result["Upper bound"]
|
||||||
gap = (ub - lb) / lb
|
gap = self.computeGap(ub, lb)
|
||||||
|
|
||||||
if "Predicted LB" not in result:
|
if "Predicted LB" not in result:
|
||||||
result["Predicted LB"] = float("nan")
|
result["Predicted LB"] = float("nan")
|
||||||
result["Predicted UB"] = float("nan")
|
result["Predicted UB"] = float("nan")
|
||||||
|
|||||||
Reference in New Issue
Block a user