From 601bfa261ae882e48cacca2af4fb7de3d2b0a8d1 Mon Sep 17 00:00:00 2001 From: Gregor Hendel Date: Fri, 15 Jan 2021 08:24:02 +0100 Subject: [PATCH] make gap computation robust against missing upper/lower bounds --- miplearn/benchmark.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/miplearn/benchmark.py b/miplearn/benchmark.py index 3048750..5984624 100644 --- a/miplearn/benchmark.py +++ b/miplearn/benchmark.py @@ -74,6 +74,14 @@ class BenchmarkRunner: for (solver_name, solver) in self.solvers.items(): 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): if self.results is None: self.results = pd.DataFrame( @@ -93,7 +101,8 @@ class BenchmarkRunner: ) lb = result["Lower bound"] ub = result["Upper bound"] - gap = (ub - lb) / lb + gap = self.computeGap(ub, lb) + if "Predicted LB" not in result: result["Predicted LB"] = float("nan") result["Predicted UB"] = float("nan")