def test_ml(): logger.info("Loading instances...") train_instances = load("%s/train_instances.bin" % basepath) test_instances = load("%s/test_instances.bin" % basepath) solvers = { "ml-exact": LearningSolver( time_limit=time_limit, solver=internal_solver, ), "ml-heuristic": LearningSolver( time_limit=time_limit, solver=internal_solver, mode="heuristic", ), } benchmark = BenchmarkRunner(solvers) logger.info("Loading results...") benchmark.load_results("%s/benchmark_baseline.csv" % basepath) logger.info("Fitting...") benchmark.fit(train_instances) logger.info("Solving...") benchmark.parallel_solve(test_instances, n_jobs=n_jobs) benchmark.save_results("%s/benchmark_ml.csv" % basepath)
def test_benchmark(): # Generate training and test instances train_instances = MaxWeightStableSetGenerator( n=randint(low=25, high=26)).generate(5) test_instances = MaxWeightStableSetGenerator( n=randint(low=25, high=26)).generate(3) # Training phase... training_solver = LearningSolver() training_solver.parallel_solve(train_instances, n_jobs=10) # Test phase... test_solvers = { "Strategy A": LearningSolver(), "Strategy B": LearningSolver(), } 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, 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, 16)
def test_baseline(): test_instances = load("%s/test_instances.bin" % basepath) solvers = { "baseline": LearningSolver( time_limit=test_time_limit, solver=internal_solver, ), } benchmark = BenchmarkRunner(solvers) benchmark.parallel_solve(test_instances, n_jobs=n_jobs) benchmark.save_results("%s/benchmark_baseline.csv" % basepath)