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: 70 variables (0 free), 66 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
eqs m = 66, order n = 26, dim = 116, blocks = 2
nnz(A) = 120 + 0, nnz(ADA) = 4114, nnz(L) = 2090
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            2.25E+000 0.000
  1 :  6.09E-002 8.00E-001 0.000 0.3558 0.9000 0.9000   2.48  1  1  2.0E+000
  2 :  6.58E-001 1.83E-001 0.000 0.2286 0.9000 0.9000   1.55  1  1  3.7E-001
  3 :  7.50E-001 1.49E-003 0.000 0.0081 0.9990 0.9990   1.19  1  1  2.7E-003
  4 :  7.50E-001 1.22E-009 0.000 0.0000 1.0000 1.0000   1.00  1  1  1.9E-009

iter seconds digits       c*x               b*y
  4      0.0   9.5  7.4999999999e-001  7.4999999978e-001
|Ax-b| =  3.3e-009, [Ay-c]_+ =  3.3E-010, |x|= 2.8e+000, |y|= 4.1e+000

Detailed timing (sec)
   Pre          IPM          Post
1.001E-002    4.006E-002    0.000E+000    
Max-norms: ||b||=8.000000e-001, ||c|| = 1,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 1.50211.
------------------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.75
------------------------------------------------------------------------
The transition probability matrix of the optimal Markov chain is: 
    0.0000    0.3750    0.0000    0.3750    0.2500
    0.3750    0.0000    0.3750    0.0000    0.2500
    0.0000    0.3750    0.0000    0.3750    0.2500
    0.3750    0.0000    0.3750    0.0000    0.2500
    0.2500    0.2500    0.2500    0.2500    0.0000

The optimal mixing rate is: 
    0.7500