]> gitweb.michael.orlitzky.com - dunshire.git/commitdiff
Start to clean up pylint warnings in symmetric_linear_game.py.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 5 Oct 2016 17:38:01 +0000 (13:38 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 5 Oct 2016 17:38:01 +0000 (13:38 -0400)
symmetric_linear_game.py

index a8cdabc71dac1f39d5578df00bab13e157de0104..29f64ad3339e4b7fe16f49b328fc2b0ed2969925 100644 (file)
@@ -41,18 +41,25 @@ class SymmetricLinearGame:
                       as a column vector.
 
         """
-        self._K  = K
+        self._K = K
         self._C = CartesianProduct(K, K)
-        n = self._K.dimension()
-        self._L  = matrix(L,  (n,n))
-        self._e1 = matrix(e1, (n,1)) # TODO: check that e1 and e2
-        self._e2 = matrix(e2, (n,1)) # are in the interior of K...
-        self._h  = matrix(0,  (2*n,1), 'd')
-        self._b = matrix(1,   (1,1), 'd')
-        self._c = matrix([-1] + [0]*n, (n+1,1), 'd')
-        self._G = append_row(append_col(matrix(0,(n,1)), -identity(n)),
+        self._e1 = matrix(e1, (K.dimension(), 1))
+        self._e2 = matrix(e2, (K.dimension(), 1))
+
+        if not K.contains_strict(self._e1):
+            raise ValueError('the point e1 must lie in the interior of K')
+        if not K.contains_strict(self._e2):
+            raise ValueError('the point e2 must lie in the interior of K')
+
+        self._L = matrix(L, (K.dimension(), K.dimension()))
+        self._b = matrix([1], tc='d')
+        # A column of zeros that fits K.
+        zero = matrix(0, (K.dimension(), 1), tc='d')
+        self._h = matrix([zero, zero])
+        self._c = matrix([-1, zero])
+        self._G = append_row(append_col(zero, -identity(K.dimension())),
                              append_col(self._e1, -self._L))
-        self._A = matrix([0] + e1, (1, n+1), 'd')
+        self._A = matrix([0, self._e1], (1, K.dimension() + 1), 'd')
 
     def solution(self):
         soln = solvers.conelp(self._c,
@@ -65,16 +72,11 @@ class SymmetricLinearGame:
 
     def solve(self):
         soln = self.solution()
-        nu = soln['x'][0]
-        print('Value of the game (player one): {:f}'.format(nu))
 
-        opt1 = soln['x'][1:]
+        print('Value of the game (player one): {:f}'.format(soln['x'][0]))
         print('Optimal strategy (player one):')
-        print(opt1)
+        print(soln['x'][1:])
 
-        omega = soln['y'][0]
-        n = self._K.dimension()
-        opt2 = soln['z'][n:]
-        print('Value of the game (player two): {:f}'.format(omega))
+        print('Value of the game (player two): {:f}'.format(soln['y'][0]))
         print('Optimal strategy (player two):')
-        print(opt2)
+        print(soln['z'][self._K.dimension():])