From bd1d2117c52b80bf54c1820ef1423c2dee5aa562 Mon Sep 17 00:00:00 2001 From: Alinson S Xavier Date: Mon, 24 Feb 2020 10:01:56 -0600 Subject: [PATCH] Update benchmark scripts --- benchmark/Makefile | 2 +- benchmark/benchmark.py | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/benchmark/Makefile b/benchmark/Makefile index ced75b5..eb4e224 100644 --- a/benchmark/Makefile +++ b/benchmark/Makefile @@ -12,7 +12,7 @@ main: $(addsuffix /performance.png, $(CHALLENGES)) %/train_instances.bin: python benchmark.py train $* -%/benchmark_baseline.csv: %/training_data.bin +%/benchmark_baseline.csv: %/train_instances.bin python benchmark.py test-baseline $* %/benchmark_ml.csv: %/benchmark_baseline.csv diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py index 8aa3387..f573b89 100755 --- a/benchmark/benchmark.py +++ b/benchmark/benchmark.py @@ -16,11 +16,7 @@ Options: """ from docopt import docopt import importlib, pathlib -from miplearn import (LearningSolver, - BenchmarkRunner, - WarmStartComponent, - BranchPriorityComponent, - ) +from miplearn import (LearningSolver, BenchmarkRunner) from numpy import median import pyomo.environ as pe import pickle @@ -29,7 +25,7 @@ import logging logging.getLogger('pyomo.core').setLevel(logging.ERROR) n_jobs = 10 -time_limit = 300 +time_limit = 900 internal_solver = "gurobi" args = docopt(__doc__) @@ -65,35 +61,36 @@ def train(): def test_baseline(): + test_instances = load("%s/test_instances.bin" % basepath) solvers = { "baseline": LearningSolver( time_limit=time_limit, components={}, ), } - test_instances = load("%s/test_instances.bin" % basepath) benchmark = BenchmarkRunner(solvers) benchmark.parallel_solve(test_instances, n_jobs=n_jobs) benchmark.save_results("%s/benchmark_baseline.csv" % basepath) def test_ml(): + train_instances = load("%s/train_instances.bin" % basepath) + test_instances = load("%s/test_instances.bin" % basepath) solvers = { "ml-exact": LearningSolver( - time_limit=time_limit, + time_limit=time_limit, ), "ml-heuristic": LearningSolver( time_limit=time_limit, mode="heuristic", ), } - test_instances = load("%s/test_instances.bin" % basepath) benchmark = BenchmarkRunner(solvers) - benchmark.load_state("%s/training_data.bin" % basepath) benchmark.load_results("%s/benchmark_baseline.csv" % basepath) + benchmark.fit(train_instances) benchmark.parallel_solve(test_instances, n_jobs=n_jobs) benchmark.save_results("%s/benchmark_ml.csv" % basepath) - + def charts(): import matplotlib.pyplot as plt @@ -155,9 +152,9 @@ def charts(): if __name__ == "__main__": if args["train"]: train() - #if args["test-baseline"]: - # test_baseline() - #if args["test-ml"]: - # test_ml() - #if args["charts"]: - # charts() + if args["test-baseline"]: + test_baseline() + if args["test-ml"]: + test_ml() + if args["charts"]: + charts()