Section 5.2.5: Mixed strategies for matrix games

% Boyd & Vandenberghe "Convex Optimization"
% Joëlle Skaf - 08/24/05
%
% Player 1 wishes to choose u to minimize his expected payoff u'Pv, while
% player 2 wishes to choose v to maximize u'Pv, where P is the payoff
% matrix, u and v are the probability distributions of the choices of each
% player (i.e. u>=0, v>=0, sum(u_i)=1, sum(v_i)=1)

% Input data
randn('state',0);
n = 10;
m = 10;
P = randn(n,m);

% Optimal strategy for Player 1
fprintf(1,'Computing the optimal strategy for player 1 ... ');

cvx_begin
    variable u(n)
    minimize ( max ( P'*u) )
    u >= 0;
    ones(1,n)*u == 1;
cvx_end

fprintf(1,'Done! \n');
obj1 = cvx_optval;

% Optimal strategy for Player 2
fprintf(1,'Computing the optimal strategy for player 2 ... ');

cvx_begin
    variable v(m)
    maximize ( min (P*v) )
    v >= 0;
    ones(1,m)*v == 1;
cvx_end

fprintf(1,'Done! \n');
obj2 = cvx_optval;

% Displaying results
disp('------------------------------------------------------------------------');
disp('The optimal strategies for players 1 and 2 are respectively: ');
disp([u v]);
disp('The expected payoffs for player 1 and player 2 respectively are: ');
[obj1 obj2]
disp('They are equal as expected!');
Computing the optimal strategy for player 1 ...  
Calling SeDuMi: 21 variables (1 free), 11 equality constraints
------------------------------------------------------------------------
SeDuMi 1.1 by AdvOL, 2005 and Jos F. Sturm, 1998, 2001-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
Split 1 free variables
eqs m = 11, order n = 23, dim = 23, blocks = 1
nnz(A) = 140 + 0, nnz(ADA) = 121, nnz(L) = 66
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            7.35E+000 0.000
  1 : -3.13E-001 3.18E+000 0.000 0.4325 0.9000 0.9000   2.46  1  1  5.6E+000
  2 : -1.67E-002 1.45E+000 0.000 0.4560 0.9000 0.9000   4.28  1  1  1.2E+000
  3 :  1.13E-002 4.36E-001 0.000 0.3006 0.9000 0.9000   1.54  1  1  3.0E-001
  4 :  2.61E-002 1.16E-001 0.000 0.2652 0.9000 0.9000   1.09  1  1  7.3E-002
  5 :  2.74E-002 2.30E-002 0.000 0.1992 0.9000 0.9000   1.06  1  1  1.5E-002
  6 :  2.77E-002 4.39E-003 0.000 0.1906 0.9000 0.9000   1.01  1  1  2.9E-003
  7 :  2.79E-002 1.24E-005 0.000 0.0028 0.9990 0.9990   1.00  1  1  
iter seconds digits       c*x               b*y
  7      0.1   Inf  2.7855878954e-002  2.7855878954e-002
|Ax-b| =  1.9e-016, [Ay-c]_+ =  1.4E-016, |x|= 9.0e-001, |y|= 5.4e-001

Detailed timing (sec)
   Pre          IPM          Post
1.001E-002    5.007E-002    0.000E+000    
Max-norms: ||b||=1, ||c|| = 1,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 8.83398.
------------------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.0278559
Done! 
Computing the optimal strategy for player 2 ...  
Calling SeDuMi: 21 variables (1 free), 11 equality constraints
------------------------------------------------------------------------
SeDuMi 1.1 by AdvOL, 2005 and Jos F. Sturm, 1998, 2001-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
Split 1 free variables
eqs m = 11, order n = 23, dim = 23, blocks = 1
nnz(A) = 140 + 0, nnz(ADA) = 121, nnz(L) = 66
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            7.35E+000 0.000
  1 : -3.40E-001 3.21E+000 0.000 0.4368 0.9000 0.9000   2.45  1  1  5.7E+000
  2 : -3.22E-002 1.48E+000 0.000 0.4622 0.9000 0.9000   4.31  1  1  1.2E+000
  3 : -2.23E-002 4.55E-001 0.000 0.3066 0.9000 0.9000   1.55  1  1  3.2E-001
  4 : -2.93E-002 1.22E-001 0.000 0.2688 0.9000 0.9000   1.09  1  1  7.8E-002
  5 : -2.82E-002 2.40E-002 0.000 0.1962 0.9000 0.9000   1.06  1  1  1.6E-002
  6 : -2.79E-002 4.59E-003 0.000 0.1912 0.9000 0.9000   1.02  1  1  3.0E-003
  7 : -2.79E-002 3.05E-005 0.000 0.0066 0.9990 0.9820   1.00  1  1  
iter seconds digits       c*x               b*y
  7      0.1  14.6 -2.7855878954e-002 -2.7855878954e-002
|Ax-b| =  2.9e-016, [Ay-c]_+ =  1.4E-016, |x|= 1.1e+000, |y|= 4.4e-001

Detailed timing (sec)
   Pre          IPM          Post
0.000E+000    6.009E-002    1.001E-002    
Max-norms: ||b||=1, ||c|| = 1,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 2.54059.
------------------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.0278559
Done! 
------------------------------------------------------------------------
The optimal strategies for players 1 and 2 are respectively: 
    0.1804         0
         0    0.3254
         0    0.0924
    0.1549         0
    0.1129         0
         0    0.0264
         0    0.4099
    0.1003    0.0509
    0.1474    0.0949
    0.3040         0

The expected payoffs for player 1 and player 2 respectively are: 

ans =

    0.0279    0.0279

They are equal as expected!