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.

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

% Last Modified by GUIDE v2.5 22-Feb-2010 17:54:28

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

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




handles.Suppliers=varargin{1};
handles.Payoff=varargin{2};
handles.ChainProfit=varargin{3};
handles.PayoffScenario=varargin{4};
handles.Risk=varargin{5};
handles.ShapleyValues=varargin{7};
handles.Probability=varargin{8};
handles.Impact=varargin{9};
handles.Replaceability=varargin{10};
handles.Scenario=varargin{6};
handles.Rounds=varargin{11};
handles.Epoch=varargin{12};
handles.attack=varargin{13};
%sistemo le righe ricopiando la prima per tutti i suppliers
set(handles.figure1,'Name',strcat(strcat(strcat(strcat(strcat(varargin{6},' Attack  -- '),' Round: '),num2str(handles.Rounds)),' Epoch: '),num2str(handles.Epoch)));
%set(handles.figure1,'Name',strcat(varargin{6},' Attack'));
%set(handles.text6,'String',varargin{6});

if strcmp(varargin{6},'Production Capacity')
    field=1;
    set(handles.text6,'String','Prod. Cap.');
else
    if strcmp(varargin{6},'Lead Time')
       field=0;
       set(handles.text6,'String','Lead Time');
    else
        if strcmp(varargin{6},'Production Cost')
            field=2;
            set(handles.text6,'String','Prod. Cost.');
        end
    end    
end    

%salto AVIO
set(handles.pushbutton2,'String',handles.Suppliers(2).Name);
if handles.attack(1)
   set(handles.pushbutton2,'ForegroundColor','red');
end  
set(handles.edit12,'String',handles.Payoff(2));
%salto avio
set(handles.edit22,'String',handles.PayoffScenario(2,3));

set(handles.edit32,'String',handles.PayoffScenario(2,1));

%set(handles.edit42,'String',handles.ChainProfit(2));
set(handles.edit52,'String',handles.Risk(2));

set(handles.text22,'String',int16(handles.Suppliers(2).Demand));


% gestire i numeri con virgola che ci sono in giro.


if (field==1)
   set(handles.text32,'String',handles.Suppliers(2).ProdCap);
else
    if (field==0)
        set(handles.text32,'String',handles.Suppliers(2).LeadTime); 
    else
        set(handles.text32,'String',handles.Suppliers(2).UnitProdCost); 
    end    
        
end  

% Gestire il colore
ForegroundColor='k';
   if (field==1)
      if (handles.Suppliers(2).ProdCap<handles.PayoffScenario(2,1))
         ForegroundColor='r';
      else
          if (handles.Suppliers(2).ProdCap>handles.PayoffScenario(2,1))
              ForegroundColor='b';
          end    
      end
   else
      if (field==0) 
         if (handles.Suppliers(2).LeadTime<handles.PayoffScenario(2,1))
            ForegroundColor='r';
         else
             if (handles.Suppliers(2).LeadTime>handles.PayoffScenario(2,1))
                 ForegroundColor='b';
             end    
         end
      else
         if (handles.Suppliers(2).UnitProdCost<handles.PayoffScenario(2,1))
            ForegroundColor='r';
         else
             if (handles.Suppliers(2).UnitProdCost>handles.PayoffScenario(2,1))
                 ForegroundColor='b';
             end    
         end
      end    
   end    
set(handles.edit32,'ForegroundColor',ForegroundColor);
set(handles.pushbutton2,'Callback','Parameters(''pushbutton1_Callback'',gcbo,[2],guidata(gcbo))');

Units=get(handles.pushbutton2,'Units');
%set the window dimension 

Position=get(handles.figure1,'Position');
Positionor=Position(4);
Position(4)=(length(handles.Suppliers)-1)*1.6+8;
diff=Position(4)-Positionor;
set(handles.figure1,'Position',Position);

%reset the position of everyting.
pos=get(handles.uipanel5,'Position');
pos(4)=pos(4)+diff;
set(handles.uipanel5,'Position',pos);
pos=get(handles.uipanel6,'Position');
pos(4)=pos(4)+diff;
set(handles.uipanel6,'Position',pos);
pos=get(handles.uipanel1,'Position');
pos(4)=pos(4)+diff;
set(handles.uipanel1,'Position',pos);
pos=get(handles.uipanel2,'Position');
pos(4)=pos(4)+diff;
set(handles.uipanel2,'Position',pos);
pos=get(handles.uipanel8,'Position');
pos(4)=pos(4)+diff;
set(handles.uipanel8,'Position',pos);

