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.

SupplyChainMonitor(varargin)
function varargout = SupplyChainMonitor(varargin)
% SUPPLYCHAINMONITOR M-file for SupplyChainMonitor.fig
%      SUPPLYCHAINMONITOR, by itself, creates a new SUPPLYCHAINMONITOR or raises the existing
%      singleton*.
%
%      H = SUPPLYCHAINMONITOR returns the handle to a new SUPPLYCHAINMONITOR or the handle to
%      the existing singleton*.
%
%      SUPPLYCHAINMONITOR('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SUPPLYCHAINMONITOR.M with the given input arguments.
%
%      SUPPLYCHAINMONITOR('Property','Value',...) creates a new SUPPLYCHAINMONITOR or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before SupplyChainMonitor_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to SupplyChainMonitor_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 SupplyChainMonitor

% Last Modified by GUIDE v2.5 16-Sep-2010 16:32:11

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @SupplyChainMonitor_OpeningFcn, ...
                   'gui_OutputFcn',  @SupplyChainMonitor_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 SupplyChainMonitor is made visible.
function SupplyChainMonitor_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 SupplyChainMonitor (see VARARGIN)

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

handles.i=varargin{1};
handles.Suppliers=varargin{2};
handles.PayoffScenario=varargin{3};
handles.Scenario=varargin{4};

if (nargin>7)
   handles.PayOff=varargin{5};
   handles.ShapleyValues=varargin{6};
   handles.Probability=varargin{7};
   handles.Risk=varargin{8};
   handles.Impact=varargin{9};
   handles.Replaceability=varargin{10};
end

if strcmp(handles.Scenario,'Production Capacity')
    field=1;
else
    if strcmp(handles.Scenario,'Lead Time')
       field=0;
    else
       field=2; 
    end   
end    

[positionB]=get(handles.pushbutton1,'Position');
position_or=positionB;
%max number of suppliers for row
x=zeros(1,20);
Units=get(handles.pushbutton1,'Units');
%supplier position in the graph
posizioni=[((positionB(3)/2)+positionB(1)),positionB(2)];

%compute the correct scale for the graph
% scalare il grafico sulla dimensione fissa della figure
% conto gli elementi per layer
dimx=50;
dimy=30;
dimxc=60;
dimyc=50;
for i=1:1:length(handles.Suppliers)
    x(handles.Suppliers(i).layer)=x(handles.Suppliers(i).layer)+1;
end

%trovo il numero di livelli
layer=min((find(x==0)))-1;

mriga=max(x);
[positionC]=get(handles.figure1,'Position');
%position_or=positionB;
posx=positionC(3)/(mriga+1);
if ((posx)<=(dimx+20))   
    dimx=(posx-10);
    dimxc=(dimx+10);
end    

posy=(positionC(4)-(positionC(4)-positionB(2)))/layer;


x=zeros(1,20);
for i=2:1:length(handles.Suppliers)
    x(handles.Suppliers(i).layer)=x(handles.Suppliers(i).layer)+1;
    %positionB(1)= position_or(1)+(110*(x(handles.Suppliers(i).layer)-1));
    positionB(1)= posx*(x(handles.Suppliers(i).layer))-(dimx/2);
    %positionB(2)=(position_or(2)+70)-(handles.Suppliers(i).layer*80);
    positionB(2)=(position_or(2))-(handles.Suppliers(i).layer-1)*posy;
    positionB(3)=dimx;
    positionB(4)=dimy;
    posizioni(i,:)=[((positionB(3)/2)+positionB(1)),positionB(2)];
    labelStrB=handles.Suppliers(i).Name;
    HDText1(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','pushbutton', ...
   'Units',Units, ...
   'Position',positionB, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'Callback',['SupplyChainMonitor(''pushbutton2_Callback'',gcbo,[',num2str(i),'],guidata(gcbo))']);
   eval(['handles.pushbutton',num2str(i),'=','HDText1(i);']);
   
   %positionB(1)= position_or(1)+(110*(x(handles.Suppliers(i).layer)-1))-5;
   positionB(1)= (posx*(x(handles.Suppliers(i).layer))-(dimx/2))-((dimxc-dimx)/2);
   %positionB(2)=(position_or(2)+70)-(handles.Suppliers(i).layer*80)-5;
   positionB(2)=((position_or(2))-(handles.Suppliers(i).layer-1)*posy)-((dimyc-dimy)/2);
   positionB(3)=dimxc;
   positionB(4)=dimyc;
   labelStrB=handles.Suppliers(i).Name;
   HDText1(i)=uipanel('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Units',Units, ...
   'Position',positionB);
   eval(['handles.uipanel',num2str(i),'=','HDText1(i);']);
   eval(['set(handles.uipanel',num2str(i),',''Title'',strcat(''Demand: '', num2str(int16(handles.Suppliers(i).Demand))))']);
end
%greate the links
for i=1:1:length(handles.Suppliers)
    for j=1:1:length(handles.Suppliers(i).Piece)
        %drow the lines
          da=posizioni(i,:);
          for k=1:1:length(handles.Suppliers(i).Piece(j).supp)
            a=posizioni(handles.Suppliers(i).Piece(j).supp(k),:);
            hold on
             line([da(1,1),a(1,1)],[da(1,2),a(1,2)])
            hold off
          end
    end    
end

if (nargin==7)
   if (field==1)
    handles.Suppliers(handles.i).ProdCap=handles.PayoffScenario(1,1);
   else
       if (field==0)
           handles.Suppliers(handles.i).LeadTime=handles.PayoffScenario(1,1);
       else
           handles.Suppliers(handles.i).UnitProdCap=handles.PayoffScenario(1,1);
       end    
   end
   set(handles.text1,'String',['Attack scenario: ',handles.Suppliers(handles.i).Name,'']);
else
   set(handles.text1,'String','Supply Chain Monitor'); 
end

for j=1:1:length(handles.Suppliers)
    if (nargin==7)
        handles.Suppliers(j).Demand=handles.PayoffScenario(1,j+1);
    end
    eval(['set(handles.pushbutton',num2str(j),',''String'',handles.Suppliers(j).Name)']);
    if (nargin==7)
       eval(['set(handles.pushbutton',num2str(j),',''Callback'',''SupplyChainMonitor(''''pushbutton1_Callback'''',gcbo,[',num2str(j),'],guidata(gcbo))'')']);
    else
       eval(['set(handles.pushbutton',num2str(j),',''Callback'',''SupplyChainMonitor(''''pushbutton2_Callback'''',gcbo,[',num2str(j),'],guidata(gcbo))'')']); 
    end    
    eval(['set(handles.uipanel',num2str(j),',''Title'',strcat(''Demand: '', num2str(int16(handles.Suppliers(j).Demand))))']);
    if (handles.Suppliers(j).Demand>0)
        eval(['set(handles.uipanel',num2str(j),',''ShadowColor'',''r'')']);
    else
        eval(['set(handles.uipanel',num2str(j),',''ShadowColor'',[0.5,0.5,0.5])']);
    end
end    

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = SupplyChainMonitor_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 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)
%
% visualizzazione generica dei parametri del noda
%  chiamato quando sono in visualizzazione dell'attacco in particolare
i=eventdata;
NodeView(handles.Suppliers(i))

% --- 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)

% questo non va bene perch  solo per la visualizzazione generica della
% tripla dell'attacco la posso usare in una finestra diversa. non qua dove
% al limite faccio vedere i parametri e non la tripla.
%
% visualizzazione del monitor del nodo con History barre ecc.
i=eventdata;
[handles.Supp(2).object]=Nodo(handles.Suppliers(i),handles.PayOff(i),handles.ShapleyValues(i),handles.Probability(i),handles.Risk(i), handles.Impact(i),handles.Replaceability(i));


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


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


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


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


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


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


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


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


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


Contact us at files@mathworks.com