]>
gitweb.michael.orlitzky.com - dunshire.git/blob - src/dunshire/errors.py
bb52cac66b194b67aedc5d1f8fc95514fd040cb8
2 Errors that can occur when solving a linear game.
5 from cvxopt
import matrix
8 def _pretty_print_dict(dictionary
):
10 Return a pretty-printed string representation of a dictionary
11 containing CVXOPT matrices.
14 for (key
, value
) in dictionary
.items():
15 if isinstance(value
, matrix
):
16 # Display matrices on their own lines, indented.
17 result
+= ' {:s}:'.format(key
)
18 colvec
= '\n{!s}'.format(value
)
19 result
+= '\n '.join(colvec
.splitlines())
22 result
+= ' {:s}: {!s}\n'.format(key
, value
)
27 class GameUnsolvableException(Exception):
29 Every linear game has a solution (this follows from a general
30 min-max theorem). If we can't solve the conic program associated
31 with a linear game, then something is wrong with either the model of
34 def __init__(self
, solution_dict
):
36 Create a new GameUnsolvableException object.
40 - ``solution_dict`` -- the solution dictionary returned from the
45 self
._solution
_dict
= solution_dict
49 tpl
= 'Solution failed with result "{:s}."\n' \
50 'CVXOPT returned:\n{!s}'
51 return tpl
.format(self
._solution
_dict
['status'],
52 _pretty_print_dict(self
._solution
_dict
))