]> gitweb.michael.orlitzky.com - dunshire.git/commitdiff
Fix lint warnings and a few variable errors in symmetric_linear_game.py.
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 6 Oct 2016 16:48:48 +0000 (12:48 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 6 Oct 2016 16:48:48 +0000 (12:48 -0400)
symmetric_linear_game.py

index 694e09f6a9f21930ee028d732f96ddda9cdbb553..e92e8200ad93e97d76b61f3453d40649fcdadcc0 100644 (file)
@@ -1,3 +1,10 @@
+"""
+Symmetric linear games and their solutions.
+
+This module contains the main SymmetricLinearGame class that knows how
+to solve a linear game.
+"""
+
 from cvxopt import matrix, printing, solvers
 
 from cones import CartesianProduct
@@ -34,12 +41,12 @@ class Solution:
               'Player 1 optimal:{:s}\n' \
               'Player 2 optimal:{:s}\n'
 
-        p1 = '\n{!s}'.format(self.player1_optimal())
-        p1 = '\n  '.join(p1.splitlines())
-        p2 = '\n{!s}'.format(self.player2_optimal())
-        p2 = '\n  '.join(p2.splitlines())
+        p1_str = '\n{!s}'.format(self.player1_optimal())
+        p1_str = '\n  '.join(p1_str.splitlines())
+        p2_str = '\n{!s}'.format(self.player2_optimal())
+        p2_str = '\n  '.join(p2_str.splitlines())
 
-        return tpl.format(self.game_value(), p1, p2)
+        return tpl.format(self.game_value(), p1_str, p2_str)
 
 
     def game_value(self):
@@ -101,16 +108,15 @@ class SymmetricLinearGame:
             raise ValueError('the point e2 must lie in the interior of K')
 
     def solution(self):
-
-        C = CartesianProduct(K, K)
+        C = CartesianProduct(self._K, self._K)
         b = matrix([1], tc='d')
         # A column of zeros that fits K.
         zero = matrix(0, (self._K.dimension(), 1), tc='d')
         h = matrix([zero, zero])
         c = matrix([-1, zero])
-        G = append_row(append_col(zero, -identity(K.dimension())),
-                      append_col(self._e1, -self._L))
-        A = matrix([0, self._e1], (1, K.dimension() + 1), 'd')
+        G = append_row(append_col(zero, -identity(self._K.dimension())),
+                       append_col(self._e1, -self._L))
+        A = matrix([0, self._e1], (1, self._K.dimension() + 1), 'd')
 
         soln_dict = solvers.conelp(c, G, h, C.cvxopt_dims(), A, b)