% Plot 6

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Plot 6: 5000 Final opinion points: Different Initial Opinions

InitialOpinionIDs = InitialOpinionIDs_large;
AgentParametersIDs = AgentParametersIDs_small;

if id_model == 1
    DigraphIDs = 1;
else
    DigraphIDs = 1:size(InteractionNetworks,2);
end

disp([ 9 9 9 'Plot 6: 5000 Final opinion points: Different Initial Opinions COMPUTATION'])    

switch id_model
    case 1 
        DigraphIDs = 1;
    case 2
        DigraphIDs = 1:9;
    case 3
        DigraphIDs = IntermediateDigraphIDs;
    case 4
        DigraphIDs = IntermediateDigraphIDs;
end

% Plot initial opinions
num_opinions = size(InitialOpinionIDs,2);

NewColor_1 = (1/255)*[255,69,0];
NewColor_2 = (1/255)*[50,205,50];
NewColor_3 = (1/255)*[65,105,225];
PointColors = AdvancedColorMap(num_opinions, NewColor_1, NewColor_2, NewColor_3, ceil(0.5*num_opinions));


Mean_opinions = nan*ones(1,num_opinions);
for id_row = 1:num_opinions
    InitialOpinions = AllInitialOpinions{InitialOpinionIDs(id_row)};
    y_value = mean(InitialOpinions);
    Mean_opinions(id_row) = y_value;
end

[~, index_sorting] = sort(Mean_opinions);
[~, random_sorting] = sort(rand(size(Mean_opinions)));

Plot_6_InitialPlot = cell(num_opinions,1);

for id_row_2 = 1:num_opinions

    id_row = random_sorting(id_row_2);
    InitialOpinions = AllInitialOpinions{InitialOpinionIDs(index_sorting(id_row))};
    x_value = mean(abs(InitialOpinions));
    y_value = mean(InitialOpinions);

    Plot_6_InitialPlot{id_row_2} = {[x_value, y_value], PointColors(id_row,:)};

end

% Compute final opinions

Plot_6_Results = cell(size(AgentParametersIDs,2)*size(DigraphIDs,2),1);

local_counter = 0;
for id_di = 1:size(DigraphIDs,2)
    Aux_3_DigraphSelection

    for id_ap = 1:size(AgentParametersIDs,2)
        Aux_4_AgentParameterSelection
        % Aux_8_PlotPreparation

        local_counter = local_counter + 1;
        disp([ 9 ' . ' num2str(local_counter) '/' num2str(size(AgentParametersIDs,2)*size(DigraphIDs,2))])

        Plot_6_LocalResults = cell(num_opinions,1);

        for id_row_2 = 1:num_opinions

id_row = random_sorting(id_row_2);
id_initial_opinion = index_sorting(id_row);
InitialOpinions = AllInitialOpinions{InitialOpinionIDs(id_initial_opinion)};
            
Opinions = EvolveModel_mod(InitialOpinions, AgentParameters, InteractionNetwork, total_time, ModelLabel);

x_value = mean(abs(Opinions(:,end)));
y_value = mean(Opinions(:,end));

Plot_6_LocalResults{id_row_2} = {[x_value, y_value], PointColors(id_row,:)};


        end

        Plot_6_Results{local_counter} = {Plot_6_LocalResults, [id_paramterer, id_network]};

%             Aux_9_PlotDetails
%             Aux_1_AgentParameterSuplot
%             Aux_2_DigraphSubplot


    end
end


save([ModelLabel '_Plot_6_Data.mat'], 'Plot_6_Results', 'Plot_6_InitialPlot')