+ def assert_translation_works(self, L, K, e1, e2):
+ """
+ Check that translating ``L`` by alpha*(e1*e2.trans()) increases
+ the value of the associated game by alpha.
+ """
+ e1 = matrix(e1, (K.dimension(), 1))
+ e2 = matrix(e2, (K.dimension(), 1))
+ game1 = SymmetricLinearGame(L, K, e1, e2)
+ soln1 = game1.solution()
+ value1 = soln1.game_value()
+ x_bar = soln1.player1_optimal()
+ y_bar = soln1.player2_optimal()
+
+ # Make ``L`` a CVXOPT matrix so that we can do math with
+ # it. Note that this gives us the "correct" representation of
+ # ``L`` (in agreement with what G has), but COLUMN indexed.
+ alpha = uniform(-10, 10)
+ L = matrix(L).trans()
+ tensor_prod = e1*e2.trans()
+
+ # Likewise, this is the "correct" representation of ``M``, but
+ # COLUMN indexed...
+ M = L + alpha*tensor_prod
+
+ # so we have to transpose it when we feed it to the constructor.
+ game2 = SymmetricLinearGame(M.trans(), K, e1, e2)
+ value2 = game2.solution().game_value()
+
+ self.assert_within_tol(value1 + alpha, value2)
+
+ # Make sure the same optimal pair works.
+ self.assert_within_tol(value2, inner_product(M*x_bar, y_bar))
+
+
+ def test_translation_orthant(self):
+ """
+ Test that translation works over the nonnegative orthant.
+ """
+ (L, K, e1, e2) = _random_orthant_params()
+ self.assert_translation_works(L, K, e1, e2)
+
+
+ def test_translation_icecream(self):
+ """
+ The same as :meth:`test_translation_orthant`, except over the
+ ice cream cone.
+ """
+ (L, K, e1, e2) = _random_icecream_params()
+ self.assert_translation_works(L, K, e1, e2)
+
+
+ def assert_opposite_game_works(self, L, K, e1, e2):
+ """
+ Check the value of the "opposite" game that gives rise to a
+ value that is the negation of the original game. Comes from
+ some corollary.
+ """
+ e1 = matrix(e1, (K.dimension(), 1))
+ e2 = matrix(e2, (K.dimension(), 1))
+ game1 = SymmetricLinearGame(L, K, e1, e2)
+
+ # Make ``L`` a CVXOPT matrix so that we can do math with
+ # it. Note that this gives us the "correct" representation of
+ # ``L`` (in agreement with what G has), but COLUMN indexed.
+ L = matrix(L).trans()
+
+ # Likewise, this is the "correct" representation of ``M``, but
+ # COLUMN indexed...
+ M = -L.trans()
+
+ # so we have to transpose it when we feed it to the constructor.
+ game2 = SymmetricLinearGame(M.trans(), K, e2, e1)
+
+ soln1 = game1.solution()
+ x_bar = soln1.player1_optimal()
+ y_bar = soln1.player2_optimal()
+ soln2 = game2.solution()
+
+ self.assert_within_tol(-soln1.game_value(), soln2.game_value())
+
+ # Make sure the switched optimal pair works.
+ self.assert_within_tol(soln2.game_value(),
+ inner_product(M*y_bar, x_bar))
+
+
+ def test_opposite_game_orthant(self):
+ """
+ Test the value of the "opposite" game over the nonnegative
+ orthant.
+ """
+ (L, K, e1, e2) = _random_orthant_params()
+ self.assert_opposite_game_works(L, K, e1, e2)
+
+
+ def test_opposite_game_icecream(self):
+ """
+ Like :meth:`test_opposite_game_orthant`, except over the
+ ice-cream cone.
+ """
+ (L, K, e1, e2) = _random_icecream_params()
+ self.assert_opposite_game_works(L, K, e1, e2)
+
+
+ def assert_orthogonality(self, L, K, e1, e2):
+ """
+ Two orthogonality relations hold at an optimal solution, and we
+ check them here.
+ """
+ game = SymmetricLinearGame(L, K, e1, e2)
+ soln = game.solution()
+ x_bar = soln.player1_optimal()
+ y_bar = soln.player2_optimal()
+ value = soln.game_value()
+
+ # Make these matrices so that we can compute with them.
+ L = matrix(L).trans()
+ e1 = matrix(e1, (K.dimension(), 1))
+ e2 = matrix(e2, (K.dimension(), 1))
+
+ ip1 = inner_product(y_bar, L*x_bar - value*e1)
+ self.assert_within_tol(ip1, 0)
+
+ ip2 = inner_product(value*e2 - L.trans()*y_bar, x_bar)
+ self.assert_within_tol(ip2, 0)
+
+
+ def test_orthogonality_orthant(self):
+ """
+ Check the orthgonality relationships that hold for a solution
+ over the nonnegative orthant.
+ """
+ (L, K, e1, e2) = _random_orthant_params()
+ self.assert_orthogonality(L, K, e1, e2)
+
+
+ def test_orthogonality_icecream(self):
+ """
+ Check the orthgonality relationships that hold for a solution
+ over the ice-cream cone.
+ """
+ (L, K, e1, e2) = _random_icecream_params()
+ self.assert_orthogonality(L, K, e1, e2)
+
+
+ def test_positive_operator_value(self):
+ """
+ Test that a positive operator on the nonnegative orthant gives
+ rise to a a game with a nonnegative value.
+
+ This test theoretically applies to the ice-cream cone as well,
+ but we don't know how to make positive operators on that cone.
+ """
+ (_, K, e1, e2) = _random_orthant_params()
+
+ # Ignore that L, we need a nonnegative one.
+ L = _random_nonnegative_matrix(K.dimension())
+
+ game = SymmetricLinearGame(L, K, e1, e2)
+ self.assertTrue(game.solution().game_value() >= -options.ABS_TOL)