Concurrent Systems Modeling using Petri Nets

Marlon Dumas

(Based on lecture material by Wil van der Aalst Eindhoven University of Technology, The http://www,workflowcourse.com)

(c) Wil van der Aalst, Eindhoven University of Technology PN-1 Behavior Modeling: State Machines

(c) Wil van der Aalst, Eindhoven University of Technology PN-2 Limitations of state machines

• Three doctors in a medical centre

• What if there are 6 doctors? • What if doctors can arrive and leave ((gso long as they are not busy)? • State explosion…

(c) Wil van der Aalst, Eindhoven University of Technology PN-3 Concurrent systems modeling

• State machines are useful to model behaviour of seqqyuential systems • But many systems are concurrent by nature • Statechart diagrams overcome some of the limitations (through compound states), but not all • Petri nets are a family of techniques for modeling systems with concurrency, communication and synchronization

(c) Wil van der Aalst, Eindhoven University of Technology PN-4 Classical • Simple technique for concurrent systems modeling – Three elements: places, transitions and arcs. – Graphical and mathematical description. – Formal semantics and allows for analysis. • Implemented in verification and simulation tools (e.g. CPN Tools, LoLa, ProM). • Once you und erst and P et ri net s, you will be be tter equipped to understand other techniques for modeling systems with concurrency (e. g. process modeling notations)

(c) Wil van der Aalst, Eindhoven University of Technology PN-5 p4 place

Elements t34 t43 transition

(name) p3

place

t23 t32

p2 (name) transition token

arc (()directed connection) t12 t21

token p1

t01 t10

p0 (c) Wil van der Aalst, Eindhoven University of Technology PN-6 free Rules

wait enter before make_picture after leave gone

occupied

• Connections are directed. • No connections between two places or two transitions. • Places may hold zero or more tokens. • First, we consider the case of at most one arc between two nodes.

(c) Wil van der Aalst, Eindhoven University of Technology PN-7 Enabled Transition

• A transition is enabled if each of its input places contains at least one token.

free

wait enter before make_picture after leave gone

occupied enabled Not Not

(c) Wil van der Aalst, Eindhoven University of Technology enabled enabled PN-8 Firing

•An enabled transition can fire (i.e., it occurs). • When it fires it consumes a token from each input place and produces a token for each

output place. free fired

wait enter before make_picture after leave gone

occupied

(c) Wil van der Aalst, Eindhoven University of Technology PN-9 “Token Game”

• In the new state, make_picture is enabled. It will fire, etc.

free

wait enter before make_picture after leave gone

occupied

(c) Wil van der Aalst, Eindhoven University of Technology PN-10 Remarks • Firing is atomic. • Multiple transitions may be enabled, but only one fires at a time (called: interleaving semantics). • The number of tokens mayyy vary if there are transitions for which the number of input places is not equal to the number of output places. • The state is represented by the distribution of tokens over pp(laces (also referred to as marking). • Any state machine can be trivially converted into a Petri net – How?

(c) Wil van der Aalst, Eindhoven University of Technology PN-11 Non-determinism p4 p4

t34 t43 t34 t43

p3 p3

t23 t32 t23 t32 transition t23 p2 fires p2

t12 t21 t12 t21

p1 p1 Two transitions are enabled but only one can fire t01 t10 t01 t10 p0 p0

(c) Wil van der Aalst, Eindhoven University of Technology PN-12 Example: Single traffic light rg

green

red go

orange

or (c) Wil van der Aalst, Eindhoven University of Technology PN-13 Two traffic lights rg

rg rg green

green green red go red go OR red go

orange orange

orange or or

or

(c) Wil van der Aalst, Eindhoven University of Technology PN-14 Problem

(c) Wil van der Aalst, Eindhoven University of Technology PN-15 Solution

rg1 rg2

g1 g2

r1 go1 x go2 r2

How to make o1 o2 them alternate?

or1 or2 (c) Wil van der Aalst, Eindhoven University of Technology PN-16 Playing the “Token Game” on the Internet

• FLASH animations: http://is.tm .tue .nl/staff/wvdaalst/workflowcourse/l ecture2.htm • Applet to build your own Petri nets and execute them: http://is.tm .tue .nl/staff/wvdaalst/workflowcourse/ pn_applet/pn_applet.htm

(c) Wil van der Aalst, Eindhoven University of Technology PN-17 Exercise: Doctor’s scenario in Petri nets

Case 1: Patients arrive and leave, number of doctors fixed Case 2: Patients arrive and leave, doctors arrive and leave (but only leave when they are free) Case 3: When patients arrive, they are classified into simple and complex cases . Simple cases require only a doctor , complex cases require a doctor and a nurse. (Assume doctors and nurses do not arrive nor leave)

(c) Wil van der Aalst, Eindhoven University of Technology PN-18 Exercise: Train system

• Consider a circular railroad system with 4 (one- way) tracks (,,,)(1,2,3,4) and 2 trains ( (,)A,B). No two trains should be at the same track at the same time and we do not care about the identities of the two trains. http://is.tm.tue.nl/staff/wvdaalst/workflowcourse/ exercises/exercise2_3.htm

(c) Wil van der Aalst, Eindhoven University of Technology PN-19 Multiple arcs connecting two nodes

• The number of arcs between an input place and a transition determines the number of tokens required to be enabled. • The number of arcs determines the number of tokens to be consumed/produced. free

wait enter before make_picture after leave gone

(c) Wil van der Aalst, Eindhoven University of Technology PN-20 Example: Ball game

red black

rb

rr bb

Which transition(()s) is/are enabled?

(c) Wil van der Aalst, Eindhoven University of Technology PN-21 Exercise: Manufacturing a chair

• Model the manufacturing of a chair from its components: 2 front legs, 2 back legs, 3 cross bars, 1 seat frame, and 1 seat cushion as a Petri net. • Select some sensible assembly order.

(c) Wil van der Aalst, Eindhoven University of Technology PN-22 Exercise: Burning alcohol.

• Model C2H5OH + 3 * O2 => 2 * CO2 + 3 * H2O • Assume that there are two steps: first each molecule is disassembled into its atoms and then these atoms are assembled into other molecules.

(c) Wil van der Aalst, Eindhoven University of Technology PN-23 Exercise: Manufacturing a car

• Model the production process shown in the Bill- Of-Materials. car subassembly2 engine 2 chair subassembly1 4 chassis wheel

(c) Wil van der Aalst, Eindhoven University of Technology PN-24 You should be able to ... • ElihtiPtitExplain what is a Petri net an dhtd what are thbithe basic elements of (plain) Petri nets • Play a tktoken game on a P Ptietri net . • Model simple concurrent systems using Petri nets.

(c) Wil van der Aalst, Eindhoven University of Technology PN-25