]>
gitweb.michael.orlitzky.com - dunshire.git/blob - symmetric_linear_game.py
29f64ad3339e4b7fe16f49b328fc2b0ed2969925
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 self
._e
1 = matrix(e1
, (K
.dimension(), 1))
47 self
._e
2 = matrix(e2
, (K
.dimension(), 1))
49 if not K
.contains_strict(self
._e
1):
50 raise ValueError('the point e1 must lie in the interior of K')
51 if not K
.contains_strict(self
._e
2):
52 raise ValueError('the point e2 must lie in the interior of K')
54 self
._L = matrix(L
, (K
.dimension(), K
.dimension()))
55 self
._b
= matrix([1], tc
='d')
56 # A column of zeros that fits K.
57 zero
= matrix(0, (K
.dimension(), 1), tc
='d')
58 self
._h
= matrix([zero
, zero
])
59 self
._c
= matrix([-1, zero
])
60 self
._G
= append_row(append_col(zero
, -identity(K
.dimension())),
61 append_col(self
._e
1, -self
._L))
62 self
._A
= matrix([0, self
._e
1], (1, K
.dimension() + 1), 'd')
65 soln
= solvers
.conelp(self
._c
,
68 self
._C
.cvxopt_dims(),
74 soln
= self
.solution()
76 print('Value of the game (player one): {:f}'.format(soln
['x'][0]))
77 print('Optimal strategy (player one):')
80 print('Value of the game (player two): {:f}'.format(soln
['y'][0]))
81 print('Optimal strategy (player two):')
82 print(soln
['z'][self
._K
.dimension():])