Skip to content

Commit 39deff0

Browse files
authored
Add enumpoly solver strategic-form tests (#969)
* Added 3 player max cut test for enumpoly strategic form * added strategic game tests for enumpoly strategic form: 3x3 coordination game, 3-player unique Nash (nau2004 sec4), 2x2x2 3 pure Nash (nau2004 sec5)
1 parent 5482aaa commit 39deff0

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ markers = [
102102
"nash_enumpure_strategy: tests of enumpure_solve in pure strategies",
103103
"nash_enumpure_agent: tests of enumpure_solve in pure behaviors",
104104
"nash_enummixed_strategy: tests of enummixed_solve in mixed strategies",
105+
"nash_enumpoly_strategy: tests of enumpoly_solve in mixed strategies",
105106
"nash_enumpoly_behavior: tests of enumpoly_solve in mixed behaviors",
106107
"nash_lcp_strategy: tests of lcp_solve in mixed strategies",
107108
"nash_lcp_behavior: tests of lcp_solve in mixed behaviors",

tests/test_games/2x2x2_nfg_from_local_max_cut_2_pure_1_mixed_eq.nfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ NFG 1 R "2x2x2 game with 2 pure and 1 mixed equilibrium"
66
- Pure strategies {a,b} encode if respective player is on left or right of the cut
77
- The payoff to a player is the sum of their incident edges across the implied cut
88
- Pure equilibrium iff local max cuts; in addition, uniform mixture is an equilibrium
9+
- In the mixed equilibrium all players mix strategies with equal probability (0.5, 0.5)
910
- Equilibrium analysis for pure profiles:
1011
a a a: 0 0 0 -- Not Nash (regrets: 1, 4, 1)
1112
b a a: 1 2 -1 -- Not Nash (regrets: 0, 0, 3)

tests/test_nash.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,84 @@ class QREquilibriumTestCase:
411411
]
412412

413413

414+
ENUMPOLY_STRATEGY_CASES = [
415+
# 2x2x2 strategic form game based on local max cut -- 2 pure and 1 mixed
416+
pytest.param(
417+
EquilibriumTestCase(
418+
factory=functools.partial(
419+
games.read_from_file, "2x2x2_nfg_from_local_max_cut_2_pure_1_mixed_eq.nfg"
420+
),
421+
solver=functools.partial(gbt.nash.enumpoly_solve, stop_after=None),
422+
expected=[
423+
[d(1, 0), d(0, 1), d(1, 0)],
424+
[d(0, 1), d(1, 0), d(0, 1)],
425+
[d("1/2", "1/2"), d("1/2", "1/2"), d("1/2", "1/2")],
426+
],
427+
prob_tol=TOL,
428+
regret_tol=TOL,
429+
),
430+
marks=pytest.mark.nash_enumpoly_strategy,
431+
id="test_enumpoly_strategy_1",
432+
),
433+
# coordination game with 3 pure and 4 mixed equilibria
434+
pytest.param(
435+
EquilibriumTestCase(
436+
factory=functools.partial(games.create_EFG_for_nxn_bimatrix_coordination_game, n=3),
437+
solver=functools.partial(gbt.nash.enumpoly_solve, stop_after=None, use_strategic=True),
438+
expected=[
439+
[d(1, 0, 0), d(1, 0, 0)],
440+
[d(0, 1, 0), d(0, 1, 0)],
441+
[d(0, 0, 1), d(0, 0, 1)],
442+
[d("1/2", "1/2", 0), d("1/2", "1/2", 0)],
443+
[d("1/2", 0, "1/2"), d("1/2", 0, "1/2")],
444+
[d(0, "1/2", "1/2"), d(0, "1/2", "1/2")],
445+
[d("1/3", "1/3", "1/3"), d("1/3", "1/3", "1/3")],
446+
],
447+
prob_tol=TOL,
448+
regret_tol=TOL,
449+
),
450+
marks=pytest.mark.nash_enumpoly_strategy,
451+
id="test_enumpoly_strategy_2",
452+
),
453+
# A three-player game with a unique Nash equilibrium in irrational mixed strategies
454+
# (nau2004 sec4 catalog game)
455+
pytest.param(
456+
EquilibriumTestCase(
457+
factory=functools.partial(gbt.catalog.load, "journals/ijgt/nau2004/sec4"),
458+
solver=functools.partial(gbt.nash.enumpoly_solve, stop_after=None),
459+
expected=[
460+
[
461+
d(0.6192325794725537, 0.3807674205274463),
462+
d(0.4798042226776053, 0.5201957773223946),
463+
d(0.3788253360656313, 0.6211746639343687)
464+
],
465+
],
466+
prob_tol=TOL,
467+
regret_tol=TOL,
468+
),
469+
marks=pytest.mark.nash_enumpoly_strategy,
470+
id="test_enumpoly_strategy_3",
471+
),
472+
# A three-player 2x2x2 game with 3 pure, 2 incompletely mixed, and a
473+
# continuum of completely mixed Nash equilibria (nau2004 sec5 catalog game)
474+
pytest.param(
475+
EquilibriumTestCase(
476+
factory=functools.partial(gbt.catalog.load, "journals/ijgt/nau2004/sec5"),
477+
solver=functools.partial(gbt.nash.enumpoly_solve, stop_after=None),
478+
expected=[
479+
[d(1, 0), d(0, 1), d(1, 0)],
480+
[d(0, 1), d(1, 0), d(1, 0)],
481+
[d(0, 1), d(0, 1), d(0, 1)],
482+
],
483+
prob_tol=TOL,
484+
regret_tol=TOL,
485+
),
486+
marks=pytest.mark.nash_enumpoly_strategy,
487+
id="test_enumpoly_strategy_4",
488+
),
489+
]
490+
491+
414492
LP_STRATEGY_RATIONAL_CASES = [
415493
pytest.param(
416494
EquilibriumTestCase(
@@ -945,6 +1023,7 @@ class QREquilibriumTestCase:
9451023
CASES += ENUMPURE_CASES
9461024
CASES += ENUMMIXED_RATIONAL_CASES
9471025
CASES += ENUMMIXED_DOUBLE_CASES
1026+
CASES += ENUMPOLY_STRATEGY_CASES
9481027
CASES += LP_STRATEGY_RATIONAL_CASES
9491028
CASES += LP_STRATEGY_DOUBLE_CASES
9501029
CASES += LCP_STRATEGY_RATIONAL_CASES

0 commit comments

Comments
 (0)