Plot predicted objective value

This commit is contained in:
2020-02-26 15:45:02 -06:00
parent 32510d077d
commit 5eee00c626
8 changed files with 50 additions and 21 deletions

View File

@@ -64,6 +64,8 @@ class BenchmarkRunner:
"Nodes",
"Mode",
"Sense",
"Predicted LB",
"Predicted UB",
])
lb = result["Lower bound"]
ub = result["Upper bound"]
@@ -78,6 +80,8 @@ class BenchmarkRunner:
"Nodes": result["Nodes"],
"Mode": solver.mode,
"Sense": result["Sense"],
"Predicted LB": result["Predicted LB"],
"Predicted UB": result["Predicted UB"],
}, ignore_index=True)
groups = self.results.groupby("Instance")
best_lower_bound = groups["Lower Bound"].transform("max")

View File

@@ -15,7 +15,7 @@ class Component(ABC):
pass
@abstractmethod
def after_solve(self, solver, instance, model):
def after_solve(self, solver, instance, model, results):
pass
@abstractmethod

View File

@@ -38,7 +38,7 @@ class LazyConstraintsComponent(Component):
cut = instance.build_lazy_constraint(model, v)
solver.internal_solver.add_constraint(cut)
def after_solve(self, solver, instance, model):
def after_solve(self, solver, instance, model, results):
pass
def fit(self, training_instances):

View File

@@ -27,8 +27,13 @@ class ObjectiveValueComponent(Component):
instance.predicted_lb = lb
logger.info("Predicted objective: [%.2f, %.2f]" % (lb, ub))
def after_solve(self, solver, instance, model):
pass
def after_solve(self, solver, instance, model, results):
if self.ub_regressor is not None:
results["Predicted UB"] = instance.predicted_ub
results["Predicted LB"] = instance.predicted_lb
else:
results["Predicted UB"] = None
results["Predicted LB"] = None
def fit(self, training_instances):
logger.debug("Extracting features...")

View File

@@ -135,7 +135,7 @@ class PrimalSolutionComponent(Component):
else:
solver.internal_solver.set_warm_start(solution)
def after_solve(self, solver, instance, model):
def after_solve(self, solver, instance, model, results):
pass
def fit(self, training_instances):

View File

@@ -306,7 +306,7 @@ class LearningSolver:
logger.debug("Calling after_solve callbacks...")
for component in self.components.values():
component.after_solve(self, instance, model)
component.after_solve(self, instance, model, results)
# Store instance for future training
self.training_instances += [instance]

View File

@@ -27,11 +27,11 @@ def test_benchmark():
benchmark = BenchmarkRunner(test_solvers)
benchmark.fit(train_instances)
benchmark.parallel_solve(test_instances, n_jobs=2, n_trials=2)
assert benchmark.raw_results().values.shape == (12,13)
assert benchmark.raw_results().values.shape == (12,16)
benchmark.save_results("/tmp/benchmark.csv")
assert os.path.isfile("/tmp/benchmark.csv")
benchmark = BenchmarkRunner(test_solvers)
benchmark.load_results("/tmp/benchmark.csv")
assert benchmark.raw_results().values.shape == (12,13)
assert benchmark.raw_results().values.shape == (12,16)