Esempio n. 1
0
 def test_3(self):
     matrix = np.array([[4, 0, 6, 2, 2, 1], [3, 8, 4, 10, 4, 4],
                        [1, 2, 6, 5, 0, 0], [6, 6, 4, 4, 10, 3],
                        [10, 4, 6, 4, 0, 9], [10, 7, 0, 7, 9, 8]])
     func_p, func_q, func_cost = nash_equilibrium1(matrix)
     p, q, cost = nash.nash_equilibrium(matrix)
     assert_equals(abs(func_cost - cost) < 0.00001, True)
     assert_equals(sum(abs(x - y) < 0.00001 for x, y in zip(func_p, p)),
                   len(func_p))
     assert_equals(sum(abs(x - y) < 0.00001 for x, y in zip(func_q, q)),
                   len(func_q))
Esempio n. 2
0
 def test_6(self):
     matrix = np.array([
         [8, 4, 7],
         [6, 5, 9],
         [7, 6, 8],
     ])
     func_p, func_q, func_cost = nash_equilibrium1(matrix)
     p, q, cost = nash.nash_equilibrium(matrix)
     assert_equals(abs(func_cost - cost) < 0.00001, True)
     assert_equals(sum(abs(x - y) < 0.00001 for x, y in zip(func_p, p)),
                   len(func_p))
     assert_equals(sum(abs(x - y) < 0.00001 for x, y in zip(func_q, q)),
                   len(func_q))
Esempio n. 3
0
 def test_2(self):
     matrix = np.array([
         [0, 0, 0],
         [1, 3, 5],
         [2, 4, 6],
     ])
     func_p, func_q, func_cost = nash_equilibrium1(matrix)
     p, q, cost = nash.nash_equilibrium(matrix)
     assert_equals(abs(func_cost - cost) < 0.00001, True)
     assert_equals(sum(abs(x - y) < 0.00001 for x, y in zip(func_p, p)),
                   len(func_p))
     assert_equals(sum(abs(x - y) < 0.00001 for x, y in zip(func_q, q)),
                   len(func_q))