From 7859f3008f4f1b32f03b3f763c4df689175e2eb1 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 5 Oct 2016 17:24:41 -0400 Subject: [PATCH] Add the errors module, in a non-working state. --- errors.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 errors.py diff --git a/errors.py b/errors.py new file mode 100644 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) -- 2.44.2