% Plot 4

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

% Plot 4: 5000 Final opinion points: Different Agent Parameters

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

disp([ 9 9 9 'Plot 4: 5000 Final opinion points: Different Agent Parameters COMPUTATION'])

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

InitialOpinionIDs = InitialOpinionIDs_small;
AgentParametersIDs = AgentParametersIDs_large;

Plot_4_Results = cell(size(DigraphIDs,2)*size(InitialOpinionIDs,2),1);

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

    for id_io = 1:size(InitialOpinionIDs,2)
        Aux_5_InitialOpinionSelection
        % Aux_8_PlotPreparation

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

        Plot_4_LocalResults = cell(size(AgentParametersIDs,2),1);

        for id_ap = 1:size(AgentParametersIDs,2)

            Aux_4_AgentParameterSelection
            % Aux_7_PredictedPlots

            Opinions = EvolveModel_mod(InitialOpinion, AgentParameters, InteractionNetwork, total_time, ModelLabel);

Trajectory = nan*ones(total_time,2);

for id_t = 1:total_time
NewOpinions = Opinions(:,id_t);
Trajectory(id_t,1) = mean(abs(NewOpinions));
Trajectory(id_t,2) = mean(NewOpinions);
end


switch id_model
case 1
    local_lambda = mean(AgentParameters)*(1/2);
    LineColor = (Color_1*local_lambda) + (Color_2*(1-local_lambda));
case 2
    local_lambda = mean(AgentParameters)*(1/7);
    LineColor = (Color_1*local_lambda) + (Color_2*(1-local_lambda));
case 3
    rad_weight = AgentParameters(:,1); % Radical trait
    stb_weight = AgentParameters(:,2); % Stubborn trait
    con_weight = ones(size(rad_weight)) - rad_weight - stb_weight; % Conformist trait
    LineColor = ([1 0 0]*mean(rad_weight)) + ([0 1 0]*mean(stb_weight)) + ([0 0 1]*mean(con_weight));
    LineColor(1) = max([0 min([1 LineColor(1)])]);
    LineColor(2) = max([0 min([1 LineColor(2)])]);
    LineColor(3) = max([0 min([1 LineColor(3)])]);
case 4
    local_lambda = mean(AgentParameters);
    LineColor = (Color_1*local_lambda) + (Color_2*(1-local_lambda));
end

Plot_4_LocalResults{id_ap} = {[Trajectory(end,1), Trajectory(end,2)], LineColor};

        end

        Plot_4_Results{local_counter} = {Plot_4_LocalResults, [id_initial_opinion, id_network], [Trajectory(1,1), Trajectory(1,2)]};
        
    end
end




save([ModelLabel '_Plot_4_Data.mat'], 'Plot_4_Results')


