Ejemplo n.º 1
0
def test_opdyts():
    loop = Loop()

    evaluator = Evaluator(simulator=CongestionSimulator(),
                          problem=CongestionProblem(0.3, iterations=10))

    algorithm = Opdyts(evaluator,
                       candidate_set_size=16,
                       number_of_transitions=20,
                       perturbation_length=50,
                       seed=0)

    assert np.round(
        Loop(threshold=1e-3,
             maximum_cost=10000).run(evaluator=evaluator,
                                     algorithm=algorithm)) == 231
Ejemplo n.º 2
0
def test_random_walk_traffic():
    problem = TrafficProblem()

    evaluator = Evaluator(simulator=TrafficSimulator(), problem=problem)

    algorithm = RandomWalk(problem, seed=1000)

    assert Loop(threshold=10.0).run(evaluator=evaluator,
                                    algorithm=algorithm) == pytest.approx(
                                        (510.0, 412.0), 10.0)
Ejemplo n.º 3
0
def test_random_walk():
    evaluator = Evaluator(simulator=QuadraticSimulator(),
                          problem=QuadraticProblem([2.0, 1.0]))

    for seed in (1000, 2000, 3000, 4000):
        algorithm = RandomWalk(evaluator, seed=seed)

        assert Loop(threshold=1e-2).run(evaluator=evaluator,
                                        algorithm=algorithm) == pytest.approx(
                                            (2.0, 1.0), 1e-1)
Ejemplo n.º 4
0
def test_scipy_traffic():
    problem = TrafficProblem()

    evaluator = Evaluator(simulator=TrafficSimulator(), problem=problem)

    algorithm = ScipyAlgorithm(problem, method="Nelder-Mead")

    assert Loop(threshold=5.0).run(evaluator=evaluator,
                                   algorithm=algorithm) == pytest.approx(
                                       (510.0, 412.0), 1.0)
Ejemplo n.º 5
0
def test_cobyla_quadratic():
    problem = QuadraticProblem([2.0, 1.0], [0.0, 0.0])

    evaluator = Evaluator(simulator=QuadraticSimulator(), problem=problem)

    algorithm = ScipyAlgorithm(problem, method="COBYLA")

    assert Loop(threshold=1e-4).run(evaluator=evaluator,
                                    algorithm=algorithm) == pytest.approx(
                                        (2.0, 1.0), 1e-2)
Ejemplo n.º 6
0
def test_nelder_mead_quadratic():
    problem = QuadraticProblem([2.0, 1.0], [0.0, 0.0])

    evaluator = Evaluator(simulator=QuadraticSimulator(), problem=problem)

    algorithm = NelderMead(problem)

    assert Loop(threshold=1e-4).run(evaluator=evaluator,
                                    algorithm=algorithm) == pytest.approx(
                                        (2.0, 1.0), 1e-2)
Ejemplo n.º 7
0
def test_random_walk_quadratic():
    problem = QuadraticProblem([2.0, 1.0])

    evaluator = Evaluator(simulator=QuadraticSimulator(), problem=problem)

    algorithm = RandomWalk(problem, seed=1000)

    assert Loop(threshold=1e-2).run(evaluator=evaluator,
                                    algorithm=algorithm) == pytest.approx(
                                        (2.0, 1.0), 1e-1)
Ejemplo n.º 8
0
def test_cmaes_quadratic():
    problem = QuadraticProblem([2.0, 1.0], [0.0, 0.0])

    evaluator = Evaluator(simulator=QuadraticSimulator(), problem=problem)

    for seed in (1000, 2000, 3000, 4000):
        algorithm = CMAES(problem, initial_step_size=0.1, seed=seed)

        assert Loop(threshold=1e-4).run(evaluator=evaluator,
                                        algorithm=algorithm) == pytest.approx(
                                            (2.0, 1.0), 1e-2)
Ejemplo n.º 9
0
def test_cmaes_traffic():
    problem = TrafficProblem()

    evaluator = Evaluator(simulator=TrafficSimulator(), problem=problem)

    for seed in (1000, 2000, 3000, 4000):
        algorithm = CMAES(problem, initial_step_size=10.0, seed=seed)

        assert Loop(threshold=1e-2).run(evaluator=evaluator,
                                        algorithm=algorithm) == pytest.approx(
                                            (510.0, 412.0), 1.0)
Ejemplo n.º 10
0
def test_cma_es():
    for seed in (1000, 2000, 3000, 4000):
        evaluator = Evaluator(simulator=CongestionSimulator(),
                              problem=CongestionProblem(0.3, iterations=200))

        algorithm = CMAES(evaluator, initial_step_size=50, seed=seed)

        assert abs(
            np.round(
                Loop(threshold=1e-4).run(evaluator=evaluator,
                                         algorithm=algorithm)) - 230) < 10
Ejemplo n.º 11
0
def __test_sis_single_fidelity():
    evaluator = Evaluator(simulator=SISSimulator(), problem=SISProblem(0.6))

    algorithm = BatchBayesianOptimization(evaluator, batch_size=4)

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        np.random.seed(0)

        assert Loop(threshold=1e-2).run(evaluator=evaluator,
                                        algorithm=algorithm) == pytest.approx(
                                            0.625, 1e-1)
Ejemplo n.º 12
0
def test_nelder_mead_traffic():
    problem = TrafficProblem()
    problem.use_bounds([[400.0, 600.0]] * 2)

    evaluator = Evaluator(simulator=TrafficSimulator(),
                          problem=TrafficProblem())

    algorithm = NelderMead(problem)

    assert Loop(threshold=1e-2).run(evaluator=evaluator,
                                    algorithm=algorithm) == pytest.approx(
                                        (510.0, 412.0), 1.0)
