]> gitweb.michael.orlitzky.com - dunshire.git/blobdiff - src/dunshire/errors.py
Print the game data along with every GameUnsolvableException.
[dunshire.git] / src / dunshire / errors.py
index 020186475b2a920f8425ffe0be76b3a27625de85..b63344a0311e9c843cdeb189c903902de4a2179b 100644 (file)
@@ -55,6 +55,12 @@ class GameUnsolvableException(Exception):
     Examples
     --------
 
+       >>> from dunshire import *
+       >>> K = IceCream(2)
+       >>> L = [[1,2],[3,4]]
+       >>> e1 = [1, 0.1]
+       >>> e2 = [3, 0.1]
+       >>> G = SymmetricLinearGame(L,K,e1,e2)
        >>> d = {'residual as dual infeasibility certificate': None,
        ...      'y': matrix([1,1]),
        ...      'dual slack': 8.779496368228267e-10,
@@ -72,8 +78,16 @@ class GameUnsolvableException(Exception):
        ...      'gap': None,
        ...      'residual as primal infeasibility certificate':
        ...          3.986246886102996e-09}
-       >>> print(GameUnsolvableException(d))
+       >>> print(GameUnsolvableException(G,d))
        Solution failed with result "primal infeasible."
+       The linear game (L, K, e1, e2) where
+         L = [ 1  2]
+             [ 3  4],
+         K = Lorentz "ice cream" cone in the real 2-space,
+         e1 = [1.0000000]
+              [0.1000000],
+         e2 = [3.0000000]
+              [0.1000000].
        CVXOPT returned:
          dual infeasibility: None
          dual objective: 1.0
@@ -98,11 +112,12 @@ class GameUnsolvableException(Exception):
            [ 0]
            [ 0]
     """
-    def __init__(self, solution_dict):
+    def __init__(self, game, solution_dict):
         """
         Create a new GameUnsolvableException object.
         """
         super().__init__()
+        self._game = game
         self._solution_dict = solution_dict
 
 
@@ -112,14 +127,13 @@ class GameUnsolvableException(Exception):
 
         The returned representation highlights the "status" field of the
         CVXOPT dictionary, since that should explain what went
-        wrong. The full CVXOPT solution dictionary is included after the
-        status.
+        wrong. The game details and full CVXOPT solution dictionary is
+        included after the status.
         """
         tpl = 'Solution failed with result "{:s}."\n' \
+              '{!s}\n' \
               'CVXOPT returned:\n  {!s}'
         cvx_lines = _pretty_format_dict(self._solution_dict).splitlines()
-
         # Indent the whole dict by two spaces.
         cvx_str = '\n  '.join(cvx_lines)
-
-        return tpl.format(self._solution_dict['status'], cvx_str)
+        return tpl.format(self._solution_dict['status'], self._game, cvx_str)