%-------------------------- plot_Fig6.m ----------------------------------%
%
% Script to replot experiments with data from the "\DATA" folder
% for each solver. This is used for comparing the "C. Init" solvers, in
% order to identify for each one the best default parameters.
%
%-------------------------------------------------------------------------%
% 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/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
ms = [5,7,14,24];
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 details
leg={   'TR:SC-INF (C Init.)',...
    'TR:SC-L2 (C Init.)',...
    'TR:L2 (C Init.)',...
    'trCG (C Init.)'};

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

% Initial properties
types.colors    = ['b' 'r' 'm' 'g' 'k' 'c' 'y']; %'k' 'y'
types.lines     = {'-', '-.', '-','-.','-','-.','-'}; %'-',   '-'
leglocation = 'SouthEast';
isLog = 0;

% Double loop, to plot for each solver outcomes for different "m" values
for i=1:nsol
    
    % Load data
    typesp.colors = [];
    typesp.lines = {'-','--',':','-.','--'};
    typesp.markers =['o' 'o' 'o' 'o' 'o'];
    for j=1:nms
        mleg{j} = ['$m=',num2str(ms(j)),'$'];        
        name_EXPERIMENT = ['EXPERIMENT_FINAL_CONS_m',num2str(ms(j))];        
        data = load([datapath,name_EXPERIMENT],'ex','numit','t_aver');
        ex(:,j) = data.ex(:,i);
        numit(:,j) = data.numit(:,i);
        t_aver(:,j) = data.t_aver(:,i);
        typesp.colors = [typesp.colors,types.colors(i)];
    end
    
    % "Normal" performance plots, ie not extended ones
    perf(ex(:,indAlg),t_aver(:,indAlg),mleg(indAlg),1,typesp,leglocation,isLog);
    box on; grid on;
    title(['$\textnormal{Time (',leg{i},')}$'],'Interpreter','latex');    
    fig                     = gcf;
    fig.PaperPositionMode   = 'auto';
    fig_pos                 = fig.PaperPosition;
    fig.PaperSize           = [fig_pos(3) fig_pos(4)];  
    figname = ['Fig6_m_',num2str(i),'.pdf']; %'time_EX_CUTEST_INIT_1';    
    print(fig,'-dpdf',fullfile(figpath,figname));    
    
    % Additional figures for comparisons on iterations are possible,
    % by un-commenting the lines below
    
%     perf(ex(:,indAlg),numit(:,indAlg),mleg(indAlg),1,typesp,leglocation,isLog);
%     box on; grid on;
%     title(['$\textnormal{Iter (',leg{i},')}$'],'Interpreter','latex');        
%     fig                     = gcf;
%     fig.PaperPositionMode   = 'auto';
%     fig_pos                 = fig.PaperPosition;
%     fig.PaperSize           = [fig_pos(3) fig_pos(4)];
%     figname = ['iter_C_SOLV_ALL_m_',num2str(i),'.pdf'];    
%     print(fig,'-dpdf',fullfile(figpath,figname));
    
end

%close ALL;

warning('on');
