Skip to content

Commit

Permalink
Allow passing a game directly to dominance elimination
Browse files Browse the repository at this point in the history
  • Loading branch information
tturocy committed Oct 23, 2024
1 parent 1495c43 commit b965801
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/pygambit/supports.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


def undominated_strategies_solve(
profile: gbt.StrategySupportProfile,
profile: gbt.Game | gbt.StrategySupportProfile,
strict: bool = False,
external: bool = False
) -> gbt.StrategySupportProfile:
Expand All @@ -36,8 +36,9 @@ def undominated_strategies_solve(
Parameters
----------
profile: StrategySupportProfile
The initial profile of strategies
profile : Game or StrategySupportProfile
The initial profile of strategies. If a `Game` is passed, elimination begins with
the full set of strategies on the game.
strict : bool, default False
If specified `True`, eliminate only strategies which are strictly dominated.
Expand All @@ -53,4 +54,6 @@ def undominated_strategies_solve(
StrategySupportProfile
A new support profile containing only the strategies which are not dominated.
"""
if isinstance(profile, gbt.Game):
profile = profile.strategy_support_profile()
return libgbt._undominated_strategies_solve(profile, strict, external)
12 changes: 5 additions & 7 deletions tests/test_stratprofiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ def test_union():

def test_undominated():
game = games.read_from_file("mixed_strategy.nfg")
support_profile = game.strategy_support_profile()
loop_profile = gbt.supports.undominated_strategies_solve(support_profile)
profile = gbt.supports.undominated_strategies_solve(game)
while True:
new_profile = loop_profile
loop_profile = gbt.supports.undominated_strategies_solve(new_profile)
if new_profile == loop_profile:
new_profile = gbt.supports.undominated_strategies_solve(profile)
if new_profile == profile:
break
assert len(loop_profile) == 2
assert loop_profile == game.strategy_support_profile(lambda x: x.label == "1")
profile = new_profile
assert profile == game.strategy_support_profile(lambda x: x.label == "1")


def test_remove_error():
Expand Down

0 comments on commit b965801

Please sign in to comment.