The GPenSIM code for the examples given in the Article:
“Performance Evaluation of Discrete-event Systems with GPenSIM”
1 University of Stavanger, Faculty of Science and Technology, Norway; reggie.davidrajuh@uis.no
2 Silesian University of Technology, Faculty of Mechanical Engineering, Gliwice, Poland; bozena.skolud@polsl.pl
3 Silesian University of Technology, Faculty of Mechanical Engineering, Gliwice, Poland; damian.krenczyk@polsl.pl
* Correspondence: reggie.davidrajuh@uis.no
Example-1: The Event Graph
MSF:
%%%% MSF: the main simulation file %%%%%%%%%%%%%%%%%%%%%
clear all; clc;
global global_info
global_info.STOP_AT = 100; % stop simulation after 100 TU
pns = pnstruct('fms_pdf'); % declare the PDF
% declare the firing times of the transitons
dyn.ft = {'tC1',10,'tC2',10, 'tM1',5,'tM2',10,'tAS',7,...
'tPS',8, 'tPCK',3, 'allothers',2};
% declare the initial markings
dyn.m0 = {'pC1',1,'pC2',1, 'pR1',1,'pR2',1,'pR3',1,'pR4',1, ...
'po1AS',1,'po2AS',1};
% combine static and dynamic parts to form the Petri net
pni = initialdynamics(pns, dyn);
mincyctime(pni, 0.07); % find the minimum cycle of event graph
PDF:
function [png] = fms_pdf()
png.PN_name = 'Event Graph model of FMS';
%%%%%%% set of places
png.set_of_Ps = {'pC1','pC2', 'pR1','pR2','pR3','pR4', ...
'poC1','poC2','piM1','piM2','poM1','poM2',...
'pi1AS','pi2AS','po1AS','po2AS',...
'piPS','poAS','piCK'};
%%%%%%% set of transitions
png.set_of_Ts = {'tC1','tC2','tM1','tM2','tM1AS','tM2AS',...
'tAS','tAP','tPS', 'tC1M1','tC2M2','tPCK'};
%%%%%%% set of arcs
png.set_of_As = {...
'pC1','tC1',1, 'tC1','poC1',1, ... % tC1
'pR1','tC1M1',1, 'poC1','tC1M1',1,... % tC1M1 inputs
'tC1M1','piM1',1, 'tC1M1','pC1',1, ... % tC1M1 outputs
'piM1','tM1',1, 'tM1','poM1',1, ... % tM1
'poM1','tM1AS',1, 'po1AS','tM1AS',1, ... % tM1AS inputs
'tM1AS','pi1AS',1, 'tM1AS','pR1',1,... % tM1AS output
...
'pC2','tC2',1, 'tC2','poC2',1, ... % tC2
'pR2','tC2M2',1, 'poC2','tC2M2',1,... % tC2M2
'tC2M2','piM2',1, 'tC2M2','pC2',1,... % tC2M2
'piM2','tM2',1, 'tM2','poM2',1, ... % tM2
'poM2','tM2AS',1, 'po2AS','tM2AS',1, ... % tM2AS inputs
'tM2AS','pi2AS',1, ... % tM2AS output
...
'pi1AS','tAS',1, 'pi2AS','tAS',1,'pR3','tAS',1,... % tAS inputs
'tAS','po1AS',1, 'tAS','po2AS',1, ... % tAS outputs
'tAS','poAS',1, 'tAS','pR2',1, ... % tAS outputs
'poAS','tAP',1, 'tAP','piPS',1, ... % tAP
'piPS','tPS',1, 'pR4','tPS',1, ... % tPS inputs
'tPS','pR4',1, 'tPS','piCK',1, ... % tPS outputs
'piCK','tPCK',1, 'tPCK','pR3',1}; % tPCK
Example-1: The AOPN model
PDF:
% PDF: 'fms_AOPN_pdf.m'
function [png] = fms_AOPN_pdf()
png.PN_name = 'AOPN model of a FMS';
png.set_of_Ps = {'pIB1','pIB2', 'pOB',... %input & output buffers
'poC1','poC2','piM1','piM2','poM1', 'poM2', ...%intermediate buffers
'pi1AS','pi2AS','poAS', 'piPS','piCK'}; %intermediate buffers
png.set_of_Ts = {'tC1','tC2', 'tC1M1','tC2M2', 'tM1','tM2',...
'tM1AS','tM2AS','tAS', 'tAP', 'tPS', 'tPCK'};
png.set_of_As = {'pIB1','tC1',1, 'tC1','poC1',1, ... % tC1 connections
'poC1','tC1M1',1, 'tC1M1','piM1',1, ... % tC1M1 connections
'piM1','tM1',1, 'tM1','poM1',1,... % tM1 connections
'poM1','tM1AS',1, 'tM1AS','pi1AS',1,... % tM1AS connections
'pIB2','tC2',1, 'tC2','poC2',1, ... % tC2 connections
'poC2','tC2M2',1, 'tC2M2','piM2',1,... % tC2M2 connections
'piM2','tM2',1, 'tM2','poM2',1,... % tM2 connections
'poM2','tM2AS',1, 'tM2AS','pi2AS',1,... % tM2AS connections
'pi1AS','tAS',1,'pi2AS','tAS',1, 'tAS','poAS',1,... % tAS connections
'poAS','tAP',1, 'tAP','piPS',1,... % tAP connections
'piPS','tPS',1, 'tPS','piCK',1, ... % tPS connections
'piCK','tPCK',1, 'tPCK','pOB',1}; % tPCK connections
MSF:
% MSF: 'fms_AOPN.m'
% AOPN model of a Flexible Manufacturing System
global global_info
global_info.STOP_AT = 300;
pns = pnstruct('fms_AOPN_pdf'); % the PDF file
dp.m0 = {'pIB1',3,'pIB2',3}; % initial markings on the places
dp.ft = {'tC1',10,'tC2',10,'tM1',5,'tM2',10,... % firing times
'tAS',7,'tPS',8, 'tPCK',3, 'allothers',2}; % firing times
dp.re = {'C1',1,inf,'C2',1,inf, 'M1',1,inf,'M2',1,inf, ... % resources
'R1',1,inf,'R2',1,inf,'R3',1,inf,'R4',1,inf}; % resources
pni = initialdynamics(pns, dp); % initial run-time PetriNet
sim = gpensim(pni); % simulation iterations
prnschedule(sim); % print the simulation results
COMMON_PRE:
function [fire, transition] = COMMON_PRE(transition)
switch transition.name
case 'tC1', granted = requestSR({'C1',1});
case 'tC1M1', granted = requestSR({'R1',1});
case 'tM1', granted = requestSR({'M1',1});
case 'tC2', granted = requestSR({'C2',1});
case 'tC2M2', granted = requestSR({'R2',1});
case 'tM2', granted = requestSR({'M2',1});
case 'tAS', granted = requestSR({'R3',1});
case 'tPS', granted = requestSR({'R4',1});
case {'tM1AS','tM2AS', 'tAP','tPCK'}, granted = 1; % request nothing
end % switch
fire = granted; % fire if the required resource is granted
COMMON_POST:
function [] = COMMON_POST(transition)
switch transition.name
case 'tC1' % do nothing
case 'tC1M1', release('tC1'); % release resource acquired by tC1
case 'tM1', release(); % release resource acquired by tM1
case 'tM1AS', release('tC1M1'); % release resource acquired by tC1M1
case 'tC2' % do nothing
case 'tC2M2', release('tC2'); % release resource acquired by tC2
case 'tM2', release(); % release resource acquired by tM2
case 'tM2AS'% do nothing
case 'tAS', release('tC2M2');
case 'tAP' % do nothing
case 'tPS', release(); % 'R4'
case 'tPCK', release('tAS');
end % switch
n = ntokens('pOB'); % get the number of tokens in pOB
if eq(n,3), global_info.STOP_SIMULATION = 1; end % stop if n==3