]>
gitweb.michael.orlitzky.com - dunshire.git/blob - symmetric_linear_game.py
a8cdabc71dac1f39d5578df00bab13e157de0104
1 from cvxopt
import matrix
, printing
, solvers
3 from cones
import CartesianProduct
4 from matrices
import append_col
, append_row
, identity
6 printing
.options
['dformat'] = '%.7f'
7 solvers
.options
['show_progress'] = False
9 class SymmetricLinearGame
:
11 A representation of a symmetric linear game.
13 The data for a linear game are,
15 * A "payoff" operator ``L``.
17 * A point ``e`` in the interior of ``K``.
18 * A point ``f`` in the interior of the dual of ``K``.
20 In a symmetric game, the cone ``K`` is be self-dual. We therefore
21 name the two interior points ``e1`` and ``e2`` to indicate that
22 they come from the same cone but are "chosen" by players one and
25 The ambient space is assumed to be the span of ``K``.
28 def __init__(self
, L
, K
, e1
, e2
):
32 - ``L`` -- an n-by-b matrix represented as a list of lists
35 - ``K`` -- a SymmetricCone instance.
37 - ``e1`` -- the interior point of ``K`` belonging to player one,
40 - ``e2`` -- the interior point of ``K`` belonging to player two,
45 self
._C
= CartesianProduct(K
, K
)
46 n
= self
._K
.dimension()
47 self
._L = matrix(L
, (n
,n
))
48 self
._e
1 = matrix(e1
, (n
,1)) # TODO: check that e1 and e2
49 self
._e
2 = matrix(e2
, (n
,1)) # are in the interior of K...
50 self
._h
= matrix(0, (2*n
,1), 'd')
51 self
._b
= matrix(1, (1,1), 'd')
52 self
._c
= matrix([-1] + [0]*n
, (n
+1,1), 'd')
53 self
._G
= append_row(append_col(matrix(0,(n
,1)), -identity(n
)),
54 append_col(self
._e
1, -self
._L))
55 self
._A
= matrix([0] + e1
, (1, n
+1), 'd')
58 soln
= solvers
.conelp(self
._c
,
61 self
._C
.cvxopt_dims(),
67 soln
= self
.solution()
69 print('Value of the game (player one): {:f}'.format(nu
))
72 print('Optimal strategy (player one):')
76 n
= self
._K
.dimension()
78 print('Value of the game (player two): {:f}'.format(omega
))
79 print('Optimal strategy (player two):')