コード例 #1
0
ファイル: test_benchmark.py プロジェクト: bknueven/MIPLearn
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)
コード例 #2
0
ファイル: benchmark.py プロジェクト: bknueven/MIPLearn
def train():
    problem_name, challenge_name = args["<challenge>"].split("/")
    pkg = importlib.import_module("miplearn.problems.%s" % problem_name)
    challenge = getattr(pkg, challenge_name)()
    train_instances = challenge.training_instances
    test_instances = challenge.test_instances
    solver = LearningSolver(time_limit=time_limit,
                            solver=internal_solver,
                            components={})
    solver.parallel_solve(train_instances, n_jobs=n_jobs)
    save(train_instances, "%s/train_instances.bin" % basepath)
    save(test_instances, "%s/test_instances.bin" % basepath)
コード例 #3
0
ファイル: test_solver.py プロジェクト: bknueven/MIPLearn
def test_parallel_solve():
    instances = [_get_instance() for _ in range(10)]
    solver = LearningSolver()
    results = solver.parallel_solve(instances, n_jobs=3)
    assert len(results) == 10
    for instance in instances:
        assert len(instance.solution["x"].keys()) == 4