]>
gitweb.michael.orlitzky.com - dunshire.git/blob - symmetric_linear_game.py
1 from cvxopt
import matrix
, printing
, solvers
3 from cones
import CartesianProduct
, NonnegativeOrthant
4 from matrices
import append_cols
, append_row
, identity
6 class SymmetricLinearGame
:
8 A representation of a symmetric linear game.
10 The data for a linear game are,
12 * A "payoff" operator ``L``.
14 * A point ``e`` in the interior of ``K``.
15 * A point ``f`` in the interior of the dual of ``K``.
17 In a symmetric game, the cone ``K`` is be self-dual. We therefore
18 name the two interior points ``e1`` and ``e2`` to indicate that
19 they come from the same cone but are "chosen" by players one and
22 The ambient space is assumed to be the span of ``K``.
25 def __init__(self
, L
, K
, e1
, e2
):
29 - ``L`` -- an n-by-b matrix represented as a list of lists
32 - ``K`` -- a SymmetricCone instance.
34 - ``e1`` -- the interior point of ``K`` belonging to player one,
37 - ``e2`` -- the interior point of ``K`` belonging to player two,
42 self
._C
= CartesianProduct(NonnegativeOrthant(2), K
, K
)
43 n
= self
._K
.dimension()
44 self
._L = matrix(L
, (n
,n
))
45 self
._e
1 = matrix(e1
, (n
,1)) # TODO: check that e1 and e2
46 self
._e
2 = matrix(e2
, (n
,1)) # are in the interior of K...
47 self
._h
= matrix(0, (self
._C
.dimension(),1), 'd')
48 self
._b
= matrix(1, (1,1), 'd')
49 self
._c
= matrix([-1,1] + ([0]*n
), (n
+2,1), 'd')
50 self
._G
= append_row(-identity(n
+2),
51 append_cols([self
._e
1, -self
._e
1, -self
._L]))
52 self
._A
= matrix([0,0] + e1
, (1, n
+2), 'd')
82 solvers
.options
['show_progress'] = False
83 soln
= solvers
.conelp(self
.c(),
86 self
.C().cvxopt_dims(),
90 printing
.options
['dformat'] = '%.7f'
91 value
= soln
['x'][0] - soln
['x'][1]
92 print('Value of the game: {:f}'.format(value
))
95 print('Optimal strategy (player one):')
99 #print('Optimal strategy (player two):')