def run(self): path = os.path.join('.','matrixgame','matrices','matrix_equilibrium.txt') a = gm.read_matrix(path) p,q = gm.nash_equilibrium(a) eq_i = -1 eq_j = -1 row_len = len(a[0]) col_len = len(a) for i in range(row_len): if all(p == a[i]): eq_i = i break for j in range(col_len): if all(q == a[:,j]): eq_j = j break x = eq_i + 1 y = eq_j + 1 y1 = 0 plt.vlines(x, ymin=y1, ymax=y, color='blue') plt.scatter(x, y, s=10, color='blue') plt.show()
def test_nash_equilibrium_2(self): path = os.path.join('.', 'matrixgame', 'test_matrices', 'test_matrix_2.txt') test_matrix = gm.read_matrix(path) test_p = np.round(np.array([1 / 2, 1 / 2]), decimals=5) test_q = np.round(np.array([1 / 2, 1 / 2]), decimals=5) p, q = gm.nash_equilibrium(test_matrix) p = np.round(p, decimals=5) q = np.round(q, decimals=5) self.assertEqual(p.tolist(), test_p.tolist()) self.assertEqual(q.tolist(), test_q.tolist())
def run(self): path = os.path.join('.', 'matrixgame', 'matrices', 'matrix_complete.txt') a = gm.read_matrix(path) p, q = gm.nash_equilibrium(a) try: i = 0 x = [i + 1 for i in range(len(p))] i = 0 y1 = [0 for i in range(len(p))] except TypeError: if p == q == -1: sys.exit(1) x = p + 1 p = q + 1 y1 = 0 plt.vlines(x, ymin=y1, ymax=p, color='blue') plt.scatter(x, p, s=10, color='blue') plt.show()