Skip to content

Commit d9c1e8a

Browse files
authored
Merge pull request #504 from QuantEcon/fix-gt-warning
FIX: Player.is_dominated: Fix warnings
2 parents 35215de + f348e23 commit d9c1e8a

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

quantecon/game_theory/normal_form_game.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ def is_dominated(self, action, tol=None, method=None):
436436
method : str, optional(default=None)
437437
If None, `lemke_howson` from `quantecon.game_theory` is used
438438
to solve for a Nash equilibrium of an auxiliary zero-sum
439-
game. If `method` is set to `'simplex'` or
440-
`'interior-point'`, `scipy.optimize.linprog` is used with
441-
the method as specified by `method`.
439+
game. If `method` is set to `'simplex'`, `'interior-point'`,
440+
or `'revised simplex'`, then `scipy.optimize.linprog` is
441+
used with the method as specified by `method`.
442442
443443
Returns
444444
-------
@@ -469,20 +469,21 @@ def is_dominated(self, action, tol=None, method=None):
469469
g_zero_sum = NormalFormGame([Player(D), Player(-D.T)])
470470
NE = lemke_howson(g_zero_sum)
471471
return NE[0] @ D @ NE[1] > tol
472-
elif method in ['simplex', 'interior-point']:
472+
elif method in ['simplex', 'interior-point', 'revised simplex']:
473473
from scipy.optimize import linprog
474474
m, n = D.shape
475-
A = np.empty((n+2, m+1))
476-
A[:n, :m] = -D.T
477-
A[:n, -1] = 1 # Slack variable
478-
A[n, :m], A[n+1, :m] = 1, -1 # Equality constraint
479-
A[n:, -1] = 0
480-
b = np.empty(n+2)
481-
b[:n] = 0
482-
b[n], b[n+1] = 1, -1
475+
A_ub = np.empty((n, m+1))
476+
A_ub[:, :m] = -D.T
477+
A_ub[:, -1] = 1 # Slack variable
478+
b_ub = np.zeros(n)
479+
A_eq = np.empty((1, m+1))
480+
A_eq[:, :m] = 1 # Equality constraint
481+
A_eq[:, -1] = 0
482+
b_eq = np.ones(1)
483483
c = np.zeros(m+1)
484484
c[-1] = -1
485-
res = linprog(c, A_ub=A, b_ub=b, method=method)
485+
res = linprog(c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq,
486+
method=method)
486487
if res.success:
487488
return res.x[-1] > tol
488489
elif res.status == 2: # infeasible
@@ -507,9 +508,9 @@ def dominated_actions(self, tol=None, method=None):
507508
method : str, optional(default=None)
508509
If None, `lemke_howson` from `quantecon.game_theory` is used
509510
to solve for a Nash equilibrium of an auxiliary zero-sum
510-
game. If `method` is set to `'simplex'` or
511-
`'interior-point'`, `scipy.optimize.linprog` is used with
512-
the method as specified by `method`.
511+
game. If `method` is set to `'simplex'`, `'interior-point'`,
512+
or `'revised simplex'`, then `scipy.optimize.linprog` is
513+
used with the method as specified by `method`.
513514
514515
Returns
515516
-------

quantecon/game_theory/tests/test_normal_form_game.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# Player #
1515

16-
LP_METHODS = [None, 'simplex', 'interior-point']
16+
LP_METHODS = [None, 'simplex', 'interior-point', 'revised simplex']
1717

1818

1919
class TestPlayer_1opponent:
@@ -162,7 +162,7 @@ def test_player_corner_cases():
162162
for method in LP_METHODS:
163163
eq_(player.is_dominated(action, method=method), False)
164164

165-
e = 1e-8
165+
e = 1e-8 * 2
166166
player = Player([[-e, -e], [1, -1], [-1, 1]])
167167
action = 0
168168
eq_(player.is_best_response(action, [1/2, 1/2], tol=e), True)

0 commit comments

Comments
 (0)