10. petri nets prof. o. nierstrasz. roadmap definition: —places, transitions, inputs, outputs...
TRANSCRIPT
![Page 1: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/1.jpg)
10. Petri Nets
Prof. O. Nierstrasz
![Page 2: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/2.jpg)
Roadmap
> Definition:— places, transitions, inputs, outputs— firing enabled transitions
> Modelling:— concurrency and synchronization
> Properties of nets:— liveness, boundedness
> Implementing Petri net models:— centralized and decentralized schemes
© Oscar Nierstrasz
Petri Nets
2
J. L. Peterson, Petri Nets Theory and the Modelling of Systems, Prentice Hall, 1983.
![Page 3: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/3.jpg)
Roadmap
> Definition:— places, transitions, inputs, outputs— firing enabled transitions
> Modelling:— concurrency and synchronization
> Properties of nets:— liveness, boundedness
> Implementing Petri net models:— centralized and decentralized schemes
© Oscar Nierstrasz
Petri Nets
3
![Page 4: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/4.jpg)
© Oscar Nierstrasz
Petri Nets
4
Petri nets: a definition
A Petri net C = P,T,I,O consists of:1. A finite set P of places2. A finite set T of transitions3. An input function I: T NatP (maps to bags of places)4. An output function O: T NatP
A marking of C is a mapping m: P Nat
Example:P = { x, y }T = { a, b }I(a) = { x }, I(b) = { x, x }O(a) = { x, y }, O(b) = { y }m = { x, x }
x
b
a
y
![Page 5: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/5.jpg)
© Oscar Nierstrasz
Petri Nets
5
Firing transitions
To fire a transition t:1. t must be enabled: m ≥ I(t)2. consume inputs and generate output: m= m - I(t) + O(t)
b
a
b
a
b
![Page 6: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/6.jpg)
Roadmap
> Definition:— places, transitions, inputs, outputs— firing enabled transitions
> Modelling:— concurrency and synchronization
> Properties of nets:— liveness, boundedness
> Implementing Petri net models:— centralized and decentralized schemes
© Oscar Nierstrasz
Petri Nets
6
![Page 7: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/7.jpg)
© Oscar Nierstrasz
Petri Nets
7
Modelling with Petri nets
Petri nets are good for modelling:> concurrency> synchronization
Tokens can represent:> resource availability> jobs to perform> flow of control> synchronization conditions ...
![Page 8: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/8.jpg)
© Oscar Nierstrasz
Petri Nets
8
Concurrency
Independent inputs permit “concurrent” firing of transitions
![Page 9: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/9.jpg)
© Oscar Nierstrasz
Petri Nets
9
Conflict
Overlapping inputs put transitions in conflicta
bb
Only one of a or b may fire
![Page 10: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/10.jpg)
© Oscar Nierstrasz
Petri Nets
10
Mutual Exclusion
The two subnets are forced to synchronize
![Page 11: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/11.jpg)
© Oscar Nierstrasz
Petri Nets
11
Fork and Join
![Page 12: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/12.jpg)
© Oscar Nierstrasz
Petri Nets
12
Producers and Consumers
producer consumer
![Page 13: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/13.jpg)
© Oscar Nierstrasz
Petri Nets
13
Bounded Buffers
#occupied slots
#free slots
![Page 14: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/14.jpg)
Roadmap
> Definition:— places, transitions, inputs, outputs— firing enabled transitions
> Modelling:— concurrency and synchronization
> Properties of nets:— liveness, boundedness
> Implementing Petri net models:— centralized and decentralized schemes
© Oscar Nierstrasz
Petri Nets
14
![Page 15: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/15.jpg)
© Oscar Nierstrasz
Petri Nets
15
Reachability and Boundedness
Reachability:> The reachability set R(C,m) of a net C is the set of all
markings m reachable from initial marking m.
Boundedness:> A net C with initial marking m is safe if places always
hold at most 1 token.> A marked net is (k-)bounded if places never hold more
than k tokens.> A marked net is conservative if the number of tokens is
constant.
![Page 16: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/16.jpg)
© Oscar Nierstrasz
Petri Nets
16
Liveness and Deadlock
Liveness:> A transition is deadlocked if it can never fire.> A transition is live if it can never deadlock.
x
a
y z
b
c
This net is both safe and conservative.Transition a is deadlocked.Transitions b and c are live.The reachability set is {{y}, {z}}.
Are the examples we have seen bounded? Are they live?
![Page 17: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/17.jpg)
© Oscar Nierstrasz
Petri Nets
17
Related Models
Finite State Processes> Equivalent to regular expressions> Can be modelled by one-token conservative nets
The FSA for: a(b|c)*d
ab
c
d
![Page 18: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/18.jpg)
Finite State Nets
© Oscar Nierstrasz
Petri Nets
18
Some Petri nets can be modelled by FSPs
u
w
av
x
c
b
{u,w}
{v,w} {u,x}
{v,x}
a
b a
b
c
Precisely which nets can (cannot) be modelled by FSPs?
![Page 19: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/19.jpg)
© Oscar Nierstrasz
Petri Nets
19
Petri nets are not computationally complete> Cannot model “zero testing”> Cannot model priorities
a
b
c
d
Zero-testing Nets
A zero-testing net: An equal number of a and b transitions may fire as a sequence during any sequence of matching c and d transitions. (#a ≥ #b, #c ≥ #d)
![Page 20: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/20.jpg)
© Oscar Nierstrasz
Petri Nets
20
Other Variants
There exist countless variants of Petri nets
Coloured Petri nets:> Tokens are “coloured” to represent different kinds of
resourcesAugmented Petri nets:> Transitions additionally depend on external conditionsTimed Petri nets:> A duration is associated with each transition
![Page 21: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/21.jpg)
© Oscar Nierstrasz
Petri Nets
21
Applications of Petri nets
Modelling information systems:> Workflow> Hypertext (possible transitions)> Dynamic aspects of OODB design
![Page 22: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/22.jpg)
Roadmap
> Definition:— places, transitions, inputs, outputs— firing enabled transitions
> Modelling:— concurrency and synchronization
> Properties of nets:— liveness, boundedness
> Implementing Petri net models:— centralized and decentralized schemes
© Oscar Nierstrasz
Petri Nets
22
![Page 23: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/23.jpg)
© Oscar Nierstrasz
Petri Nets
23
Implementing Petri nets
We can implement Petri net structures in either centralized or decentralized fashion:
Centralized:> A single “net manager” monitors the current state of the
net, and fires enabled transitions.Decentralized:> Transitions are processes, places are shared resources,
and transitions compete to obtain tokens.
![Page 24: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/24.jpg)
© Oscar Nierstrasz
Petri Nets
24
Centralized schemes
In one possible centralized scheme, the Manager selects and fires enabled transitions.
Concurrently enabled transitions can be fired in parallel.
![Page 25: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/25.jpg)
© Oscar Nierstrasz
Petri Nets
25
Decentralized schemes
In decentralized schemes transitions are processes and tokens are resources held by places:
Transitions can be implemented as thread-per-message gateways so the same transition can be fired more than once if enough tokens are available.
x y
a b
x y
a bget()
![Page 26: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/26.jpg)
© Oscar Nierstrasz
Petri Nets
26
Transactions
Transitions attempting to fire must grab their input tokens as an atomic transaction, or the net may deadlock even though there are enabled transitions!
If a and b are implemented by independent processes, and x and y by shared resources, this net can deadlock even though b is enabled if a (incorrectly) grabs x and waits for y.
a
b
x y
![Page 27: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/27.jpg)
© Oscar Nierstrasz
Petri Nets
CP 12.27
Coordinated interaction
A simple solution is to treat the state of the entire net as a single, shared resource:
After a transition fires, it notifies waiting transitions.
a
b
x y
a bget()
![Page 28: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/28.jpg)
Petit Petri — a Petri Net Editor built with Etoys
Petri Nets
28
![Page 29: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/29.jpg)
Etoys implementation
© Oscar Nierstrasz
Petri Nets
29
Mouse down
Mouse up
![Page 30: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/30.jpg)
Examples
© Oscar Nierstrasz
Petri Nets
30
![Page 31: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/31.jpg)
© Oscar Nierstrasz
Petri Nets
CP 12.31
What you should know!
> How are Petri nets formally specified?> How can nets model concurrency and synchronization?> What is the “reachability set” of a net? How can you
compute this set?> What kinds of Petri nets can be modelled by finite state
processes?> How can a (bad) implementation of a Petri net deadlock
even though there are enabled transitions?> If you implement a Petri net model, why is it a good idea
to realize transitions as “thread-per-message gateways”?
![Page 32: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/32.jpg)
© Oscar Nierstrasz
Petri Nets
CP 12.32
Can you answer these questions?
> What are some simple conditions for guaranteeing that a net is bounded?
> How would you model the Dining Philosophers problem as a Petri net? Is such a net bounded? Is it conservative? Live?
> What could you add to Petri nets to make them Turing-complete?
> What constraints could you put on a Petri net to make it fair?
![Page 33: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/33.jpg)
License
© Oscar Nierstrasz
ESE — Introduction
Attribution-ShareAlike 3.0 UnportedYou are free:
to Share — to copy, distribute and transmit the workto Remix — to adapt the work
Under the following conditions:Attribution. You must attribute the work in the manner specified by the author or licensor
(but not in any way that suggests that they endorse you or your use of the work).Share Alike. If you alter, transform, or build upon this work, you may distribute the
resulting work only under the same, similar or a compatible license.For any reuse or distribution, you must make clear to others the license terms of this work.
The best way to do this is with a link to this web page.Any of the above conditions can be waived if you get permission from the copyright holder.Nothing in this license impairs or restricts the author's moral rights.
http://creativecommons.org/licenses/by-sa/3.0/
![Page 34: 10. Petri Nets Prof. O. Nierstrasz. Roadmap Definition: —places, transitions, inputs, outputs —firing enabled transitions Modelling: —concurrency](https://reader034.vdocument.in/reader034/viewer/2022051516/56649f445503460f94c6540e/html5/thumbnails/34.jpg)
Etoys implementation
© Oscar Nierstrasz
Petri Nets
34