Petri Nets
ee249 Fall 2000
Marco Sgroi
Models Of Computation
for reactive systems
• Main MOCs:
– Communicating Finite State Machines
– Dataflow Process Networks
– Discrete Event
– Codesign Finite State Machines
– Petri Nets
• Main languages:
– StateCharts
– Esterel
– Dataflow networks 2
1
EE249: Design of Embedded System (corrections) ASV/LL
Outline
• Petri nets
– Introduction
– Examples
– Properties
– Analysis techniques
– Scheduling
2
EE249: Design of Embedded System (corrections) ASV/LL
p1 t1 2
p4
3
t3
5
p3
Petri Net
• A PN (N,M0) is a Petri Net Graph N
– places: represent distributed state by holding tokens
• marking (state) M is an n-vector (m1,m2,m3… ), where mi is the non-
negative number of tokens in place pi.
• initial marking (M0) is initial state
– transitions: represent actions/events
• enabled transition: enough tokens in predecessors
• firing transition: modifies marking
p2 t2
• … and an initial marking M0. t1 2
p1 p4
3
Places/Transition: conditions/events t3 6
p3
3
EE249: Design of Embedded System (corrections) ASV/LL
2 2
2
2
3
3 7
t2
t5
t3 t4
8
t6
4
EE249: Design of Embedded System (corrections) ASV/LL
t1
Concurrency
t2
t5
t3 t4
9
t6
t2
t5
Causality, sequencing
t3 t4
10
t6
5
EE249: Design of Embedded System (corrections) ASV/LL
t1
t2
t5
Choice,
t3 t4 conflict
11
t6
t2
t5
Choice,
t3 t4 conflict
12
t6
6
EE249: Design of Embedded System (corrections) ASV/LL
Confusion
• t1 and t2 are concurrent but their firing order is not
irrelevant for conflict resolution (not local choice)
• From (1,1,0,0,0):
– solving a conflict (t1,t2) (0,0,0,0,1),(0,0,1,1,0)
– not solving a conflict (t2,t1) (0,0,1,1,0)
p1 t1 p3
t3 p5
p2 t2 p4
13
Communication Protocol
P1 P2
Send Ack
Receive Ack
14
7
EE249: Design of Embedded System (corrections) ASV/LL
Communication Protocol
P1 P2
Send Ack
Receive Ack
15
Communication Protocol
P1 P2
Send Ack
Receive Ack
16
8
EE249: Design of Embedded System (corrections) ASV/LL
Communication Protocol
P1 P2
Send Ack
Receive Ack
17
Communication Protocol
P1 P2
Send Ack
Receive Ack
18
9
EE249: Design of Embedded System (corrections) ASV/LL
Communication Protocol
P1 P2
Send Ack
Receive Ack
19
Producer-Consumer Problem
Produce
Buffer
Consume
20
10
EE249: Design of Embedded System (corrections) ASV/LL
Producer-Consumer Problem
Produce
Buffer
Consume
21
Producer-Consumer Problem
Produce
Buffer
Consume
22
11
EE249: Design of Embedded System (corrections) ASV/LL
Producer-Consumer Problem
Produce
Buffer
Consume
23
Producer-Consumer Problem
Produce
Buffer
Consume
24
12
EE249: Design of Embedded System (corrections) ASV/LL
Producer-Consumer Problem
Produce
Buffer
Consume
25
Producer-Consumer Problem
Produce
Buffer
Consume
26
13
EE249: Design of Embedded System (corrections) ASV/LL
Producer-Consumer Problem
Produce
Buffer
Consume
27
Producer-Consumer Problem
Produce
Buffer
Consume
28
14
EE249: Design of Embedded System (corrections) ASV/LL
Producer-Consumer Problem
Produce
Buffer
Consume
29
Producer-Consumer Problem
Produce
Buffer
Consume
30
15
EE249: Design of Embedded System (corrections) ASV/LL
Producer-Consumer Problem
Produce
Buffer
Consume
31
Producer-Consumer Problem
Produce
Buffer
Consume
32
16
EE249: Design of Embedded System (corrections) ASV/LL
Producer-Consumer Problem
Produce
Buffer
Consume
33
Producer-Consumer Problem
Produce
Buffer
Consume
34
17
EE249: Design of Embedded System (corrections) ASV/LL
Inhibitor arcs
35
PN properties
• Behavioral: depend on the initial marking (most
interesting)
– Reachability
– Boundedness
– Schedulability
– Liveness
– Conservation
• Structural: do not depend on the initial marking
(often too restrictive)
– Consistency
– Structural boundedness 36
18
EE249: Design of Embedded System (corrections) ASV/LL
Reachability
• Marking M is reachable from marking M0 if there
exists a sequence of firings σ = M0 t1 M1 t2 M2… M
that transforms M0 to M.
• The reachability problem is decidable.
p2
t2
p1 t1 p4
Μ 0 = (1,0,1,0)
t3
M1 = (1,0,0,1)
t3
p3 t2
Μ 0 = (1,0,1,0)
M = (1,1,0,0)
M = (1,1,0,0) 37
Liveness
• Liveness: from any marking any transition can
become fireable
– Liveness implies deadlock freedom, not viceversa
Not live
38
19
EE249: Design of Embedded System (corrections) ASV/LL
Liveness
• Liveness: from any marking any transition can
become fireable
– Liveness implies deadlock freedom, not viceversa
Not live
39
Liveness
• Liveness: from any marking any transition can
become fireable
– Liveness implies deadlock freedom, not viceversa
Deadlock-free
40
20
EE249: Design of Embedded System (corrections) ASV/LL
Liveness
• Liveness: from any marking any transition can
become fireable
– Liveness implies deadlock freedom, not viceversa
Deadlock-free
41
Boundedness
• Boundedness: the number of tokens in any place
cannot grow indefinitely
– (1-bounded also called safe)
– Application: places represent buffers and registers (check
there is no overflow)
Unbounded
42
21
EE249: Design of Embedded System (corrections) ASV/LL
Boundedness
• Boundedness: the number of tokens in any place
cannot grow indefinitely
– (1-bounded also called safe)
– Application: places represent buffers and registers (check
there is no overflow)
Unbounded
43
Boundedness
• Boundedness: the number of tokens in any place
cannot grow indefinitely
– (1-bounded also called safe)
– Application: places represent buffers and registers (check
there is no overflow)
Unbounded
44
22
EE249: Design of Embedded System (corrections) ASV/LL
Boundedness
• Boundedness: the number of tokens in any place
cannot grow indefinitely
– (1-bounded also called safe)
– Application: places represent buffers and registers (check
there is no overflow)
Unbounded
45
Boundedness
• Boundedness: the number of tokens in any place
cannot grow indefinitely
– (1-bounded also called safe)
– Application: places represent buffers and registers (check
there is no overflow)
Unbounded
46
23
EE249: Design of Embedded System (corrections) ASV/LL
Conservation
• Conservation: the total number of tokens in the
net is constant
Not conservative
47
Conservation
• Conservation: the total number of tokens in the
net is constant
Not conservative
48
24
EE249: Design of Embedded System (corrections) ASV/LL
Conservation
• Conservation: the total number of tokens in the
net is constant
Conservative
2
49
Analysis techniques
50
25
EE249: Design of Embedded System (corrections) ASV/LL
Incidence Matrix
t2
p1 t1 p2 p3
t1 t2 t3
t3 -1 0 0 p1
A= 1 1 -1 p2
0 -1 1 p3
State equations
• E.g. reachability of M =|0 0 1|T from M0 = |1 0 0|T
t2
p1 t1 p2 p3 -1 0 0
A= 1 1 -1
0 -1 1
t3
1 0 1 -1 0 0 1
v1 = 0 0 = 0 + 1 1 -1 0
1 1 0 0 -1 1 1
26
EE249: Design of Embedded System (corrections) ASV/LL
t3
t1
2
2
Firing vector: (1,2,2) Deadlock!!
53
t2
p1 t1 p2 p3 -1 0 0
A= 1 1 -1
0 -1 1
t3 54
27
EE249: Design of Embedded System (corrections) ASV/LL
Application of T-invariants
• Scheduling
– Cyclic schedules: need to return to the initial state
i *k2 + o
*k1
T-invariant: (1,1,1,1,1)
Schedule: i *k2 *k1 + o
55
• Solutions of yA = 0
S-invariants
– sets of places whose weighted total token count does not
change after the firing of any transition (y M = y M’)
– e.g. y =| 1 1 1 |T
t2
p1 t1 p2 p3 -1 1 0
AT= 0 1 -1
0 -1 1
t3
56
28
EE249: Design of Embedded System (corrections) ASV/LL
Application of S-invariants
57
• Extremely efficient
(polynomial in the size of the net)
• Generally provide only necessary or sufficient
information
• Excellent for ruling out some deadlocks or
otherwise dangerous conditions
• Can be used to infer structural boundedness
58
29
EE249: Design of Embedded System (corrections) ASV/LL
Coverability Tree
• Build a (finite) tree representation of the markings
Karp-Miller algorithm
• Label initial marking M0 as the root of the tree and tag it as new
• While new markings exist do:
– select a new marking M
– if M is identical to a marking on the path from the root to M, then tag M as
old and go to another new marking
– if no transitions are enabled at M, tag M dead-end
– while there exist enabled transitions at M do:
• obtain the marking M’that results from firing t at M
• on the path from the root to M if there exists a marking M’’such that
M’(p)>=M’’(p) for each place p and M’ is different from M’’, then replace M’(p)
by ω for each p such that M’(p) >M’’(p)
• introduce M’as a node, draw an arc with label t from M to M’ and tag M’as
new. 59
Coverability Tree
• Boundedness is decidable
1000
with coverability tree
t2
p1 t1 p2 p3
p4
t3
60
30
EE249: Design of Embedded System (corrections) ASV/LL
Coverability Tree
• Boundedness is decidable
1000
with coverability tree
t1
t2 0100
p1 t1 p2 p3
p4
t3
61
Coverability Tree
• Boundedness is decidable
1000
with coverability tree
t1
0100
t2
p1 t1 p2 p3 t3
0011
p4
t3
62
31
EE249: Design of Embedded System (corrections) ASV/LL
Coverability Tree
• Boundedness is decidable
1000
with coverability tree
t1
t2 0100
p1 t1 p2 p3 t3
0011
t2
p4 0101
t3
63
Coverability Tree
• Boundedness is decidable
1000
with coverability tree
t1
0100
t2
p1 t1 p2 p3 t3
0011
t2
t3 p4 010ω
32
EE249: Design of Embedded System (corrections) ASV/LL
Coverability Tree
• Boundedness is decidable
1000
with coverability tree
t1
t2 0100
p1 t1 p2 p3 t3
0011
t2
t3 p4 010ω
Reachability graph
t2
p1 t1 p2 p3 100
t3
33
EE249: Design of Embedded System (corrections) ASV/LL
Reachability graph
t2
p1 t1 p2 p3 100
t1
010
t3
Reachability graph
t2
p1 t1 p2 p3 100
t1
010
t3
t3
001
34
EE249: Design of Embedded System (corrections) ASV/LL
Reachability graph
t2
p1 t1 p2 p3 100
t1
010
t3
t2 t3
001
35
EE249: Design of Embedded System (corrections) ASV/LL
71
36
EE249: Design of Embedded System (corrections) ASV/LL
73
Free-Choice (FC)
t1
t2
Confusion (not-Free-Choice) Extended Free-Choice
Free-Choice: the outcome of a choice depends on the
value of a token (abstracted non-deterministically)
rather than on its arrival time.
Easy to analyze 74
37
EE249: Design of Embedded System (corrections) ASV/LL
Free-Choice nets
• Introduced by Hack (‘72)
• Extensively studied by Best (‘86) and Desel and
Esparza (‘95)
• Can express concurrency, causality and choice without
confusion
• Very strong structural theory
– necessary and sufficient conditions for liveness and safeness,
based on decomposition
– concurrency, causality and choice relations are mutually
exclusive
– exploits duality between MG and SM 75
38
EE249: Design of Embedded System (corrections) ASV/LL
77
78
39
EE249: Design of Embedded System (corrections) ASV/LL
79
80
40
EE249: Design of Embedded System (corrections) ASV/LL
81
MG reductions
• The set of all reductions yields a cover of MG
components (T-invariants)
82
41
EE249: Design of Embedded System (corrections) ASV/LL
MG reductions
• The set of all reductions yields a cover of MG
components (T-invariants)
83
84
42
EE249: Design of Embedded System (corrections) ASV/LL
85
43
EE249: Design of Embedded System (corrections) ASV/LL
87
Hack’s theorem
88
44
EE249: Design of Embedded System (corrections) ASV/LL
Hack’s theorem
89
Hack’s theorem
90
45
EE249: Design of Embedded System (corrections) ASV/LL
Hack’s theorem
91
Hack’s theorem
92
46
EE249: Design of Embedded System (corrections) ASV/LL
Hack’s theorem
93
Hack’s theorem
94
47
EE249: Design of Embedded System (corrections) ASV/LL
Hack’s theorem
95
Hack’s theorem
96
48
EE249: Design of Embedded System (corrections) ASV/LL
Hack’s theorem
97
Hack’s theorem
98
49
EE249: Design of Embedded System (corrections) ASV/LL
Hack’s theorem
99
Hack’s theorem
100
50
EE249: Design of Embedded System (corrections) ASV/LL
Hack’s theorem
101
Hack’s theorem
102
51
EE249: Design of Embedded System (corrections) ASV/LL
Hack’s theorem
Not live
103
104
52
EE249: Design of Embedded System (corrections) ASV/LL
53
EE249: Design of Embedded System (corrections) ASV/LL
• Graphical formalism
• Distributed state (including buffering)
• Concurrency, sequencing and choice made
explicit
• Structural and behavioral properties
• Analysis techniques based on
– linear algebra (only sufficient)
– structural analysis (necessary and sufficient only for
FC)
107
54