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 SDPT3: 68 variables, 9 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints =  9
 dim. of sdp    var  = 10,   num. of sdp  blk  =  1
 dim. of linear var  =  8
 dim. of free   var  =  5 *** convert ublk to lblk
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
   HKM      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      mean(obj)   cputime
-------------------------------------------------------------------
 0|0.000|0.000|2.5e+01|1.0e+01|3.0e+03|-6.622169e-10| 0:0:00| chol  1  1 
 1|0.921|0.963|2.0e+00|4.5e-01|6.4e+01| 2.781077e+00| 0:0:00| chol  1  1 
 2|1.000|0.957|7.0e-07|2.8e-02|5.2e+00|-3.520294e-01| 0:0:00| chol  1  1 
 3|1.000|0.717|7.3e-07|8.7e-03|1.1e+00|-5.103355e-01| 0:0:00| chol  1  1 
 4|0.965|0.369|1.0e-07|5.5e-03|4.6e-01|-7.432146e-01| 0:0:00| chol  1  1 
 5|0.990|0.944|3.9e-08|3.2e-04|1.9e-02|-7.491908e-01| 0:0:00| chol  1  1 
 6|0.988|0.988|1.7e-09|4.9e-06|2.3e-04|-7.499892e-01| 0:0:00| chol  1  1 
 7|0.989|0.989|2.8e-10|3.0e-06|7.8e-06|-7.499999e-01| 0:0:00| chol  1  1 
 8|1.000|0.989|2.2e-12|9.9e-08|2.4e-07|-7.500000e-01| 0:0:00| chol  1  2 
 9|1.000|0.989|7.7e-13|3.1e-09|7.4e-09|-7.500000e-01| 0:0:00|
  stop: max(relative gap, infeasibilities) < 1.49e-08
-------------------------------------------------------------------
 number of iterations   =  9
 primal objective value = -7.49999998e-01
 dual   objective value = -7.50000000e-01
 gap := trace(XZ)       = 7.36e-09
 relative gap           = 2.95e-09
 actual relative gap    = 7.57e-10
 rel. primal infeas     = 7.73e-13
 rel. dual   infeas     = 3.09e-09
 norm(X), norm(y), norm(Z) = 1.1e+00, 1.2e+00, 2.8e+00
 norm(A), norm(b), norm(C) = 1.0e+01, 2.0e+00, 4.5e+00
 Total CPU time (secs)  = 0.3  
 CPU time per iteration = 0.0  
 termination code       =  0
 DIMACS: 7.7e-13  0.0e+00  6.9e-09  0.0e+00  7.6e-10  2.9e-09
-------------------------------------------------------------------
------------------------------------------------------------
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