X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=errors.py;fp=errors.py;h=0000000000000000000000000000000000000000;hb=56ea961887d507114174af5f92b8c3c77b0b7a50;hp=bb52cac66b194b67aedc5d1f8fc95514fd040cb8;hpb=23a78f1c16aa4654b74a1908a091661fc6d551a2;p=dunshire.git diff --git a/errors.py b/errors.py deleted file mode 100644 index bb52cac..0000000 --- a/errors.py +++ /dev/null @@ -1,52 +0,0 @@ -""" -Errors that can occur when solving a linear game. -""" - -from cvxopt import matrix - - -def _pretty_print_dict(dictionary): - """ - Return a pretty-printed string representation of a dictionary - containing CVXOPT matrices. - """ - result = '' - for (key, value) in dictionary.items(): - if isinstance(value, matrix): - # Display matrices on their own lines, indented. - result += ' {:s}:'.format(key) - colvec = '\n{!s}'.format(value) - result += '\n '.join(colvec.splitlines()) - result += '\n' - else: - result += ' {:s}: {!s}\n'.format(key, value) - - return result - - -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: - - - ``solution_dict`` -- the solution dictionary returned from the - cone program. - - """ - super().__init__() - self._solution_dict = solution_dict - - - def __str__(self): - tpl = 'Solution failed with result "{:s}."\n' \ - 'CVXOPT returned:\n{!s}' - return tpl.format(self._solution_dict['status'], - _pretty_print_dict(self._solution_dict))