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.

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

% Last Modified by GUIDE v2.5 28-May-2010 15:50:47

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

% Choose default command line output for SCRStart
handles.output = hObject;
handles.Tran=0;
handles.Chai=0;
set(handles.figure1,'Name','Simulation Set-up');
[X,MAP] = imread('logo.bmp');
HD=axes; image(X);
set(HD,'Units','pixels',...
  'Position',[0 0 size(X,2) size(X,1)],...
  'Units','normal');

% Update handles structure
guidata(hObject, handles);




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


% --- Outputs from this function are returned to the command line.
function varargout = SCRStart_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)
handles.Type=get(handles.listbox1,'Value');
handles.Rounds=str2num(get(handles.edit1,'String'));
handles.Incent=get(handles.checkbox1,'Value');
handles.Epoch=str2num(get(handles.edit2,'String'));

%test variables
[a,b,c]=size(handles.Training);
    
if ((a<handles.Rounds)|(b<length(handles.SupplyChain))|(c<handles.Epoch))
    disp('ERROR: Incorrect configuation of Test set, please regenerate it')
    return;
end    

SCRS(handles.Rounds,handles.Type,handles.Incent,handles.Epoch,handles.Training,handles.SupplyChain,handles.funzione,handles.File);


% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (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 listbox1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox1


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

% Hint: listbox 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 edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 import.
function import_Callback(hObject, eventdata, handles)
% hObject    handle to import (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile( ...
        {'*.rdf'}, ...
        'Select Model file');
if isequal([filename,pathname],[0,0])
        return
else
        File = fullfile(pathname,filename);
        RDF=parseRDF(File);
        handles.File=File;
        [handles.SupplyChain,handles.funzione ] = RDFtoMAT(RDF);
        guidata(hObject, handles);
        LoadOk();
        handles.Chai=1;
        if strcmp(get(handles.pushbutton1,'Enable'),'on')
           % reset the test is required
           disp('Please reload the test set by pressing the Load button')
           set(handles.pushbutton1,'Enable','off');
        else
        if (handles.Tran==1)
            set(handles.pushbutton1,'Enable','on');
        end
        end
        set(handles.pushbutton3,'Enable','on');
        set(handles.pushbutton5,'Enable','on');
end
% Update handles structure
guidata(hObject, handles);
return


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





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


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (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 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 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)
handles.Type=get(handles.listbox1,'Value');
handles.Rounds=str2num(get(handles.edit1,'String'));
handles.Incent=get(handles.checkbox1,'Value');
handles.Epoch=str2num(get(handles.edit2,'String'));

handles.Training=rand(handles.Rounds,length(handles.SupplyChain),handles.Epoch);
test=handles.Training;
handles.Tran=1;
if (handles.Chai==1)
    set(handles.pushbutton1,'Enable','on');
end    
% Update handles structure
save(strcat(handles.File,'_Test.mat'),'test');
disp('Test set generated');
guidata(hObject, handles);

% --- 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)
if (handles.Chai==1)
    load(strcat(handles.File,'_Test.mat'));
    handles.Tran=1;
    handles.Training=test;
    disp('Test set Loaded');
    if (handles.Chai==1)
        set(handles.pushbutton1,'Enable','on');
    end    
    guidata(hObject, handles);
else
    disp('Load Chain first!');
end    
    

Contact us at files@mathworks.com