]> gitweb.michael.orlitzky.com - dunshire.git/commitdiff
Add the errors module, in a non-working state.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 5 Oct 2016 21:24:41 +0000 (17:24 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 5 Oct 2016 21:24:41 +0000 (17:24 -0400)
errors.py [new file with mode: 0644]

diff --git a/errors.py b/errors.py
new file mode 100644 (file)
index 0000000..cc3b57e
--- /dev/null
+++ b/errors.py
@@ -0,0 +1,56 @@
+"""
+Errors that can occur when solving a linear game.
+"""
+
+class GameUnsolvableException(Exception):
+    """
+    Every linear game has a solution (this follows from a general
+    min-max theorem). If we can't solve the conic program associated
+    with a linear game, then something is wrong with either the model of
+    the input.
+    """
+    def __init__(self, solution_dict):
+        """
+        Create a new GameUnsolvableException object.
+
+        INPUT:
+
+        - ``primal`` -- the objective value of the primal cone program.
+
+        - ``dual`` -- the objective value of the dual cone program.
+
+        - ``solution_dict`` -- the solution dictionary returned from the cone program.
+
+        """
+        tpl = 'solution failed with error: {:s}\n' \
+              'CVXOPT returned:\n{!s}'
+        self.message = tpl.format(solution_dict['status'], solution_dict)
+
+
+class GameValueMismatchException(Exception):
+    """
+    This error occurs when the primal and dual objective value of the
+    conic program associated with a linear game do not agree. By
+    construction, every conic program derived from a linear game must
+    have a solution and the same objective value (the "value of the
+    game") is shared by both players.
+
+    Each instance of this class will know the two mismatched values, and
+    its ``message`` field will explain why they can't be so.
+    """
+    def __init__(self, primal, dual, solution_dict):
+        """
+        Create a new GameValueMismatchException.
+
+        INPUT:
+
+        - ``primal`` -- the objective value of the primal cone program.
+
+        - ``dual`` -- the objective value of the dual cone program.
+
+        - ``solution_dict`` -- the solution dictionary returned from the cone program.
+
+        """
+        tpl = 'game value mismatch for player1={:.7f}, player2={:.7f}\n' \
+              'CVXOPT returned:\n{!s}'
+        self.message = tpl.format(primal, dual, solution_dict)