Ejemplo n.º 13
0
def test_scipy():
    evaluator = Evaluator(
        simulator = QuadraticSimulator(),
        problem = QuadraticProblem([2.0, 1.0], [0.0, 0.0])
    )

    algorithm = ScipyAlgorithm(evaluator, method = "COBYLA")

    assert Loop(threshold = 1e-3).run(
        evaluator = evaluator,
        algorithm = algorithm
    ) == pytest.approx((2.0, 1.0), 1e-3)
Ejemplo n.º 14
0
def __test_bayesian_optimization():
    evaluator = Evaluator(simulator=QuadraticSimulator(),
                          problem=QuadraticProblem([2.0, 1.0]))

    algorithm = BatchBayesianOptimization(evaluator, batch_size=4)

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        np.random.seed(0)

        assert Loop(threshold=1e-2).run(evaluator=evaluator,
                                        algorithm=algorithm) == pytest.approx(
                                            (2.0, 1.0), 1e-1)
Ejemplo n.º 15
0
def test_spsa():
    evaluator = Evaluator(simulator=QuadraticSimulator(),
                          problem=QuadraticProblem([2.0, 1.0], [0.0, 0.0]))

    for seed in (1000, 2000, 3000, 4000):
        algorithm = SPSA(evaluator,
                         perturbation_factor=2e-2,
                         gradient_factor=0.2,
                         seed=seed)

        assert Loop(threshold=1e-4).run(evaluator=evaluator,
                                        algorithm=algorithm) == pytest.approx(
                                            (2.0, 1.0), 1e-2)
Ejemplo n.º 16
0
def test_spsa_traffic():
    problem = TrafficProblem()

    evaluator = Evaluator(simulator=TrafficSimulator(), problem=problem)

    for seed in (1000, 2000, 3000, 4000):
        algorithm = SPSA(problem,
                         perturbation_factor=10.0,
                         gradient_factor=1.0,
                         seed=seed)

        assert Loop(threshold=1e-2).run(evaluator=evaluator,
                                        algorithm=algorithm) == pytest.approx(
                                            (510.0, 412.0), 1.0)
Ejemplo n.º 17
0
def test_fdsa_quadratic():
    problem = QuadraticProblem([2.0, 1.0], [0.0, 0.0])

    evaluator = Evaluator(simulator=QuadraticSimulator(), problem=problem)

    algorithm = FDSA(
        problem,
        perturbation_factor=2e-2,
        gradient_factor=0.2,
    )

    assert Loop(threshold=1e-4).run(evaluator=evaluator,
                                    algorithm=algorithm) == pytest.approx(
                                        (2.0, 1.0), 1e-2)
Ejemplo n.º 18
0
def test_fdsa_traffic():
    problem = TrafficProblem()

    evaluator = Evaluator(simulator=TrafficSimulator(), problem=problem)

    algorithm = FDSA(
        problem,
        perturbation_factor=10.0,
        gradient_factor=1.0,
    )

    assert Loop(threshold=1e-2).run(evaluator=evaluator,
                                    algorithm=algorithm) == pytest.approx(
                                        (510.0, 412.0), 1.0)
Ejemplo n.º 19
0
def test_nelder_mead_congestion():
    evaluator = Evaluator(
        simulator = RosenbrockSimulator(),
        problem = RosenbrockProblem(2)
    )

    algorithm = NelderMead(evaluator, bounds = [
        [-6.0, 6.0],
        [-6.0, 6.0]
    ])

    assert Loop(threshold = 1e-6).run(
        evaluator = evaluator,
        algorithm = algorithm
    ) == pytest.approx((1.0, 1.0), 1e-2)
Ejemplo n.º 20
0
def test_opdyts_traffic():
    problem = TrafficProblem(iterations=40)

    evaluator = Evaluator(simulator=TrafficSimulator(), problem=problem)

    for seed in (1000, 2000, 3000, 4000):
        algorithm = Opdyts(problem,
                           candidate_set_size=16,
                           number_of_transitions=10,
                           perturbation_length=50,
                           seed=seed)

        assert Loop(threshold=1e-2).run(evaluator=evaluator,
                                        algorithm=algorithm) == pytest.approx(
                                            (510.0, 412.0), 1.0)
Ejemplo n.º 21
0
Archivo: run.py Proyecto: kaghog/octras
simulator = MATSimSimulator(
    working_directory="work",
    class_path="resources/ile_de_france-1.2.0.jar",
    main_class="org.eqasim.ile_de_france.RunSimulation")

analyzer = ParisAnalyzer(threshold=0.05,
                         number_of_bounds=40,
                         minimum_distance=100.0,
                         maximum_distance=40 * 1e3,
                         reference_path=reference_path)

problem = ParisProblem(analyzer,
                       threads=threads_per_simulation,
                       iterations=iterations,
                       config_path=config_path)

evaluator = Evaluator(problem=problem,
                      simulator=simulator,
                      parallel=parallel_simulations)

algorithm = SPSA(evaluator=evaluator,
                 perturbation_factor=0.1,
                 gradient_factor=0.5,
                 perturbation_exponent=0.101,
                 gradient_exponent=0.602,
                 gradient_offset=0)

tracker = PickleTracker(output_path)

Loop().run(evaluator=evaluator, algorithm=algorithm, tracker=tracker)