X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=errors.py;fp=errors.py;h=cc3b57ebc10faefe2a17158ec4ab2743eccc130e;hb=7859f3008f4f1b32f03b3f763c4df689175e2eb1;hp=0000000000000000000000000000000000000000;hpb=dcfe79aa1411f58cda36fff3114986dd77a0c0c3;p=dunshire.git 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)