+
+
+class SymmetricLinearGameTest(TestCase):
+
+ def assertEqualWithinTol(self, first, second):
+ """
+ Test that ``first`` and ``second`` are equal within our default
+ tolerance.
+ """
+ self.assertTrue(abs(first - second) < options.ABS_TOL)
+
+
+ def test_solution_exists(self):
+ """
+ Every linear game has a solution, so we should be able to solve
+ every symmetric linear game. Pick some parameters randomly and
+ give it a shot.
+ """
+ from cones import NonnegativeOrthant
+ from random import randint, uniform
+ ambient_dim = randint(1,10)
+ K = NonnegativeOrthant(ambient_dim)
+ e1 = [uniform(0.1, 10) for idx in range(ambient_dim)]
+ e2 = [uniform(0.1, 10) for idx in range(ambient_dim)]
+ L = [[uniform(-10, 10) for i in range(ambient_dim)]
+ for j in range(ambient_dim)]
+ G = SymmetricLinearGame(L, K, e1, e2)
+ soln = G.solution()
+ L_matrix = matrix(L).trans()
+ expected = inner_product(L_matrix*soln.player1_optimal(),
+ soln.player2_optimal())
+ self.assertEqualWithinTol(soln.game_value(), expected)