Skip to content

Commit af7141e

Browse files
committed
support_enumeration: Refactoring
Use `NormalFormGame.payoff_arrays` (#382)
1 parent d73c959 commit af7141e

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

quantecon/game_theory/support_enumeration.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,19 @@ def support_enumeration_gen(g):
6262
raise TypeError('input must be a 2-player NormalFormGame')
6363
if N != 2:
6464
raise NotImplementedError('Implemented only for 2-player games')
65-
return _support_enumeration_gen(g.players[0].payoff_array,
66-
g.players[1].payoff_array)
65+
return _support_enumeration_gen(g.payoff_arrays)
6766

6867

6968
@jit(nopython=True) # cache=True raises _pickle.PicklingError
70-
def _support_enumeration_gen(payoff_matrix0, payoff_matrix1):
69+
def _support_enumeration_gen(payoff_matrices):
7170
"""
7271
Main body of `support_enumeration_gen`.
7372
7473
Parameters
7574
----------
76-
payoff_matrix0 : ndarray(float, ndim=2)
77-
Payoff matrix for player 0, of shape (m, n)
78-
79-
payoff_matrix1 : ndarray(float, ndim=2)
80-
Payoff matrix for player 1, of shape (n, m)
75+
payoff_matrices : tuple(ndarray(float, ndim=2))
76+
Tuple of payoff matrices, of shapes (m, n) and (n, m),
77+
respectively.
8178
8279
Yields
8380
------
@@ -86,7 +83,7 @@ def _support_enumeration_gen(payoff_matrix0, payoff_matrix1):
8683
respectively.
8784
8885
"""
89-
nums_actions = payoff_matrix0.shape[0], payoff_matrix1.shape[0]
86+
nums_actions = payoff_matrices[0].shape
9087
n_min = min(nums_actions)
9188

9289
for k in range(1, n_min+1):
@@ -97,10 +94,12 @@ def _support_enumeration_gen(payoff_matrix0, payoff_matrix1):
9794
while supps[0][-1] < nums_actions[0]:
9895
supps[1][:] = np.arange(k)
9996
while supps[1][-1] < nums_actions[1]:
100-
if _indiff_mixed_action(payoff_matrix0, supps[0], supps[1],
101-
A, actions[1]):
102-
if _indiff_mixed_action(payoff_matrix1, supps[1], supps[0],
103-
A, actions[0]):
97+
if _indiff_mixed_action(
98+
payoff_matrices[0], supps[0], supps[1], A, actions[1]
99+
):
100+
if _indiff_mixed_action(
101+
payoff_matrices[1], supps[1], supps[0], A, actions[0]
102+
):
104103
out = (np.zeros(nums_actions[0]),
105104
np.zeros(nums_actions[1]))
106105
for p, (supp, action) in enumerate(zip(supps,
@@ -139,7 +138,7 @@ def _indiff_mixed_action(payoff_matrix, own_supp, opp_supp, A, out):
139138
140139
out : ndarray(float, ndim=1)
141140
Array of length k+1 to store the k nonzero values of the desired
142-
mixed action in `out[:-1]` (and the payoff value in `out[-1]`.)
141+
mixed action in `out[:-1]` (and the payoff value in `out[-1]`).
143142
144143
Returns
145144
-------

0 commit comments

Comments
 (0)