Code covered by the BSD License  

Highlights from
Supply Chain Risk Simulator (SCRS)

from Supply Chain Risk Simulator (SCRS) by Marco Anisetti
Supply Chain simulator for risk assessment and incentive schemes.

ResultsExplorer(varargin)
function varargout = ResultsExplorer(varargin)
% RESULTSEXPLORER M-file for ResultsExplorer.fig
%      RESULTSEXPLORER, by itself, creates a new RESULTSEXPLORER or raises the existing
%      singleton*.
%
%      H = RESULTSEXPLORER returns the handle to a new RESULTSEXPLORER or the handle to
%      the existing singleton*.
%
%      RESULTSEXPLORER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in RESULTSEXPLORER.M with the given input arguments.
%
%      RESULTSEXPLORER('Property','Value',...) creates a new RESULTSEXPLORER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before ResultsExplorer_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to ResultsExplorer_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help ResultsExplorer

% Last Modified by GUIDE v2.5 15-Sep-2010 17:02:42

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ResultsExplorer_OpeningFcn, ...
                   'gui_OutputFcn',  @ResultsExplorer_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before ResultsExplorer is made visible.
function ResultsExplorer_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to ResultsExplorer (see VARARGIN)
% Res.PayOff=[];
% Res.Economicalimpact=[];
% Res.PayoffScenario=[];
% Res.risk=[];
% Res.scenario=[];
% Res.ShapleyValues=[];
% Res.Probability=[];
% Res.Impact=[];
% Res.Repalceability=[];
% 
% Res.PayOffI=[];
% Res.ShapleyValuesI=[];
% Res.ProbabilityI=[];
% Res.ImpactI=[];
% Res.riskI=[];
% Res.LostIncentive=[];
% Res.MonteIncentives=[];
% Res.SimulatedAttack=[];


handles.Res=varargin{1};
handles.rounds=varargin{2};
handles.epoch=varargin{3};
handles.incent=varargin{4};
handles.Results_risk_no_inc=varargin{5};
handles.Results_risk_inc=varargin{6};
handles.Results_prob_no_inc=varargin{7};
handles.Results_prob_inc=varargin{8};
handles.Results_impa=varargin{9};
handles.Results_Ince=varargin{10};
handles.Results_attack=varargin{11};

for i=1:1:handles.rounds
    a(i,1)={num2str(i)};
end
for i=1:1:handles.epoch
    b(i,1)={num2str(i)};
end
set(handles.popupmenu2,'String',a);
set(handles.popupmenu3,'String',b);


% Choose default command line output for ResultsExplorer
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes ResultsExplorer wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = ResultsExplorer_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2


% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu3 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu3


% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
rounds=get(handles.popupmenu2,'Value');
epoch=get(handles.popupmenu3,'Value');
indice=(handles.rounds*(epoch-1))+rounds;
% attackers at the previous round
if (rounds>1)
 attack=handles.Results_attack(rounds-1,:,epoch);
else
 attack=zeros(1,length(handles.Res(indice).SuppliersNew));
end 
Parameters(handles.Res(indice).SuppliersNew,handles.Res(indice).PayOff,handles.Res(indice).Economicalimpact,handles.Res(indice).PayoffScenario,handles.Res(indice).risk,handles.Res(indice).scenario,handles.Res(indice).ShapleyValues,handles.Res(indice).Probability,handles.Res(indice).Impact,handles.Res(indice).Replaceability,rounds,epoch,attack);
SCRSTuple(handles.Res(indice).SuppliersNew,handles.Res(indice).scenario,handles.Res(indice).ShapleyValues, handles.Res(indice).PayOff, handles.Res(indice).Replaceability, handles.Res(indice).Probability ,handles.Res(indice).Impact,handles.Res(indice).risk,rounds,epoch,attack);
SupplyChainMonitor(1,handles.Res(indice).SuppliersNew,handles.Res(indice).PayoffScenario,handles.Res(indice).scenario,handles.Res(indice).PayOff,handles.Res(indice).ShapleyValues,handles.Res(indice).Probability,handles.Res(indice).risk,handles.Res(indice).Impact,handles.Res(indice).Replaceability,handles.rounds,handles.epoch);
if (handles.incent==1)
     SCRSTuple_Incentive(handles.Res(indice).SuppliersNew,handles.Res(indice).scenario,handles.Res(indice).ShapleyValuesI,handles.Res(indice).PayOffI, handles.Res(indice).Replaceability, handles.Res(indice).ProbabilityI,handles.Res(indice).ImpactI,handles.Res(indice).riskI,handles.Res(indice).LostIncentive,handles.Res(indice).MonteIncentives,rounds,epoch,attack);
end






% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


nomi=cell(length(handles.Res(1).SuppliersNew)-1,1);
for i=1:1:(length(handles.Res(1).SuppliersNew)-1)
    nomi{i}=handles.Res(1).SuppliersNew(i+1).Name;
