]>
gitweb.michael.orlitzky.com - dunshire.git/blob - errors.py
2 Errors that can occur when solving a linear game.
5 from cvxopt
import matrix
7 class GameException(Exception):
9 The base class for all exceptions that can occur during the solution
12 def pretty_print_dict(self
, solution_dict
):
14 Return a pretty-printed string representation of a CVXOPT
18 for (k
,v
) in solution_dict
.items():
19 if isinstance(v
, matrix
):
20 # Try to display vectors as rows on one line.
21 result
+= ' {:s}: {!s}'.format(k
,v
.trans())
23 result
+= ' {:s}: {!s}\n'.format(k
,v
)
28 class GameUnsolvableException(GameException
):
30 Every linear game has a solution (this follows from a general
31 min-max theorem). If we can't solve the conic program associated
32 with a linear game, then something is wrong with either the model of
35 def __init__(self
, status
, solution
, solution_dict
):
37 Create a new GameUnsolvableException object.
41 - ``status`` -- the failure status code returned by CVXOPT.
43 - ``solution`` -- a Solution object.
45 - ``solution_dict`` -- the solution dictionary returned from the
49 tpl
= 'Solution failed with error "{:s}".\n' \
51 'CVXOPT returned:\n{!s}'
52 # TODO: dont convert the solution to a string, we need
53 # to output the two values as well.
54 self
.message
= tpl
.format(status
,
56 self
.pretty_print_dict(solution_dict
))