示例#1
0
async def test_merge_trace():
    """Test that traces are merged"""
    game0 = asyncgame.wrap(
        paygame.game(2, 2, [[2, 0], [1, 1], [0, 2]], [[0, 0], [1, 1], [0, 0]]))
    game1 = asyncgame.wrap(
        paygame.game(2, 2, [[2, 0], [1, 1], [0, 2]], [[0, 0], [1, 1], [0, 3]]))
    traces = await trace.trace_all_equilibria(game0, game1)
    assert len(traces) == 1
示例#2
0
async def test_basic_asyncgame():
    """Test that wrapped async games work"""
    game = gamegen.game([4, 3], [3, 4])
    agame = asyncgame.wrap(game)
    rest = agame.random_restriction()
    rgame = await agame.get_restricted_game(rest)
    assert rgame.is_complete()
    assert rsgame.empty_copy(rgame) == rsgame.empty_copy(game.restrict(rest))

    dgame = await agame.get_deviation_game(rest)
    mix = restrict.translate(rgame.random_mixture(), rest)
    assert not np.isnan(dgame.deviation_payoffs(mix)).any()

    dup = asyncgame.wrap(game)
    assert hash(dup) == hash(agame)
    assert dup == agame
示例#3
0
async def test_innerloop_game(base):
    """Test that inner loop works for a game"""
    game = gamegen.samplegame_replace(base)
    sched = gamesched.gamesched(game)
    eqas = await innerloop.inner_loop(schedgame.schedgame(sched))
    verify_dist_thresh(eqas)
    eqag = await innerloop.inner_loop(asyncgame.wrap(game))
    assert utils.allclose_perm(eqas, eqag, atol=1e-3, rtol=1e3)
示例#4
0
async def test_mix_asyncgame():
    """Test that that mixture async games work"""
    game0 = gamegen.game([4, 3], [3, 4])
    game1 = gamegen.game([4, 3], [3, 4])
    agame = asyncgame.mix(asyncgame.wrap(game0), asyncgame.wrap(game1), 0.4)
    assert agame.get_game() == rsgame.mix(game0, game1, 0.4)
    assert str(agame) == "{} - 0.4 - {}".format(repr(game0), repr(game1))

    rest = agame.random_restriction()
    rgame = await agame.get_restricted_game(rest)
    assert rgame.is_complete()
    assert rsgame.empty_copy(rgame) == rsgame.empty_copy(game0.restrict(rest))

    dgame = await agame.get_deviation_game(rest)
    mix = restrict.translate(rgame.random_mixture(), rest)
    assert not np.isnan(dgame.deviation_payoffs(mix)).any()

    dup = asyncgame.mix(asyncgame.wrap(game0), asyncgame.wrap(game1), 0.4)
    assert hash(dup) == hash(agame)
    assert dup == agame
示例#5
0
async def test_at_least_one(base, _):
    """inner loop should always find one equilibrium with at_least one"""
    game = gamegen.game_replace(base)
    eqa = await innerloop.inner_loop(asyncgame.wrap(game), style='one')
    assert eqa.size
示例#6
0
async def test_random_trace_game(base):
    """Test tracing for random games"""
    agame1 = asyncgame.wrap(gamegen.game_replace(base))
    agame2 = asyncgame.wrap(gamegen.game_replace(base))
    traces = await trace.trace_all_equilibria(agame1, agame2, style="one")
    verify_complete_traces(traces)