Section 4.6.3: Find the fastest mixing Markov chain on a graph

% Boyd & Vandenberghe "Convex Optimization"
% Joëlle Skaf - 09/26/05
%
% The 'fastest mixing Markov chain problem' is to find a transition
% probability matrix P on a graph E that minimizes the mixing rate r, where
% r = max{ lambda_2, -lambda_n } with lambda_1>=...>=lambda_n being the
% eigenvalues of P.

% Generate input data
n = 5;
E = [0 1 0 1 1; ...
     1 0 1 0 1; ...
     0 1 0 1 1; ...
     1 0 1 0 1; ...
     1 1 1 1 0];

% Create and solve model
cvx_begin
    variable P(n,n) symmetric
    minimize(norm(P - (1/n)*ones(n)))
    P*ones(n,1) == ones(n,1);
    P >= 0;
    P(E==0) == 0;
cvx_end
e = flipud(eig(P));
r = max(e(2), -e(n));

% Display results
disp('------------------------------------------------------------------------');
disp('The transition probability matrix of the optimal Markov chain is: ');
disp(P);
disp('The optimal mixing rate is: ');
disp(r);
 
Calling sedumi: 68 variables, 9 equality constraints
   For improved efficiency, sedumi is solving the dual problem.
------------------------------------------------------------
SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 9, order n = 21, dim = 115, blocks = 3
nnz(A) = 50 + 0, nnz(ADA) = 81, nnz(L) = 45
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            1.32E+01 0.000
  1 :  -4.78E-01 4.45E+00 0.000 0.3379 0.9000 0.9000   2.21  1  1  5.0E+00
  2 :  -6.85E-01 1.30E+00 0.000 0.2921 0.9000 0.9000   1.34  1  1  1.3E+00
  3 :  -7.51E-01 3.93E-02 0.000 0.0302 0.9900 0.9900   1.13  1  1  3.5E-02
  4 :  -7.50E-01 1.28E-06 0.000 0.0000 1.0000 1.0000   1.01  1  1  1.1E-06
  5 :  -7.50E-01 1.31E-13 0.000 0.0000 1.0000 1.0000   1.00  1  1  1.2E-13

iter seconds digits       c*x               b*y
  5      0.0  13.5 -7.5000000000e-01 -7.5000000000e-01
|Ax-b| =   9.0e-14, [Ay-c]_+ =   2.8E-15, |x|=  1.9e+00, |y|=  8.3e-01

Detailed timing (sec)
   Pre          IPM          Post
1.000E-02    2.000E-02    0.000E+00    
Max-norms: ||b||=1, ||c|| = 4.000000e-01,
Cholesky |add|=0, |skip| = 1, ||L.L|| = 1.
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.75
------------------------------------------------------------------------
The transition probability matrix of the optimal Markov chain is: 
         0    0.3750         0    0.3750    0.2500
    0.3750         0    0.3750         0    0.2500
         0    0.3750         0    0.3750    0.2500
    0.3750         0    0.3750         0    0.2500
    0.2500    0.2500    0.2500    0.2500         0

The optimal mixing rate is: 
    0.7500