Table Of ContentReggie Davidrajuh
Modeling Discrete-Event
Systems with GPenSIM
An Introduction
123
ReggieDavidrajuh
Department ofElectrical Engineering
andComputer Science
University of Stavanger
Stavanger
Norway
Additional material tothis bookcanbedownloaded from http://extras.springer.com.
ISSN 2191-530X ISSN 2191-5318 (electronic)
SpringerBriefs inApplied SciencesandTechnology
ISBN978-3-319-73101-8 ISBN978-3-319-73102-5 (eBook)
https://doi.org/10.1007/978-3-319-73102-5
LibraryofCongressControlNumber:2017964442
©TheAuthor(s)2018
Preface
Petrinetisbeingwidelyacceptedbytheresearchcommunityasatoolformodeling
and simulation of discrete-event systems. There are a number of Petri net tools
available for academic and commercial use. These tools are advanced tools pow-
erful enough to model complex and large systems. In this book, a new Petri net
simulator called General Purpose Petri net Simulator (GPenSIM) is introduced.
GPenSIM runs on MATLAB platform. GPenSIM is designed with three specific
goals:(1)modeling,simulation,performanceanalysis,andcontrolofdiscrete-event
systems,(2)atoolthatiseasytouseandextend,and(3)allowingPetrinetmodels
to be integrated with other MATLAB toolboxes (e.g., Fuzzy Logic, Control
Systems).
Thisbookiswrittenasabooktoassiststudentsandpracticingengineersdevelop
mathematical models of discrete-event systems with GPenSIM. Thus, Petri net
theory is kept to a minimum, and it is expected that the students know some Petri
net theory beforehand. To help the readers grasp the modeling basics quickly and
easily, there are many examples worked out in this book. These examples are
simple and easy to follow. Both the simulator GPenSIM and codes for examples
(M-files) can be downloaded from the companion website: http://www.davidrajuh.
net/gpensim.
ThisbookisbasedonthenewversionofGPenSIM,version10.Theversion10
is the first stable version of GPenSIM, which is thoroughly checked for bugs. In
addition, there are some changes in input and output parameters of some of the
GPenSIMfunctions.Duetothesechanges,unfortunately,version10isnotupward
compatible with its previous versions.
ThisbookwaswrittenwhileIwasstayingattheSilesianUniversityofTechnology,
Poland,formysabbaticalleave.IwanttothanktheInstituteofEngineeringProcesses
Automation and Integrated Manufacturing Systems of the Faculty of Mechanical
Engineering, for hosting me, especially Professor Dr. hab. inz Bozena Skolud and
Dr.hab.inzDamianKrenczykforalltheirhelpduringmysabbaticalstayinPoland.
Finally, I want to thank my wife Ruglin and my daughter Ada for their love and
patiencewithme.
I hope you enjoy the book!
Stavanger, Norway Reggie Davidrajuh
October 2017
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 What Is GPenSIM?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Petri nets: Basic Concepts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.1 P/T Petri net . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.2 Formal Definition of P/T Petri nets . . . . . . . . . . . . . . . . 3
1.2.3 Input and Output Places of a Transition. . . . . . . . . . . . . 3
1.2.4 Enabled Transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Petri net Dynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.1 Time and Petri net . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.2 Coverability Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4 A Simple P/T Petri net Model. . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5 Timed Petri net. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.6 Atomicity and Virtual Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.7 Defining Timed Petri net (TPN). . . . . . . . . . . . . . . . . . . . . . . . . 8
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2 Modeling with GPenSIM: Basic Concepts. . . . . . . . . . . . . . . . . . . . . 9
2.1 Separating the Static and Dynamic Details . . . . . . . . . . . . . . . . . 9
2.2 Pre-processors and Post-processors . . . . . . . . . . . . . . . . . . . . . . 9
2.2.1 Using Pre-processor and Post-processor. . . . . . . . . . . . . 10
2.3 Global Info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.4 Integrating with MATLAB Environment . . . . . . . . . . . . . . . . . . 11
2.5 Creating an Untimed Petri net Model with GPenSIM . . . . . . . . . 12
2.5.1 Example-01: A Simple P/T (Untimed) Petri net . . . . . . . 12
2.5.2 Step-1: Defining the Petri net Graph . . . . . . . . . . . . . . . 12
2.5.3 Step-2: Creating the Pre-processor
and Post-processor Files . . . . . . . . . . . . . . . . . . . . . . . . 13
2.5.4 Step-3: The Main Simulation File: Assigning
the Initial Dynamics. . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.5.5 The Simulations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.5.6 Viewing the Simulation Results with ‘Prnss’ . . . . . . . . . 14
2.6 Summary: Creating a Simple Untimed Petri net Model. . . . . . . . 16
2.7 Static PN Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.8 Assigning Names to Places and Transitions . . . . . . . . . . . . . . . . 17
2.9 GPenSIM Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.10 Creating a Timed Petri net . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.10.1 Example-02: A Simple Timed Petri net . . . . . . . . . . . . . 18
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3 Pre-processor and Post-processor Files. . . . . . . . . . . . . . . . . . . . . . . 23
3.1 The Processor Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.2 Structure of a Pre-processor File . . . . . . . . . . . . . . . . . . . . . . . . 24
3.2.1 Example-03: Pre-processor Example . . . . . . . . . . . . . . . 25
3.2.2 Example-04: COMMON_PRE Example . . . . . . . . . . . . 29
3.3 Implementing Preference Through Pre-processors. . . . . . . . . . . . 30
3.3.1 Example-05: Implementing Preference Through
Pre-processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.4 Post-processors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.4.1 Example-06: Alternating Firing Using Binary
Semaphore. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.5 Common Processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.6 Structure of COMMON_PRE and COMMON_POST Files. . . . . 35
3.6.1 Example-07: Alternating Firing with COMMON
Processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.7 Summary: COMMON Processors Versus Specific Processors . . . 37
3.7.1 Example-08: Mixing COMMON and Specific
Processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.8 Combining COMMON and Specific Processors . . . . . . . . . . . . . 39
3.9 Using Processors as Test Probe . . . . . . . . . . . . . . . . . . . . . . . . . 40
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4 Analysis of Petri nets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.1 Coverability Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.1.1 Example-09: Cotree with Finite States. . . . . . . . . . . . . . 44
4.1.2 Example-10: Cotree with Infinite States. . . . . . . . . . . . . 46
4.2 Firing Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.2.1 Example-11: Verifying T-Invariants. . . . . . . . . . . . . . . . 50
4.2.2 Example-12: Alternating Firing with Firing Sequence. . . 52
4.2.3 Example-13: Crosstalk Algorithm . . . . . . . . . . . . . . . . . 53
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5 Optimizing Simulations with GPenSIM . . . . . . . . . . . . . . . . . . . . . . 59
5.1 Global Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.1.1 Example-14: DELTA_TIME Demo. . . . . . . . . . . . . . . . 60
5.2 ‘MAX_LOOP’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5.2.1 Example-15: MAX_LOOP . . . . . . . . . . . . . . . . . . . . . . 63
5.2.2 What Are Loops?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
5.3 ‘PRINT_LOOP_NUMBER’ . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
5.4 ‘STARTING_AT’. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.4.1 ‘STOP_AT’. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.5 ‘STOP_SIMULATION’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
5.5.1 Example-16: OPTION
‘STOP_SIMULATION’ Demo . . . . . . . . . . . . . . . . . . . 68
5.6 Using Hourly Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
5.6.1 Example-17: Hourly Clock . . . . . . . . . . . . . . . . . . . . . . 70
5.7 Summary: The OPTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
5.8 Generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
5.8.1 Example-18: Generator for Token Generation . . . . . . . . 75
5.9 Stochastic Firing Times and Variable Firing Times. . . . . . . . . . . 77
5.9.1 Example-19: Stochastic Firing Times with Advanced
Stat. Toolbox. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
5.9.2 Example-20: Stochastic Firing Times WO Advanced
Stat. Toolbox. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
5.10 Achieving Variable Firing Time . . . . . . . . . . . . . . . . . . . . . . . . 79
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
6 Petri net Extensions and Restrictions . . . . . . . . . . . . . . . . . . . . . . . . 81
6.1 Petri net Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
6.2 Petri net Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
6.2.1 Example-21: Petri net Class . . . . . . . . . . . . . . . . . . . . . 82
6.3 Inhibitor Arcs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
6.3.1 Firing Rule When Inhibitor Arcs Are Used . . . . . . . . . . 84
6.3.2 Example-22: Batch Processing . . . . . . . . . . . . . . . . . . . 85
6.4 Coverability Tree for Petri nets with Inhibitor Arcs . . . . . . . . . . 86
6.4.1 Example-23: Coverability Tree of a Petri net with
Inhibitor Arcs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
6.5 Prioritizing Transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
6.5.1 Priorities of Transitions . . . . . . . . . . . . . . . . . . . . . . . . 89
6.5.2 Example-24: Alternating Firing with Priority . . . . . . . . . 90
6.5.3 Example-25: Priority Decrement Example . . . . . . . . . . . 92
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7 Performance Evaluation of Discrete-Event Systems . . . . . . . . . . . . . 95
7.1 Measuring Activation Timing . . . . . . . . . . . . . . . . . . . . . . . . . . 95
7.1.1 Example-26: Measuring Activation Time. . . . . . . . . . . . 96
7.1.2 Example-27: Measuring Activation Time. . . . . . . . . . . . 97
7.2 Minimum Cycle Time in Marked Graphs. . . . . . . . . . . . . . . . . . 98
7.2.1 Example-28: Finding Minimal Cycle Time . . . . . . . . . . 99
7.3 Expected Performance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
7.3.1 Example-29: Finding Bottleneck in an Enterprise
Information System . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
8 Interfacing with the External Environment . . . . . . . . . . . . . . . . . . . 105
8.1 Internal Data Structures of the Basic Petri net Elements . . . . . . . 105
8.1.1 Example-30: Data Structures. . . . . . . . . . . . . . . . . . . . . 105
8.1.2 The Data Structure of PN—The Global Petri
net Run-Time Structure . . . . . . . . . . . . . . . . . . . . . . . . 107
8.1.3 The Data Structure of Place . . . . . . . . . . . . . . . . . . . . . 108
8.1.4 The Data Structure of Transition. . . . . . . . . . . . . . . . . . 109
8.2 PNML-2-GPenSIM Converter . . . . . . . . . . . . . . . . . . . . . . . . . . 110
8.2.1 Example-31: Generating GPenSIM Files
from a PNML File . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
8.3 Avoiding PDF Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
8.3.1 Example-32: A Simple Model Without PDF . . . . . . . . . 115
8.3.2 Example-33: A Large Cyclic Example. . . . . . . . . . . . . . 117
8.4 Interfacing with External Hardware . . . . . . . . . . . . . . . . . . . . . . 119
8.4.1 Example-34: Switching Lights on a LEGO Mindstorm
NXT Robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
8.5 Interfacing with Graph Algorithms Toolbox. . . . . . . . . . . . . . . . 125
8.5.1 Example-35: Converting a Bipartite Petri net
into a Homogeneous Digraph . . . . . . . . . . . . . . . . . . . . 125
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
9 Structural Invariants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
9.1 GPenSIM Functions for Structural Properties . . . . . . . . . . . . . . . 129
9.1.1 Example-36: Finding Siphons and Minimal Siphons. . . . 130
9.1.2 Example-37: Finding Traps and Minimal Traps . . . . . . . 131
9.1.3 Example-38: Finding P-Invariants and T-Invariants . . . . 132
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Appendix: Frequently Used GPenSIM Functions.. .... .... ..... .... 135
Index .... .... .... .... .... ..... .... .... .... .... .... ..... .... 137
Chapter 1
Introduction
This chapter introduces Petri nets and the General Purpose Petri net Simulator
(GPenSIM). Petri net is widely accepted for modeling and simulation of
discrete-event systems, due to its graphical representation and the well-defined
semantics.GPenSIMdefinesaPetrinetlanguageonMATLABplatform.GPenSIM
is also a simulator with which Petri net models can be developed, simulated, and
analyzed. GPenSIM is easy to learn, use, and extend.
1.1 What Is GPenSIM?
GPenSIM defines a Petri net language for modeling and simulation of
discrete-event systems on MATLAB platform. GPenSIM is developed by the
author of this book. GPenSIM is also a simulator with which Petri net models can
bedevelopedand simulated. Inaddition, GPenSIMcanalso beusedasareal-time
controller. Even though GPenSIM is a new simulator, it is being used by many
researchers around the world. Recently, a team of Australian researchers chose
GPenSIMastheidealtoolformodelingandsimulationofmarkedgraph(aPetrinet
class),becauseofGPenSIM’sflexibilityinbeingabletocontrolthesystemviathe
model (Cameron et al. 2015). For the same reason, Tilbury laboratory at the
University of Michigan also selected GPenSIM as the tool for modeling manu-
facturing system (Lopez et al. 2017).
GPenSIMsupportsmany Petri nets extensions, suchas inhibitorarcs, transition
priorities, enabling functions, color extension. In addition, it provides a collection
of functions for performance analysis. Because of its flexibility, it is also easy to
implement any other Petri net extensions with GPenSIM, e.g., Attributed Hybrid
Dynamical net (Lopez et al. 2017), Cohesive Place-Transition Nets with inhibitor
arcs (Davidrajuh and Saadallah 2016).
2 1 Introduction
1.2 Petri nets: Basic Concepts
ThissectionintroducesthebasicconceptsofPetrinetsanditsrelationtotime.This
section gives only a brief introduction. For a formal study of Petri nets, interested
readersarereferredtobookslikeCassandrasandLafortune(2009),DiCesareetal.
(1993), Murrata (1989), and Peterson (1981).
1.2.1 P/T Petri net
A P/T Petri net contains two types of elements: places and transitions; places
generally represent passive elements (such as input and output buffers, conveyor
belts)andtransitionsrepresentactiveelements(suchasmachines,robots).Petrinet
isadirected bipartitegraph meaning aplace canonly beconnectedtotransition(s)
and a transition to place(s); the connections between places and transitions are
termed as arcs.
In addition to places, transitions, and arcs, Petri net also has tokens. Tokens
represent objects that can flow around in a network of nodes, e.g., materials in a
material flow system, data (or information) in an information flow. Places hold
tokens; tokens move from place to place via the arcs. Tokens are shown as black
spotsinaPetrinet.Ifaplacehasalargenumberoftokens,then itiscustomaryto
show the number of tokens with numerals than black spots.
The arcs that connect places to transitions and transitions to places have the
default weight of one. If an arc has a weight that is greater than unity, then the
weight is shown in the arc. The arc weight represents the capacity of the arc to
transport a number of tokens simultaneously at a time.
Figure 1.1showsthreeplacesp ,p ,andp .Thesethreeplaceshold4,3,and1
1 2 3
tokens, respectively. When a transition fires, a number of tokens are taken (‘con-
sumed’) from the input places and new tokens are deposited (‘produced’) into the
output places; the arc weights determine the number of tokens consumed and
produced.Foratransitiontobeabletofire,thenumberoftokensintheinputplaces
must be equal or larger than the weights of the arcs connecting the input places to
the transition. The transition will then become able to fire (enabled transition).
Figure 1.2shows thestateofthesamplePetri netfrom Fig. 1.1 afterthetransition
t has fired once.
1
Fig.1.1 SamplePetrinet
p 4
1 t
1
1 p
3
2
p 3
2