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.

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

% Last Modified by GUIDE v2.5 15-Sep-2010 15:48:32

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

handles.Suppliers=varargin{1};
handles.Scenario=varargin{2};
handles.ShapleyValues=varargin{3};
handles.Payoff=varargin{4};
handles.Replaceability=varargin{5};
handles.Probability=varargin{6};
handles.Impact=varargin{7};
handles.Risk=varargin{8};
handles.Incentive=varargin{9};
handles.Lot=varargin{10};
handles.Rounds=varargin{11};
handles.Epoch=varargin{12};
handles.attack=varargin{13};


% tolgo avio
[out ind]=sort(handles.Risk(2:end),'descend');
%Sistemo gli indici per riavere l'ordine corretto
ind=ind+1;

%sistemo le righe ricopiando la prima per tutti i suppliers
str=strcat(strcat(strcat('SCRS Tuple with INCENTIVE:  --  Round: ',num2str(handles.Rounds)),' Epoch: '),num2str(handles.Epoch));
set(handles.figure1,'Name',str);
Units=get(handles.edit11,'Units');
BackgroundColor=get(handles.edit11,'BackgroundColor');

set(handles.text11,'String',handles.Suppliers(ind(1)).Name);
set(handles.edit11,'String',handles.ShapleyValues(ind(1)));
set(handles.edit21,'String',handles.Payoff(ind(1)));
set(handles.edit31,'String',handles.Replaceability(ind(1)));
set(handles.edit41,'String',handles.Probability(ind(1)));
set(handles.edit51,'String',handles.Impact(ind(1)));
set(handles.edit61,'String',handles.Risk(ind(1)));
set(handles.edit71,'String',handles.Incentive(ind(1)));


%set the window dimension 

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

