%------------------------------- plot_Fig4.m -----------------------------%
%
% Script to replot experiments with data from the "\DATA" folder
% for each solver. This is used for comparing the best solvers overall,
% corresponding to Figure 4 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 C. Init
% 04/09/21, J.B., Extended plots
% 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 constant initialization)
% 62 problems used. Only the first 2 memory values are used, because
% the final comparison is among two solvers only
ms = [5,14,14,14];
qs = [7,0,0,0];
indAlg = [1 3];
np = 62;
nms = length(ms);
ex = zeros(np,nms);
t_aver = zeros(np,nms);
numit = zeros(np,nms);
nsol = 4;

% Plotting details
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 properties
types.colors    = ['b' 'm' 'm' 'g' 'k' 'c' 'y']; %'k' 'y'
types.lines     = {'-', '-.', '-','-.','-','-.','-'}; %'-',   '-'
leglocation = 'SouthEast';
isLog = 1;

% Experiment Suffix
exSuff = {'VARINIT2_m5_q7','CONS_m14','CONS_m14','CONS_m14'}; % ,'3'

typesp.colors = [];
typesp.lines = {'-',':',':','-.','--'};
typesp.markers =['o' 'o' 'o' 'o' 'o'];
for j=1:nms
    if isempty(strfind(exSuff{j},'CONS'))
        mleg{j} = [leg{j},' (Init. 2, $m=',num2str(ms(j)),', q=',num2str(qs(j)),'$)'];
    else
        mleg{j} = [leg{j},' (C Init., $m=',num2str(ms(j)),'$)'];
    end
    name_EXPERIMENT = ['EXPERIMENT_FINAL_',exSuff{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 by un-commenting the next lines

% perf(ex(:,indAlg),t_aver(:,indAlg),mleg(indAlg),1,typesp,leglocation,isLog);
% box on; grid on;
% title('$\textnormal{Time}$','Interpreter','latex');
% fig                     = gcf;
% fig.PaperPositionMode   = 'auto';
% fig_pos                 = fig.PaperPosition;
% fig.PaperSize           = [fig_pos(3) fig_pos(4)];
% figname = ['time_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);
% box on; grid on;
% title('$\textnormal{Iter}$','Interpreter','latex');
% fig                     = gcf;
% fig.PaperPositionMode   = 'auto';
% fig_pos                 = fig.PaperPosition;
% fig.PaperSize           = [fig_pos(3) fig_pos(4)];
% figname = ['iter_SOLV_ALL_BEST','.pdf'];
% print(fig,'-dpdf',fullfile(figpath,figname));

% Extended perf. profiles
ticks   = -3; % -1
ticke   = 5; % 2
XTick   = 2.^(ticks:ticke);
XLim    = [XTick(1),XTick(end)];
leglocation1 = 'SouthEast';
legFontSize1 = 7;
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}$','Interpreter','latex');

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

figname = ['Fig4','.pdf'];

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

warning('on');
%close ALL;
