+
+
+ 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)
+
+
+ def assert_lyapunov_works(self, L, K, e1, e2):
+ """
+ Check that Lyapunov games act the way we expect.
+ """
+ game = SymmetricLinearGame(L, K, e1, e2)
+ soln = game.solution()
+
+ # We only check for positive/negative stability if the game
+ # value is not basically zero. If the value is that close to
+ # zero, we just won't check any assertions.
+ if soln.game_value() > options.ABS_TOL:
+ # L should be positive stable
+ ps = all([eig > -options.ABS_TOL for eig in eigenvalues_re(L)])
+ self.assertTrue(ps)
+ elif soln.game_value() < -options.ABS_TOL:
+ # L should be negative stable
+ ns = all([eig < options.ABS_TOL for eig in eigenvalues_re(L)])
+ self.assertTrue(ns)
+
+ # The dual game's value should always equal the primal's.
+ dualsoln = game.dual().solution()
+ self.assert_within_tol(dualsoln.game_value(), soln.game_value())
+
+
+ def test_lyapunov_orthant(self):
+ """
+ Test that a Lyapunov game on the nonnegative orthant works.
+ """
+ (L, K, e1, e2) = _random_orthant_params()
+
+ # Ignore that L, we need a diagonal (Lyapunov-like) one.
+ # (And we don't need to transpose those.)
+ L = _random_diagonal_matrix(K.dimension())
+
+ self.assert_lyapunov_works(L, K, e1, e2)
+
+
+ def test_lyapunov_icecream(self):
+ """
+ Test that a Lyapunov game on the ice-cream cone works.
+ """
+ (L, K, e1, e2) = _random_icecream_params()
+
+ # Ignore that L, we need a diagonal (Lyapunov-like) one.
+ # (And we don't need to transpose those.)
+ L = _random_lyapunov_like_icecream(K.dimension())
+
+ self.assert_lyapunov_works(L, K, e1, e2)