nhra_gt.subgames.nash¶
Nash Equilibrium Solvers for 2-Player Normal-Form Games.
This module provides standard game-theoretic solvers for computing Pure and Mixed Nash Equilibria, as well as Stackelberg and Rubinstein bargaining solutions. It includes equilibrium selection rules (payoff dominant, risk dominant).
Classes¶
NashEquilibrium
dataclass
¶
A Nash equilibrium for a finite 2-player game.
Represents a steady state where no player can benefit by changing their strategy while the other players keep theirs unchanged.
Source code in src/nhra_gt/subgames/nash.py
EquilibriumSelection
dataclass
¶
Result of an equilibrium selection process.
Wraps a chosen equilibrium and the total count of equilibria found, providing a backwards-compatible interface for callers.
Source code in src/nhra_gt/subgames/nash.py
TwoPlayerGame
dataclass
¶
Represents a 2-player normal-form game.
Includes payoff matrices and action labels for both players.
Source code in src/nhra_gt/subgames/nash.py
Functions¶
solve_game(game, mechanism='nash', rule='payoff_dominant', discount_rate=0.9, first_mover=0)
¶
Unified solver dispatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
game
|
TwoPlayerGame
|
The game to solve. |
required |
mechanism
|
str
|
'nash', 'stackelberg', 'rubinstein'. |
'nash'
|
rule
|
str
|
Equilibrium selection rule for Nash ('payoff_dominant', 'risk_dominant', 'random'). |
'payoff_dominant'
|
discount_rate
|
float
|
Delta for Rubinstein/Sequential. |
0.9
|
first_mover
|
int
|
Index of the first mover (Stackelberg Leader). |
0
|
Returns:
| Type | Description |
|---|---|
EquilibriumSelection
|
EquilibriumSelection wrapping the solution. |
Source code in src/nhra_gt/subgames/nash.py
pure_nash(game)
¶
Finds all Pure Strategy Nash Equilibria.
An action profile is a PNE if no player can unilaterally improve their payoff by switching to a different pure action.
Source code in src/nhra_gt/subgames/nash.py
mixed_nash_2x2(game)
¶
Solve mixed Nash for 2x2 games using the indifference principle.
Returns None if the game is degenerate or has only pure equilibria.
Source code in src/nhra_gt/subgames/nash.py
all_nash(game)
¶
Finds all pure Nash equilibria, plus the mixed equilibrium for 2x2 games.
Source code in src/nhra_gt/subgames/nash.py
solve_all_equilibria(game)
¶
select_equilibrium(eqs, rule='payoff_dominant', u_row=None, u_col=None)
¶
Select one equilibrium from a set.
Rules
- 'payoff_dominant': maximise sum of expected payoffs
- 'row_favourable': maximise row expected payoff
- 'random': uniform random
For mixed equilibria, expected payoffs use row@U@col.
Source code in src/nhra_gt/subgames/nash.py
get_best_response_path(game, max_iter=10)
¶
Simulates iterative best response from a starting position.
Used for visualizing the path to equilibrium (v25 re-integration).