function CLQRAlgorithm
%
% M. Herceg, ETH Zurich, 2014
%
% requires MPT3

close all

%% printing parameters
label_font_size = 14;
tick_font_size = 10;
line_width = 0.8;
axeswidth=0.2;
% create new folder for storing figures
mkdir('figures');
figure_name = ['.',filesep,'figures',filesep,'xploration'];


%% core code
% polytopes
P1 = Polyhedron([-3.048, 2.019; -1.107, 0.03852; 1.107,-0.03852; 3.048, -2.019]);
P2 = Polyhedron([-5, 2.986; -5, 5; 5, 5; 5, -1.967]);
P3 = Polyhedron([-3.048, 2.019; 0.1451, 0.9615; 4.067, -1.019; 1.107, -0.03852]);


% case1
fig1 = figure;
P1.plot('color',[0.6 0.6 0.6],'linewidth',line_width);
axis([-3 3 -3 3]);

set(gca,'LineWidth',axeswidth)
set(gca,'FontSize', tick_font_size);
hx1 = xlabel('$x_1$');
set(hx1, 'FontSize', label_font_size);
hy1 = ylabel('$x_2$');
set(hy1, 'FontSize', label_font_size);

ha=arrow([0.2 0.3],[0.6 1]);
set(ha,'linewidth',line_width);
%arrow([-1.5 -1.5],[-0.4 0.2])

ht0 = text(-0.5,1.3,'Step $\eps$ over facet');
set(ht0,'FontSize',label_font_size);

ht1 = text(-0.4,-0.2,'$\mathcal{O}_{\infty}^{\text{LQR}}$');
set(ht1,'FontSize',label_font_size);

disp('Hit any key to continue.');
pause

% case2
fig2 = figure;
P1.plot('color',[0.6 0.6 0.6],'linewidth',line_width);
hold on
P2.plot('color',[0.9 0.9 0.9],'linewidth',line_width);
axis([-3 3 -3 3]);


set(gca,'LineWidth',axeswidth)
set(gca,'FontSize', tick_font_size);
hx1 = xlabel('$x_1$');
set(hx1, 'FontSize', label_font_size);
hy1 = ylabel('$x_2$');
set(hy1, 'FontSize', label_font_size);

ht2 = text(-0.4,-0.2,'$\mathcal{O}_{\infty}^{\text{LQR}}$');
set(ht2,'FontSize',label_font_size);
ht3 = text(0.5,1.5,'$\mathcal{P}_{1}$');
set(ht3,'FontSize',label_font_size);


disp('Hit any key to continue.');
pause


% case3
fig3 = figure;
P1.plot('color',[0.6 0.6 0.6],'linewidth',line_width);
hold on
P3.plot('color',[0.9 0.9 0.9],'linewidth',line_width);
axis([-3 3 -3 3]);


set(gca,'LineWidth',axeswidth)
set(gca,'FontSize', tick_font_size);
hx1 = xlabel('$x_1$');
set(hx1, 'FontSize', label_font_size);
hy1 = ylabel('$x_2$');
set(hy1, 'FontSize', label_font_size);

ht4 = text(-0.4,-0.2,'$\mathcal{O}_{\infty}^{\text{LQR}}$');
set(ht4,'FontSize',label_font_size);
ht5 = text(-1,1.7,'Reachability subset $\mathcal{ITP}_{1}^{1}$');
set(ht5,'FontSize',label_font_size);

ha=arrow([0.8 1.4],[0.25 0.55]);
set(ha,'linewidth',line_width);



%% save book figures
% generate FIG file
saveas(fig1, [figure_name,'1_new_matlab'], 'fig');

% print 
laprint(fig1, [figure_name,'1_new_tex'],'scalefonts','off');

% generate FIG file
saveas(fig2, [figure_name,'2_new_matlab'], 'fig');

% print 
laprint(fig2, [figure_name,'2_new_tex'],'scalefonts','off');

% generate FIG file
saveas(fig3, [figure_name,'3_new_matlab'], 'fig');

% print 
laprint(fig3, [figure_name,'3_new_tex'],'scalefonts','off');


end