예제 #1
0
def test_rpss():
    from magnum.examples.rock_paper_scissors_spock import rps as g

    res = solve(g, use_smt=True)
    assert res.feasible

    res = solve(g)
    assert res.feasible
    assert len(res.counter_examples) <= 3
    assert approx(res.cost) == 0.5

    res = solve(g, max_ce=2, max_rounds=7)
    assert res.feasible
예제 #2
0
def test_rps():
    from magnum.examples.rock_paper_scissors import rps as g

    res = solve(g, use_smt=True)
    assert not res.feasible
    assert len(res.counter_examples) == 3

    with raises(MaxRoundsError):
        solve(g, max_ce=1, refuted_recs=False)

    # TODO
    res = solve(g)
    assert not res.feasible
    assert len(res.counter_examples) == 3

    res = solve(g, max_ce=1, max_rounds=10)
    assert not res.feasible
예제 #3
0
def mpc(orig: Game, *, use_smt=False,):
    prev_games = [(0, orig.scope, orig)]
    while True:
        max_age = max(map(lens[0].get(), prev_games))

        age, _, g = prev_games[0]
        g = g >> max_age - age
        for age, _, g2 in prev_games[1:]:
            g &= g2 >> max_age - age

        res = solve(g, use_smt=use_smt)
        msg = yield bind(res).solution.modify(time_shift(max_age))

        new_init = measurement_to_stl(msg.measurement)
        next_game = orig.reinit(new_init)
        next_game = next_game.new_obj(msg.obj)

        # Stale old games + Remove out of scope games + add new game.
        prev_games = [(t+1, s, g) for t, s, g in prev_games if t < s]
        prev_games.append((0, next_game.scope, next_game))
예제 #4
0
def test_feasible_example2_cegis():
    from magnum.examples.feasible_example2 import feasible_example as g

    res = solve(g)
    assert not res.feasible
    assert len(res.counter_examples) in (1, 2)
예제 #5
0
def test_nway_rps():
    for k in range(1, 4):
        g = create_game(k)
        res = cegis.solve(g)
        assert not res.feasible
        assert len(res.counter_examples) == k