%-------------------------------- plot_Fig3.m ----------------------------%
%
% Script to replot experiments with data from the "\DATA" folder
% for each solver. This is used for comparing the best solvers,
% with non-constant initializations, and corresponds to Figure 3 in the
% manuscript
%
%-------------------------------------------------------------------------%
% 03/03/21, J.B., Initial version
% 03/05/21, J.B.,
% 03/08/21, J.B., Plot memory outcomes per solver
% 03/10/21, J.B., Plots with low memory values
% 04/06/21, J.B., Preparation of plots with 4 different "m" values
% 04/08/21, J.B., Comparison Init. 2
% 04/23/21, J.B., Re-naming of file and preparation for release
% 01/28/22, J.B., Updating of figure names after revision
% 06/20/22, J.B., Toggle warning and keep figures on

clc;
clear;

addpath(genpath('../ALGS'));
figpath = fullfile(pwd,'..','/FIGS/');
datapath = fullfile(pwd,'..','/DATA/');

warning('off');

% Memory values from experiments (with non-constant initialization)
% 62 problems used
ms = [5,5,5,5];
qs = [7,7,7,5];
indAlg = [1 2 3 4];
np = 62;
nms = length(ms);
ex = zeros(np,nms);
t_aver = zeros(np,nms);
numit = zeros(np,nms);
nsol = 4;

% Plotting labels, and additional parameters
leg={   'TR:SC-INF',...
    'TR:SC-L2',...
    'TR:L2',...
    'trCG'};

mleg = cell(nms);
types.markers   = ['o' 'o' 'o' 'o' 'o' 'o' 'o']; %'s' 's'

% Initial line types
types.colors    = ['b' 'r' 'm' 'g' 'k' 'c' 'y']; %'k' 'y'
types.lines     = {'-', '-.', '-','-.','-','-.','-'}; %'-',   '-'

leglocation = 'SouthEast';
isLog = 1;
legFontSize = 8;
scaleMaxRatio = 4.0;
typesp.colors = [];
typesp.lines = {'-','-','-','-','--'};
typesp.markers =['o' 'o' 'o' 'o' 'o'];

for j=1:nms
    mleg{j} = [leg{j},' ($m=',num2str(ms(j)),', q=',num2str(qs(j)),'$)'];    
    name_EXPERIMENT = ['EXPERIMENT_FINAL_VARINIT2_',...
        'm',num2str(ms(j)),'_','q',num2str(qs(j))];    
    data = load([datapath,name_EXPERIMENT],'ex','numit','t_aver');
    ex(:,j) = data.ex(:,j);
    numit(:,j) = data.numit(:,j);
    t_aver(:,j) = data.t_aver(:,j);
    typesp.colors = [typesp.colors,types.colors(j)];
end

% Additional plots possible, by un-commenting the next lines

% perf(ex(:,indAlg),t_aver(:,indAlg),mleg(indAlg),1,typesp,...
%     leglocation,isLog,legFontSize,scaleMaxRatio);
% box on; grid on;
% title('$\textnormal{Time (Init. 2)}$','Interpreter','latex');
% fig                     = gcf;
% fig.PaperPositionMode   = 'auto';
% fig_pos                 = fig.PaperPosition;
% fig.PaperSize           = [fig_pos(3) fig_pos(4)];
% 
% figname = ['time_I_SOLV_ALL_BEST','.pdf']; %'time_EX_CUTEST_INIT_1';
% print(fig,'-dpdf',fullfile(figpath,figname));
% 
% perf(ex(:,indAlg),numit(:,indAlg),mleg(indAlg),1,typesp,leglocation,isLog,...
%     legFontSize,scaleMaxRatio);
% box on; grid on;
% title('$\textnormal{Iter (Init. 2)}$','Interpreter','latex');
% fig                     = gcf;
% fig.PaperPositionMode   = 'auto';
% fig_pos                 = fig.PaperPosition;
% fig.PaperSize           = [fig_pos(3) fig_pos(4)];
% 
% figname = ['iter_I_SOLV_ALL_BEST','.pdf'];
% print(fig,'-dpdf',fullfile(figpath,figname));

% Extended performance profiles 
ticks   = -2; % -1
ticke   = 5; % 2
XTick   = 2.^(ticks:ticke);
XLim    = [XTick(1),XTick(end)];
leglocation1 = 'SouthEast';
legFontSize1 = 7.5;
markerSize = 0;
lineWidths = [1.8, 1.6, 1.4, 1.2];

typesp.markers =['o' 'o' 'd' 'h' 'o'];

perf_ext_fnc(ex(:,indAlg),t_aver(:,indAlg),mleg(indAlg),1,typesp,...
    leglocation1,XTick,XLim,legFontSize1,markerSize,lineWidths);

% On first plot "grid on" does not produce desired result,
% thus toggle once more
grid on; grid off;
grid on;
title('$\textnormal{Time (Init. 2)}$','Interpreter','latex');

% Modified printing
fig                     = gcf;
fig.PaperPositionMode   = 'auto';
fig_pos                 = fig.PaperPosition;
fig.PaperSize           = [fig_pos(3) fig_pos(4)];

figname = ['Fig3','.pdf']; %'time_EX_CUTEST_INIT_1';

print(fig,'-dpdf',fullfile(figpath,figname));

%close ALL;
warning('on');