pos=get(handles.text1,'Position');
pos(2)=pos(2)+diff;
set(handles.text1,'Position',pos);
pos=get(handles.text2,'Position');
pos(2)=pos(2)+diff;
set(handles.text2,'Position',pos);
pos=get(handles.text4,'Position');
pos(2)=pos(2)+diff;
set(handles.text4,'Position',pos);
pos=get(handles.text6,'Position');
pos(2)=pos(2)+diff;
set(handles.text6,'Position',pos);
pos=get(handles.text11,'Position');
pos(2)=pos(2)+diff;
set(handles.text11,'Position',pos);

pos=get(handles.pushbutton2,'Position');
pos(2)=pos(2)+diff;
set(handles.pushbutton2,'Position',pos);

pos=get(handles.edit12,'Position');
pos(2)=pos(2)+diff;
set(handles.edit12,'Position',pos);
pos=get(handles.edit22,'Position');
pos(2)=pos(2)+diff;
set(handles.edit22,'Position',pos);
pos=get(handles.edit32,'Position');
pos(2)=pos(2)+diff;
set(handles.edit32,'Position',pos);
pos=get(handles.edit52,'Position');
pos(2)=pos(2)+diff;
set(handles.edit52,'Position',pos);

pos=get(handles.text22,'Position');
pos(2)=pos(2)+diff;
set(handles.text22,'Position',pos);
pos=get(handles.text32,'Position');
pos(2)=pos(2)+diff;
set(handles.text32,'Position',pos);
% set the rest of the window