end
r=[];
p=[];
im=[];
in=[];
at=[];
% se ho una sola epoca questo non funziona
if (handles.epoch>1)
for i=1:1:handles.rounds
    r=[r;mean(reshape(handles.Results_risk_no_inc(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)'),mean(reshape(handles.Results_risk_inc(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)')];
    p=[p;mean(reshape(handles.Results_prob_no_inc(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)'),mean(reshape(handles.Results_prob_inc(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)')];
    rmax=[r;max(reshape(handles.Results_risk_no_inc(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)'),mean(reshape(handles.Results_risk_inc(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)')];
    pmax=[p;max(reshape(handles.Results_prob_no_inc(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)'),mean(reshape(handles.Results_prob_inc(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)')];
    rmin=[r;min(reshape(handles.Results_risk_no_inc(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)'),min(reshape(handles.Results_risk_inc(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)')];
    pmin=[p;min(reshape(handles.Results_prob_no_inc(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)'),min(reshape(handles.Results_prob_inc(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)')];
    im=[im;mean(reshape(handles.Results_impa(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)')];
    in=[in;mean(reshape(handles.Results_Ince(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)')];
    at=[at;sum(reshape(handles.Results_attack(i,:,:),length(handles.Res(1).SuppliersNew),handles.epoch)')];
end
else
    disp('Only one epoch')
    r=[handles.Results_risk_no_inc,handles.Results_risk_inc];
    p=[handles.Results_prob_no_inc,handles.Results_prob_inc];
    im=[handles.Results_impa];
    in=[handles.Results_Ince];
    at=[handles.Results_attack];
end

%

disp('plot')

if get(handles.radiobutton2,'Value')

rm=reshape(mean(r),length(handles.Res(1).SuppliersNew),2);
pm=reshape(mean(p),length(handles.Res(1).SuppliersNew),2);
im2=mean(im)';
in2=mean(in)';
%rm=mean(r)';
if get(handles.checkbox2,'Value')
   figure('Position',[100,400,750,300]);
   h=axes; % Select the proper axes
   if (handles.incent==1)
       title('Average Risk comparison: no incentives vs. incentives','FontWeight','bold');
   else
       title('Average Risk','FontWeight','bold');
   end    
   xlabel('Suppliers','FontWeight','bold');
   ylabel('Risk','FontWeight','bold');
   set(h,'XTick',[1:(length(handles.Res(1).SuppliersNew))-1]);
   set(h,'XTickLabel',nomi);
   hold on
   bar(rm(2:end,:),'group')
   hold off
end
if get(handles.checkbox1,'Value')
  %pm=mean(p)';
  figure('Position',[100,400,750,300]);
  h=axes; % Select the proper axes
  if (handles.incent==1)
    title('Average Probability comparison: no incentives vs. incentives','FontWeight','bold');
  else
     title('Average Probability','FontWeight','bold');
  end    
  xlabel('Suppliers','FontWeight','bold');
  ylabel('Probability','FontWeight','bold');
  set(h,'XTick',[1:(length(handles.Res(1).SuppliersNew))-1]);
  set(h,'XTickLabel',nomi);
  hold on
  bar(pm(2:end,:),'group')
  hold off
end
% figure;
% h=axes; % Select the proper axes
% if (handles.incent==1)
%     title('Average Impacts vs. Incentives','FontWeight','bold');
% else
%      title('Average Impacts','FontWeight','bold');
% end   
% set(h,'XTick',[1:(length(handles.Res(1).SuppliersNew))]);
% set(h,'XTickLabel',nomi);
% hold on
% bar([im2,in2],'group')
% hold off

% Surface
% Probability and risk
else
if get(handles.checkbox2,'Value')
   figure('Position',[100,400,750,400]);  
   h=axes; % Select the proper axes
   title('Average Risk evolution through rounds','FontWeight','bold');
   campos([handles.rounds,-(length(handles.Res(1).SuppliersNew)),2]);
   xlabel('Suppliers','FontWeight','bold');
   ylabel('Risk','FontWeight','bold');
   set(h,'XTick',[1:(length(handles.Res(1).SuppliersNew))-1]);
   set(h,'XTickLabel',nomi);
   hold on
   surf(r(1:handles.rounds,2:length(handles.Res(1).SuppliersNew)+1));
   hold off
end
if get(handles.checkbox1,'Value')
   figure('Position',[100,400,750,400]); 
   h=axes; % Select the proper axes
   title('Average Probability evolution through rounds','FontWeight','bold');
   campos([handles.rounds,-(length(handles.Res(1).SuppliersNew)),2]);
   xlabel('Suppliers','FontWeight','bold');
   ylabel('Probability','FontWeight','bold');
   set(h,'XTick',[1:(length(handles.Res(1).SuppliersNew))-1]);
   set(h,'XTickLabel',nomi);
   hold on
   surf(p(1:handles.rounds,2:length(handles.Res(1).SuppliersNew)+1));
   hold off
end

end


%costoincentivi=sum(in)
%costoattacchi=sum(im)




% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox1


% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox2


% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton2
set(handles.radiobutton3,'Value',0);
set(handles.radiobutton2,'Value',1);

% --- Executes on button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton3
set(handles.radiobutton3,'Value',1);
set(handles.radiobutton2,'Value',0);

Contact us at files@mathworks.com