+
+
+ 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.
+ eigs = eigenvalues_re(L)
+ if soln.game_value() > options.ABS_TOL:
+ # L should be positive stable
+ positive_stable = all([eig > -options.ABS_TOL for eig in eigs])
+ self.assertTrue(positive_stable)
+ elif soln.game_value() < -options.ABS_TOL:
+ # L should be negative stable
+ negative_stable = all([eig < options.ABS_TOL for eig in eigs])
+ self.assertTrue(negative_stable)
+
+ # 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.
+ """
+ (K, e1, e2) = _random_orthant_params()[1:]
+ 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.
+ """
+ (K, e1, e2) = _random_icecream_params()[1:]
+ L = _random_lyapunov_like_icecream(K.dimension())
+
+ self.assert_lyapunov_works(L, K, e1, e2)