X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=dunshire%2Fgames.py;h=9610802e4ffd4108d2c244b2c36a9e44084427cd;hb=edb2575f68414f97408d876368172d1862cedc5e;hp=80f5f8ae2a46d09f15e34546c511edeca286f4fa;hpb=d5b8c807fe3ce495dbf8c76ac718a7d99a273111;p=dunshire.git diff --git a/dunshire/games.py b/dunshire/games.py index 80f5f8a..9610802 100644 --- a/dunshire/games.py +++ b/dunshire/games.py @@ -7,7 +7,7 @@ knows how to solve a linear game. from cvxopt import matrix, printing, solvers from .cones import CartesianProduct -from .errors import GameUnsolvableException +from .errors import GameUnsolvableException, PoorScalingException from .matrices import append_col, append_row, identity from . import options @@ -351,6 +351,10 @@ class SymmetricLinearGame: If the game could not be solved (if an optimal solution to its associated cone program was not found). + PoorScalingException + If the game could not be solved because CVXOPT crashed while + trying to take the square root of a negative number. + Examples -------- @@ -425,7 +429,16 @@ class SymmetricLinearGame: # Actually solve the thing and obtain a dictionary describing # what happened. - soln_dict = solvers.conelp(c, G, h, C.cvxopt_dims(), A, b) + try: + soln_dict = solvers.conelp(c, G, h, C.cvxopt_dims(), A, b) + except ValueError as e: + if str(e) == 'math domain error': + # Oops, CVXOPT tried to take the square root of a + # negative number. Report some details about the game + # rather than just the underlying CVXOPT crash. + raise PoorScalingException(self) + else: + raise e # The optimal strategies are named ``p`` and ``q`` in the # background documentation, and we need to extract them from