+
+ 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))
+ G = SymmetricLinearGame(L, K, e1, e2)
+ G_soln = G.solution()
+ value_G = G_soln.game_value()
+ x_bar = G_soln.player1_optimal()
+ y_bar = G_soln.player2_optimal()
+
+ alpha = uniform(-10, 10)
+ # 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()
+ E = e1*e2.trans()
+ # Likewise, this is the "correct" representation of ``M``, but
+ # COLUMN indexed...
+ M = L + alpha*E
+
+ # so we have to transpose it when we feed it to the constructor.
+ H = SymmetricLinearGame(M.trans(), K, e1, e2)
+ value_H = H.solution().game_value()
+
+ # Make sure the same optimal pair works.
+ H_payoff = inner_product(M*x_bar, y_bar)
+
+ self.assert_within_tol(value_G + alpha, value_H)
+ self.assert_within_tol(value_H, H_payoff)
+
+
+ def test_translation_orthant(self):
+ """
+ Test that translation works over the nonnegative orthant.
+ """
+ (L, K, e1, e2) = self.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) = self.random_icecream_params()
+ self.assert_translation_works(L, K, e1, e2)
+
+
+ def assert_opposite_game_works(self, L, K, e1, e2):
+ e1 = matrix(e1, (K.dimension(), 1))
+ e2 = matrix(e2, (K.dimension(), 1))
+ G = 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.
+ H = SymmetricLinearGame(M.trans(), K, e2, e1)
+
+ G_soln = G.solution()
+ x_bar = G_soln.player1_optimal()
+ y_bar = G_soln.player2_optimal()
+ H_soln = H.solution()
+
+ # Make sure the switched optimal pair works.
+ H_payoff = inner_product(M*y_bar, x_bar)
+
+ self.assert_within_tol(-G_soln.game_value(), H_soln.game_value())
+ self.assert_within_tol(H_soln.game_value(), H_payoff)
+
+
+ def test_opposite_game_orthant(self):
+ """
+ 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.
+ """
+ (L, K, e1, e2) = self.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) = self.random_icecream_params()
+ self.assert_opposite_game_works(L, K, e1, e2)