![Page 1: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/1.jpg)
Oscar Nierstrasz
11. Petri Nets
J. L. Peterson, Petri Nets Theory and the Modelling of Systems, Prentice Hall, 1983.
![Page 2: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/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
2
![Page 3: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/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
3
![Page 4: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/4.jpg)
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: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/5.jpg)
Petri nets (or “place/transition nets”) were invented Carl Adam Petri. They offer a very intuitive graphical formalism for modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds of vertices — places and transitions — together with a marking — a function that indicates how many tokens are currently in every given place. Transitions are enabled if they have at least one token in every input place. Firing an enabled transition leads to a new marking by removing one token from every input and adding one to every output place. In the diagram we see the same net represented both graphically, and using multisets.
![Page 6: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/6.jpg)
The following classic survey (and subsequent book) offer an excellent introduction:
James L. Peterson. Petri Nets. In ACM Computing Surveys 9(3) p. 223—252, September 1977. http://dx.doi.org/10.1145/356698.356702 http://scgresources.unibe.ch/Literature/CP/Pete77aSurvey.pdf See also: https://en.wikipedia.org/wiki/Petri_net
![Page 7: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/7.jpg)
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)
![Page 8: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/8.jpg)
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)
a
b
![Page 9: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/9.jpg)
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)
a
b
a
b
![Page 10: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/10.jpg)
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 11: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/11.jpg)
This diagram shows how the net of the previous slide can lead to various possible sequences of transitions being fired. Note that the “language” of a Petri net consists of the set of possible firing sequences. In this case, the language can be expressed as a regular expression. Exercise: what is the (regular) language of this net?
![Page 12: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/12.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
6
![Page 13: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/13.jpg)
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 14: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/14.jpg)
Petri nets can be used to model a wide range of concurrency problems. Transitions can represent competing processes, and places can represent resources, with tokens (markings) indicating the availability of a resource. But a process may also correspond to a subnet, with places representing the state of a process. Tokens can then represent control flow, or data flow, or synchronization conditions.
![Page 15: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/15.jpg)
Concurrency
8
Independent inputs permit “concurrent” firing of transitions
![Page 16: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/16.jpg)
Concurrency
8
Independent inputs permit “concurrent” firing of transitions
![Page 17: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/17.jpg)
Concurrency
8
✂
Independent inputs permit “concurrent” firing of transitions
![Page 18: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/18.jpg)
In this example, two independent subnets can fire concurrently, since they share no resources (no common places). Note that Petri nets have no notion of simultaneous firing of transitions. Instead “concurrent” transitions may fire in an interleaving way.
![Page 19: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/19.jpg)
Conflict
9
a
b
Overlapping inputs put transitions in conflict
Only one of a or b may fire
![Page 20: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/20.jpg)
Conflict
9
a
bb
Overlapping inputs put transitions in conflict
Only one of a or b may fire
![Page 21: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/21.jpg)
Conflict
9
a
bb
✂
Overlapping inputs put transitions in conflict
Only one of a or b may fire
![Page 22: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/22.jpg)
Mutual Exclusion
10
The two subnets are forced to synchronize
![Page 23: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/23.jpg)
Mutual Exclusion
10
The two subnets are forced to synchronize
![Page 24: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/24.jpg)
Mutual Exclusion
10
The two subnets are forced to synchronize
![Page 25: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/25.jpg)
Mutual Exclusion
10
The two subnets are forced to synchronize
![Page 26: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/26.jpg)
Mutual Exclusion
10
The two subnets are forced to synchronize
![Page 27: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/27.jpg)
Mutual Exclusion
10
✂
The two subnets are forced to synchronize
![Page 28: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/28.jpg)
In this diagram we have two subnets that represent two concurrent processes. Each subnet has two transitions — one to enter a “critical section”, and one to leave it. The tokens within the subnets represent flow of control. The place connecting the subnets represents a mutual exclusion condition (or semaphore, or lock). A token is present if the resource is available, and is absent if there is already a process in the critical section. Note how places and tokens represent very different things in this model. NB: The rectangles are there just to indicate subnets; they are not part of the Petri net formalism.
![Page 29: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/29.jpg)
11
Fork and Join
![Page 30: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/30.jpg)
11
Fork and Join
![Page 31: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/31.jpg)
11
Fork and Join
![Page 32: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/32.jpg)
11
Fork and Join
![Page 33: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/33.jpg)
11
Fork and Join
![Page 34: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/34.jpg)
11
Fork and Join
✂
![Page 35: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/35.jpg)
Here the rectangles again represent subnets, but we do not show what is in them. Note how the first transition (“fork”) spawns several threads of control, each thread being represented by a token. The final transition (“join”) waits for all threads to complete, and then fires, replacing the multiple threads by a single one. What assumptions need to hold over the subnets for this to work?
![Page 36: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/36.jpg)
12
Producers and Consumers
producer consumer
![Page 37: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/37.jpg)
12
Producers and Consumers
producer consumer
![Page 38: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/38.jpg)
12
Producers and Consumers
producer consumer
![Page 39: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/39.jpg)
12
Producers and Consumers
producer consumer
![Page 40: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/40.jpg)
12
Producers and Consumers
producer consumer
![Page 41: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/41.jpg)
12
Producers and Consumers
producer consumer
![Page 42: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/42.jpg)
12
Producers and Consumers
producer consumer
![Page 43: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/43.jpg)
12
Producers and Consumers
producer consumer
![Page 44: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/44.jpg)
12
Producers and Consumers
producer consumer
![Page 45: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/45.jpg)
12
Producers and Consumers
producer consumer
✂
![Page 46: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/46.jpg)
Here we again have subnets representing communicating processes, with tokens inside the subnets representing flow of control. The place connecting them, however, this time represents a buffer, with the tokens it contains representing payloads (messages) produced by one subnet and consumed by the other.
![Page 47: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/47.jpg)
13
Bounded Buffers
#occupied slots
#free slots
![Page 48: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/48.jpg)
13
Bounded Buffers
#occupied slots
#free slots
![Page 49: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/49.jpg)
13
Bounded Buffers
#occupied slots
#free slots
![Page 50: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/50.jpg)
13
Bounded Buffers
#occupied slots
#free slots
![Page 51: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/51.jpg)
13
Bounded Buffers
#occupied slots
#free slots
![Page 52: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/52.jpg)
13
Bounded Buffers
#occupied slots
#free slots
![Page 53: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/53.jpg)
13
Bounded Buffers
#occupied slots
#free slots
![Page 54: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/54.jpg)
13
Bounded Buffers
#occupied slots
#free slots
![Page 55: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/55.jpg)
13
Bounded Buffers
#occupied slots
#free slots
![Page 56: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/56.jpg)
13
Bounded Buffers
#occupied slots
#free slots
![Page 57: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/57.jpg)
13
Bounded Buffers
#occupied slots
#free slots
![Page 58: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/58.jpg)
13
Bounded Buffers
#occupied slots
#free slots
✂
![Page 59: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/59.jpg)
While the previous example made use of an unbounded buffer, this example shows how a bounded buffer can be modeled. Tokens in the middle represent either the number of occupied slots or the available ones. The producer needs at least one free slot to produce an output, and the consumer needs at least one full slot to consume an input. In this way the producer cannot get ahead of the consumer.
![Page 60: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/60.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
14
![Page 61: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/61.jpg)
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 62: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/62.jpg)
Note that each marking m represents a possible state of the net. As we have seen in the various examples, the reachability set may be finite or infinite. A safe net is clearly k-bounded (k=1).
Are conservative nets necessarily k-bounded? Is the reverse true? Which of these have finite reachability sets?
![Page 63: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/63.jpg)
Liveness and Deadlock
16
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}}.
Liveness:> A transition is deadlocked if it can never fire.> A transition is live if it can never deadlock.
Are the examples we have seen bounded? Are they live?
![Page 64: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/64.jpg)
Note that liveness is a very strong condition, since it states that it is always possible for the transition to become enabled again. However there is no guarantee that it will fire, only that it might.
Go back through all the examples and for each net explain whether or not is it is bounded (safe, conservative, k-bounded) or live.
![Page 65: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/65.jpg)
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 66: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/66.jpg)
Finite state processes (FSPs) can easily be modeled by Petri nets simply by adding a single net transition between every pair of connected states. A single token then models the current state.
![Page 67: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/67.jpg)
Finite State Nets
18
Some Petri nets can be modelled by FSPs
u
w
av
xc
b
{u,w}
{v,w} {u,x}
{v,x}
a
b a
b
c
Precisely which nets can (cannot) be modelled by FSPs?
![Page 68: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/68.jpg)
Finite State Nets
18
Some Petri nets can be modelled by FSPs
u
w
av
xc
b
{u,w}
{v,w} {u,x}
{v,x}
a
b a
b
c
Precisely which nets can (cannot) be modelled by FSPs?
![Page 69: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/69.jpg)
Finite State Nets
18
Some Petri nets can be modelled by FSPs
u
w
av
xc
b
{u,w}
{v,w} {u,x}
{v,x}
a
b a
b
c
Precisely which nets can (cannot) be modelled by FSPs?
![Page 70: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/70.jpg)
Finite State Nets
18
Some Petri nets can be modelled by FSPs
u
w
av
xc
b
{u,w}
{v,w} {u,x}
{v,x}
a
b a
b
c
Precisely which nets can (cannot) be modelled by FSPs?
![Page 71: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/71.jpg)
Finite State Nets
18
Some Petri nets can be modelled by FSPs
u
w
av
xc
b
{u,w}
{v,w} {u,x}
{v,x}
a
b a
b
c
✂
Precisely which nets can (cannot) be modelled by FSPs?
![Page 72: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/72.jpg)
Any bounded net, i.e., with a finite reachability set, can be modeled by a FSA. Simply introduce one state for each reachable marking FSA indicating which net transitions fire between the states, and addd a single token for the initial marking. In the example, there are just four reachable markings, hence four states in the FSP. NB: An infinite reachability set does not guarantee that an equivalent FSP does not exist. A counterexample is the first example of the slide deck, which models the regular language a*b, so even though it has an infinite reachability set, it is equivalent to the FSP (0)—a→(0), (0)—b→(STOP).
![Page 73: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/73.jpg)
Zero-testing Nets
19
a
b
cd
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)
Petri nets are not computationally complete> Cannot model “zero testing”> Cannot model priorities
![Page 74: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/74.jpg)
Zero-testing Nets
19
a
b
cd
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)
Petri nets are not computationally complete> Cannot model “zero testing”> Cannot model priorities
![Page 75: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/75.jpg)
Zero-testing Nets
19
a
b
cd
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)
Petri nets are not computationally complete> Cannot model “zero testing”> Cannot model priorities
![Page 76: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/76.jpg)
Zero-testing Nets
19
a
b
cd
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)
Petri nets are not computationally complete> Cannot model “zero testing”> Cannot model priorities
![Page 77: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/77.jpg)
Zero-testing Nets
19
a
b
cd
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)
Petri nets are not computationally complete> Cannot model “zero testing”> Cannot model priorities
![Page 78: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/78.jpg)
Zero-testing Nets
19
a
b
cd
✂
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)
Petri nets are not computationally complete> Cannot model “zero testing”> Cannot model priorities
![Page 79: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/79.jpg)
Petri nets are strictly more powerful than FSPs (or FSAs), but less powerful than Turing machines. (Turing machines can generate languages that nets cannot, just as nets can generate languages that FSAs cannot.) Adding almost any feature to nets (such as zero-testing), however, will make them Turing-complete. In the example, d can only fire if the zero-input place between a and b is empty, i.e., if a and b have fired exactly the same number of times. This behaviour is impossible to express with a “plain” Petri net.
![Page 80: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/80.jpg)
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 81: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/81.jpg)
Augmented Petri nets have been used to model “active databases” in which activities are triggered when some event takes place, such as an integrity constraint being violated.
![Page 82: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/82.jpg)
21
Applications of Petri nets
Modelling information systems:> Workflow> Hypertext (possible transitions)> Dynamic aspects of OODB design
![Page 83: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/83.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
22
![Page 84: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/84.jpg)
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 85: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/85.jpg)
The centralized scheme just implements the formal definition of Petri nets, but has no “real” concurrency. The distributed version is truly concurrent, but the difficulty is in realizing the atomic nature of firing transitions competing for the same tokens.
![Page 86: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/86.jpg)
Centralized schemes
24Concurrently enabled transitions can be fired in parallel.
In one possible centralized scheme, the Manager selects and fires enabled transitions.
Net Manager
Identify enabled transitions
Select and fire transitions
deadlocked
found some
got new markings
![Page 87: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/87.jpg)
Possible problems: starvation (dining phils); deadlock (no detection) ...
![Page 88: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/88.jpg)
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 89: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/89.jpg)
The idea is that the availability of a token in a place will trigger a new thread in transitions that input that place.
![Page 90: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/90.jpg)
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 91: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/91.jpg)
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 92: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/92.jpg)
This solution combines the centralized and distributed approaches. NB: We can represent the entire state as an object in a shared one-slot buffer! Distributed scheme — idea: define equivalence classes via input relation x~y if {x,y} in I(a) for some a.
Can you think of other, simple approaches that maximize concurrency while avoiding deadlock?
![Page 93: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/93.jpg)
Petit Petri — a Petri Net Editor built with Etoys
28
![Page 94: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/94.jpg)
Petit Petri is a Petri Net editor and simulator implemented in eToys.
See: http://scg.unibe.ch/download/petitpetri/
![Page 95: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/95.jpg)
Etoys implementation
29
Mouse down
Mouse up
![Page 96: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/96.jpg)
The entire implementation consists of 9 simple event driven scripts. After building a net, the user can simulate its execution by clicking on an enabled transition. Mouse down will instruct all input places to decrease their token count by one, and mouse up will instruct output places to increase their token count. When a place’s token count drops to zero, it tells its successor transitions to become disabled. When a place’s token count increases, it tells its successors to check if they are enabled (checkIfFirable optimistically sets itself to green, and then asks its predecessors to disable it if any of them are empty). Mouse enter and mouse leave for a place will update its color, leaving it yellow if it is empty.
![Page 97: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/97.jpg)
Examples
30
![Page 98: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/98.jpg)
Several examples from the lecture are implemented in Petit Petri, as well as a few different versions of Dining Philosophers and the “Star Game” (the goal is to move all five tokens from their current place to their neighbour).
![Page 99: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/99.jpg)
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 100: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/100.jpg)
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 101: 11. Petri Nets - Portalscg.unibe.ch/download/lectures/cp/CP-11-PetriNets-animated.pdf · modeling concurrent processes. Formal Petri nets are directed bigraphs, graphs with two kinds](https://reader035.vdocuments.mx/reader035/viewer/2022062916/5eb9d1c73502f56107567147/html5/thumbnails/101.jpg)
Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
You are free to:Share — copy and redistribute the material in any medium or formatAdapt — remix, transform, and build upon the material for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms:
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
http://creativecommons.org/licenses/by-sa/4.0/