From eb940c4312540b7db2f43a8c4067aff6e94928de Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 4 Nov 2016 19:11:23 -0400 Subject: [PATCH] Fix a bug in my two-tolerance strategy and add a test case for it. --- dunshire/games.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/dunshire/games.py b/dunshire/games.py index 1f3a15a..08a6d6f 100644 --- a/dunshire/games.py +++ b/dunshire/games.py @@ -667,24 +667,48 @@ class SymmetricLinearGame: >>> norm(s1.player2_optimal() - s2.player2_optimal()) < ABS_TOL True + This game cannot be solved with the default tolerance, but it + can be solved with a weaker one:: + + >>> from dunshire import * + >>> from dunshire.options import ABS_TOL + >>> L = [[ 0.58538005706658102767, 1.53764301129883040886], + ... [-1.34901059721452210027, 1.50121179114155500756]] + >>> K = NonnegativeOrthant(2) + >>> e1 = [1.04537193228494995623, 1.39699624965841895374] + >>> e2 = [0.35326554172108337593, 0.11795703527854853321] + >>> SLG = SymmetricLinearGame(L,K,e1,e2) + >>> print(SLG._try_solution(ABS_TOL / 10)) + Traceback (most recent call last): + ... + dunshire.errors.GameUnsolvableException: Solution failed... + >>> print(SLG._try_solution(ABS_TOL)) + Game value: 9.1100945 + Player 1 optimal: + [-0.0000000] + [ 8.4776631] + Player 2 optimal: + [0.0000000] + [0.7158216] + """ try: - solvers.options['show_progress'] = options.VERBOSE - solvers.options['abs_tol'] = tolerance + opts = {'show_progress': options.VERBOSE, 'abstol': tolerance} soln_dict = solvers.conelp(self._c(), self._G(), self._h(), self._C().cvxopt_dims(), self._A(), - self._b()) - except ValueError as e: - if str(e) == 'math domain error': + self._b(), + options=opts) + except ValueError as error: + if str(error) == '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 + raise error # The optimal strategies are named ``p`` and ``q`` in the # background documentation, and we need to extract them from -- 2.44.2