%reset the position of everyting.
pos=get(handles.text11,'Position');
pos(2)=pos(2)+diff;
set(handles.text11,'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.text3,'Position');
pos(2)=pos(2)+diff;
set(handles.text3,'Position',pos);
pos=get(handles.text4,'Position');
pos(2)=pos(2)+diff;
set(handles.text4,'Position',pos);
pos=get(handles.text5,'Position');
pos(2)=pos(2)+diff;
set(handles.text5,'Position',pos);
pos=get(handles.text6,'Position');
pos(2)=pos(2)+diff;
set(handles.text6,'Position',pos);
pos=get(handles.text8,'Position');
pos(2)=pos(2)+diff;
set(handles.text8,'Position',pos);

pos=get(handles.edit11,'Position');
pos(2)=pos(2)+diff;
set(handles.edit11,'Position',pos);
pos=get(handles.edit21,'Position');
pos(2)=pos(2)+diff;
set(handles.edit21,'Position',pos);
pos=get(handles.edit31,'Position');
pos(2)=pos(2)+diff;
set(handles.edit31,'Position',pos);
pos=get(handles.edit41,'Position');
pos(2)=pos(2)+diff;
set(handles.edit41,'Position',pos);
pos=get(handles.edit51,'Position');
pos(2)=pos(2)+diff;
set(handles.edit51,'Position',pos);
pos=get(handles.edit61,'Position');
pos(2)=pos(2)+diff;
set(handles.edit61,'Position',pos);
pos=get(handles.edit71,'Position');
pos(2)=pos(2)+diff;
set(handles.edit71,'Position',pos);


%
for i=1:1:(length(handles.Suppliers))-2
    %#############################Colonna attori##############################
   %ButtPosX ButtPosY ButtWidth ButtHeight
   eval(['[positionB]=get(handles.text1',num2str(i),',''Position'');']);
   DeltaY=positionB(4)*1.5;
   positionB(2)=positionB(2)-DeltaY;
   labelStrB=handles.Suppliers(ind(i+1)).Name;
   HDText1(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','text', ...
   'Units',Units, ...
   'Position',positionB, ...
   'String',labelStrB, ...
   'Enable','on');
   eval(['handles.text1',num2str(i+1),'=','HDText1(i);']);
   
   if handles.attack(ind(i))
       eval(['set(handles.text1',num2str(i),',''ForegroundColor'',''red'');']);
   else
       eval(['set(handles.text1',num2str(i),',''ForegroundColor'',''black'');']);
   end 
   
   %#############################Colonna Shapley##############################
   eval(['[positionE]=get(handles.edit1',num2str(i),',''Position'');']);
   positionE(2)=positionE(2)-DeltaY;
   labelStrB=handles.ShapleyValues(ind(i+1));
   HDEdit1(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','edit', ...
   'Units',Units, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'BackgroundColor',BackgroundColor);
   eval(['handles.edit1',num2str(i+1),'=','HDEdit1(i);']);
   %#############################Colonna Payoff##############################
   eval(['[positionE]=get(handles.edit2',num2str(i),',''Position'');']);
   positionE(2)=positionE(2)-DeltaY;
   labelStrB=handles.Payoff(ind(i+1));
   HDEdit2(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','edit', ...
   'Units',Units, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'BackgroundColor',BackgroundColor);
   eval(['handles.edit2',num2str(i+1),'=','HDEdit2(i);']);
   
   %#############################Colonna Replaceability##############################
   eval(['[positionE]=get(handles.edit3',num2str(i),',''Position'');']);
   %DeltaY=positionB(4);
   positionE(2)=positionE(2)-DeltaY;
   labelStrB=handles.Replaceability(ind(i+1));
   HDEdit3(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','edit', ...
   'Units',Units, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'BackgroundColor',BackgroundColor);
   eval(['handles.edit3',num2str(i+1),'=','HDEdit3(i);']);
   %#############################Colonna Impact##############################
   eval(['[positionE]=get(handles.edit4',num2str(i),',''Position'');']);
   %DeltaY=positionB(4);
   positionE(2)=positionE(2)-DeltaY;
   labelStrB=handles.Probability(ind(i+1));
   HDEdit4(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','edit', ...
   'Units',Units, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'BackgroundColor',BackgroundColor);
   eval(['handles.edit4',num2str(i+1),'=','HDEdit4(i);']);
   %#############################Colonna Impact##############################
   eval(['[positionE]=get(handles.edit5',num2str(i),',''Position'');']);
   %DeltaY=positionB(4);
   positionE(2)=positionE(2)-DeltaY;
   labelStrB=handles.Impact(ind(i+1));
   HDEdit5(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','edit', ...
   'Units',Units, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'BackgroundColor',BackgroundColor);
   eval(['handles.edit5',num2str(i+1),'=','HDEdit5(i);']);
   %#############################Colonna Risk##############################
   eval(['[positionE]=get(handles.edit6',num2str(i),',''Position'');']);
   %DeltaY=positionB(4);
   positionE(2)=positionE(2)-DeltaY;
   labelStrB=handles.Risk(ind(i+1));
   HDEdit6(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','edit', ...
   'Units',Units, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'BackgroundColor',BackgroundColor);
   eval(['handles.edit6',num2str(i+1),'=','HDEdit6(i);']);
   %#############################Colonna Inc##############################
   eval(['[positionE]=get(handles.edit7',num2str(i),',''Position'');']);
   %DeltaY=positionB(4);
   positionE(2)=positionE(2)-DeltaY;
   labelStrB=handles.Incentive(ind(i+1));
   HDEdit7(i)=uicontrol('Parent', handles.figure1, ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','edit', ...
   'Units',Units, ...
   'Position',positionE, ...
   'String',labelStrB, ...
   'Enable','on', ...
   'BackgroundColor',BackgroundColor);
   eval(['handles.edit7',num2str(i+1),'=','HDEdit7(i);']);
   
end



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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = SCRSTuple_Incentive_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;



function edit11_Callback(hObject, eventdata, handles)
% hObject    handle to edit11 (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 edit11 as text
%        str2double(get(hObject,'String')) returns contents of edit11 as a double


% --- Executes during object creation, after setting all properties.
function edit11_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit11 (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 edit21_Callback(hObject, eventdata, handles)
% hObject    handle to edit21 (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 edit21 as text
%        str2double(get(hObject,'String')) returns contents of edit21 as a double


% --- Executes during object creation, after setting all properties.
function edit21_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit21 (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 edit31_Callback(hObject, eventdata, handles)
% hObject    handle to edit31 (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 edit31 as text
%        str2double(get(hObject,'String')) returns contents of edit31 as a double


% --- Executes during object creation, after setting all properties.
function edit31_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit31 (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 edit41_Callback(hObject, eventdata, handles)
% hObject    handle to edit41 (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 edit41 as text
%        str2double(get(hObject,'String')) returns contents of edit41 as a double


% --- Executes during object creation, after setting all properties.
function edit41_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit41 (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 edit51_Callback(hObject, eventdata, handles)
% hObject    handle to edit51 (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 edit51 as text
%        str2double(get(hObject,'String')) returns contents of edit51 as a double


% --- Executes during object creation, after setting all properties.
function edit51_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit51 (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 edit61_Callback(hObject, eventdata, handles)
% hObject    handle to edit61 (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 edit61 as text
%        str2double(get(hObject,'String')) returns contents of edit61 as a double


% --- Executes during object creation, after setting all properties.
function edit61_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit61 (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 edit71_Callback(hObject, eventdata, handles)
% hObject    handle to edit71 (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 edit71 as text
%        str2double(get(hObject,'String')) returns contents of edit71 as a double


% --- Executes during object creation, after setting all properties.
function edit71_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit71 (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


Contact us at files@mathworks.com