BackgroundColor=get(handles.edit12,'BackgroundColor');
for i=2:1:(length(handles.Suppliers)-1)
    %#############################Colonna attori##############################
   %ButtPosX ButtPosY ButtWidth ButtHeight
   eval(['[positionB]=get(handles.pushbutton',num2str(i),',''Position'');']);
   DeltaY=positionB(4);
   positionB(2)=positionB(2)-DeltaY;
   labelStrB=handles.Suppliers(i+1).Name;
   HDButton(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','pushbutton', ...
   'Units',Units, ...
   'Position',positionB, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'Callback',['Parameters(''pushbutton1_Callback'',gcbo,[',num2str(i+1),'],guidata(gcbo))']);
   eval(['handles.pushbutton',num2str(i+1),'=','HDButton(i);']);
   if handles.attack(i)
       eval(['set(handles.pushbutton',num2str(i),',''ForegroundColor'',''red'');']);
   end    
   %#############################Colonna Payoff##############################
   eval(['[positionE]=get(handles.edit1',num2str(i),',''Position'');']);
   %DeltaY=positionB(4);
   positionE(2)=positionE(2)-DeltaY;
   labelStrB=handles.Payoff(i+1);
   HDEdit1(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','edit', ...
   'Units',Units, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'BackgroundColor',BackgroundColor, ...
   'Callback','Parameters(''edit11_Callback'',gcbo,[],guidata(gcbo))');
   eval(['handles.edit1',num2str(i+1),'=','HDEdit1(i);']);
   %#############################Colonna Demand##############################
   eval(['[positionE]=get(handles.edit2',num2str(i),',''Position'');']);
   %DeltaY=positionB(4);
   positionE(2)=positionE(2)-DeltaY;
   labelStrB=handles.PayoffScenario(i+1,i+2);
   HDEdit2(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','edit', ...
   'Units',Units, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'BackgroundColor',BackgroundColor, ...
   'Callback','Parameters(''edit11_Callback'',gcbo,[],guidata(gcbo))');
   eval(['handles.edit2',num2str(i+1),'=','HDEdit2(i);']);
   %text
   eval(['[positionE]=get(handles.text2',num2str(i),',''Position'');']);
   %DeltaY=positionB(4);
   positionE(2)=positionE(2)-DeltaY;
   %############# OCCHIO ALL'OUTPUT NON INTERO 
   labelStrB=int16(handles.Suppliers(i+1).Demand);
   HDtext2(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','text', ...
   'Units',Units, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on');
   eval(['handles.text2',num2str(i+1),'=','HDtext2(i);']);
   
   %#############################Colonna field##############################
   eval(['[positionE]=get(handles.edit3',num2str(i),',''Position'');']);
   %DeltaY=positionB(4);
   positionE(2)=positionE(2)-DeltaY;
   labelStrB=handles.PayoffScenario(i+1,1);
   ForegroundColor='k';
   if (field==1)
      if (handles.Suppliers(i+1).ProdCap<handles.PayoffScenario(i+1,1))
         ForegroundColor='r';
      else
          if (handles.Suppliers(i+1).ProdCap>handles.PayoffScenario(i+1,1))
              ForegroundColor='b';
          end    
      end
   else
      if (field==0) 
         if (handles.Suppliers(i+1).LeadTime<handles.PayoffScenario(i+1,1))
            ForegroundColor='r';
         else
             if (handles.Suppliers(i+1).LeadTime>handles.PayoffScenario(i+1,1))
                 ForegroundColor='b';
             end    
         end
      else
         if (handles.Suppliers(i+1).UnitProdCost<handles.PayoffScenario(i+1,1))
            ForegroundColor='r';
         else
             if (handles.Suppliers(i+1).UnitProdCost>handles.PayoffScenario(i+1,1))
                 ForegroundColor='b';
             end    
         end
      end    
   end    
       
   HDEdit3(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','edit', ...
   'Units',Units, ...
   'ForegroundColor',ForegroundColor, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'BackgroundColor',BackgroundColor, ...
   'Callback','Parameters(''edit11_Callback'',gcbo,[],guidata(gcbo))');
   eval(['handles.edit3',num2str(i+1),'=','HDEdit3(i);']);
   %text
   eval(['[positionE]=get(handles.text3',num2str(i),',''Position'');']);
   %DeltaY=positionB(4);
   positionE(2)=positionE(2)-DeltaY;
   if (field==1)
      labelStrB=handles.Suppliers(i+1).ProdCap;
   else
       if (field==0)
          labelStrB=handles.Suppliers(i+1).LeadTime; 
       else
          labelStrB=handles.Suppliers(i+1).UnitProdCost; 
       end    
   end    
   HDtext3(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','text', ...
   'Units',Units, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on');
   eval(['handles.text3',num2str(i+1),'=','HDtext3(i);']);
%    %#############################Colonna ChainProfit##############################
%    eval(['[positionE]=get(handles.edit4',num2str(i),',''Position'');']);
%    %DeltaY=positionB(4);
%    positionE(2)=positionE(2)-DeltaY;
%    labelStrB=handles.ChainProfit(i+1);
%    HDEdit4(i)=uicontrol('Parent', handles.figure1, ...
%    'BusyAction','Queue','Interruptible','off',...
%    'Style','edit', ...
%    'Units',Units, ...
%    'Position',positionE, ...
%    'String',labelStrB, ...
%    'Enable','on', ...
%    'BackgroundColor',BackgroundColor, ...
%    'Callback','Parameters(''edit11_Callback'',gcbo,[],guidata(gcbo))');
%    eval(['handles.edit4',num2str(i+1),'=','HDEdit4(i);']);
   %#############################Colonna Rischio##############################
   eval(['[positionE]=get(handles.edit5',num2str(i),',''Position'');']);
   %DeltaY=positionB(4);
   positionE(2)=positionE(2)-DeltaY;
   labelStrB=handles.Risk(i+1);
   HDEdit5(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','edit', ...
   'Units',Units, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'BackgroundColor',BackgroundColor, ...
   'Callback','Parameters(''edit11_Callback'',gcbo,[],guidata(gcbo))');
   eval(['handles.edit5',num2str(i+1),'=','HDEdit5(i);']);
   
end

% % Update handles structure
% handles.pushbutton(i)=HDButton(i);


% Update handles structure
guidata(hObject, handles);


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


% --- Outputs from this function are returned to the command line.
function varargout = Parameters_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 pushbutton2.
function pushbutton1_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)
i=eventdata;
SupplyChainMonitor(i,handles.Suppliers,handles.PayoffScenario(i,:),handles.Scenario);


function edit12_Callback(hObject, eventdata, handles)
% hObject    handle to edit12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit12 as text
%        str2double(get(hObject,'String')) returns contents of edit12 as a double


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

% Hint: edit 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



function edit22_Callback(hObject, eventdata, handles)
% hObject    handle to edit22 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit22 as text
%        str2double(get(hObject,'String')) returns contents of edit22 as a double


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

% Hint: edit 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



function edit32_Callback(hObject, eventdata, handles)
% hObject    handle to edit32 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit32 as text
%        str2double(get(hObject,'String')) returns contents of edit32 as a double


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

% Hint: edit 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





function edit42_Callback(hObject, eventdata, handles)
% hObject    handle to edit42 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit42 as text
%        str2double(get(hObject,'String')) returns contents of edit42 as a double


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

% Hint: edit 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





function edit52_Callback(hObject, eventdata, handles)
% hObject    handle to edit52 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit52 as text
%        str2double(get(hObject,'String')) returns contents of edit52 as a double


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

% Hint: edit 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 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)




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


Contact us at files@mathworks.com