%% Define the LP
% minimize    -x1 - 2*x2
% subject to  -2*x1 + x2 <= 2
%             -x1 + 2*x2 <= 7
%              x1        <= 3
%              x1, x2 >= 0
%
% Except, we need this in standard form:
% minimize f'*x subject to. A*x <= b

c = [-1 -2];
A = [-2 1; -1 2; 1 0];
b = [2; 7; 3];
lb = [0; 0];
ub = []; % No upper bound

%% Plot the LP polytope
clf; 
plotregion(-A,-b,lb,ub); 

%% Convert the LP into standard form
cs = [-1 -2 0 0 0]';
AS = [A eye(3)];

%% Setup CVX
addpath('~/Dropbox/matlab-extern/cvx/');
cvx_setup

%% Use CVX to plot the central path
clf; 
n = length(cs);
plotregion(-A,-b,lb,ub); 
box off; hold on;
taus = logspace(1,-7);
for tau=taus
    cvx_begin
      variable x(n);
      minimize ( sum(x.*cs) - tau*sum(log(x)));
      AS*x == b;
      0 <= x;
    cvx_end
    plot(x(1), x(2), '.','MarkerSize',24);
    drawnow;
end
hold off;