From 9da611019b85e58ecab8450f9a9043c6f4a184d1 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 12 Oct 2016 15:37:05 -0400 Subject: [PATCH] Add tests for the orthogonality relationships of a game solution. --- src/dunshire/games.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/dunshire/games.py b/src/dunshire/games.py index 3c53343..76fbf7d 100644 --- a/src/dunshire/games.py +++ b/src/dunshire/games.py @@ -763,3 +763,44 @@ class SymmetricLinearGameTest(TestCase): """ (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) -- 2.44.2