Mathematical Foundation of Computer Sciences VIII
Total Page:16
File Type:pdf, Size:1020Kb
Mathematical Foundation of Computer Sciences VIII Theoretical Computer Sciences Guoqiang Li School of Software, Shanghai Jiao Tong University 1 Petri Nets 1 Petri Nets Petri Nets Systems are specified as a directed bipartite graph. Systems are specified as a directed bipartite graph. The two The two kinds of nodes in the graph: kinds of nodes in the graph: Embedded Systems Design Fö 5 2 of2 75 Petri Nets Petri Nets Systems are specified as a directed bipartite graph. Systems are specified as a directed bipartite graph. The two The two kinds of nodes in the graph: kinds of nodes in the graph: 1. Places: they hold the distributed state of the • Places: they holdsystem the expressed distributed by state the presence/absence of the system expressed by theof tokens presence/absence in the places. of tokens in the places. Embedded Systems Design Fö 5 3 of3 75 Petri Nets Petri Nets Systems are specified as a directed bipartite graph. Systems are specified as a directed bipartite graph. The two The two kinds of nodes in the graph: kinds of nodes in the graph: 1. Places: they hold the distributed state of the • Places: they holdsystem the expressed distributed by state the presence/absence of the system expressed by theof tokens presence/absence in the places. of tokens in the places. • Transitions:2. denote Transitions the activity: denote in the the activity system in the system Embedded Systems Design Fö 5 4 of4 75 Petri Nets Petri Nets Systems are specified as a directed bipartite graph. Systems are specified as a directed bipartite graph. The two The two kinds of nodes in the graph: kinds of nodes in the graph: 1. Places: they hold the distributed state of the • Places: they holdsystem the expressed distributed by state the presence/absence of the system expressed by theof tokens presence/absence in the places. of tokens in the places. • Transitions:2. denote Transitions the activity: denote in the the activity system in the system The state of the system: captured by the marking of the places (number of tokens in each place) The state of the system: captured by the marking of the places (number of tokens in each place) Embedded Systems Design Fö 5 5 of 75 5 Petri Nets Petri Nets Systems are specified as a directed bipartite graph. The dynamicThe evolution two kinds of of thenodes system: in the determinedgraph: by the firing process of transitions. 1. Places: they hold the distributed state of the • A transition issystem enabled expressed and may fireby the whenever presence/absence all its predecessor placesof tokens are marked. in the places. 2. Transitions: denote the activity in the system The state of the system: captured by the marking of the places (number of tokens in each place) Embedded Systems Design Fö 5 5 of 75 6 Petri Nets Petri Nets The dynamicThe dynamic evolution evolution of the of system:the system: determined determined by theby the firing firing process process of of transitions.transitions. • A transition A transition is enabled is andenabled may and fire whenevermay fire whenever all its predecessorall placesits predecessor are marked. places are marked. • If a transition fires it removes a token from each If a transition fires it removes a token from each predecessor place and adds a token to each successor place. predecessor place and adds a token to each successor place. 7 Embedded Systems Design Fö 5 7 of 75 Nondeterminism Nondeterminism Both T1 and T2 are enabled and any of the two may fire. T1 T2 8 Embedded Systems Design Fö 5 8 of 75 NondeterminismNondeterminism Both T1 and T2 are enabled and any of the two may fire. Nondeterminism T1 T2 Both T1 and T2 are enabled and any of the two may fire. T1 T2 T1 T2 Embedded Systems Design Fö 5 9 of 75 9 Embedded Systems Design Fö 5 8 of 75 Nondeterminism Nondeterminism Both T1 and T2 are enabled and any of the two may fire.Nondeterminism T1 T2 Both T1 and T2 are enabled and any of the two may fire. T1 T2 T1 T2 Embedded Systems Design Fö 5 10 of 75 10 Embedded Systems Design Fö 5 8 of 75 NondeterminismNondeterminismNondeterminism Both T1 and T2Both are T1 enabled and T2 and are anyenabled and any of the two mayof fire.the two may fire.Nondeterminism T1 T1 T2 T2 Both T1 and T2 are enabled and any of the two may fire. T1 T2 T1 T2 T1 T2 Embedded Systems Design FöEmbedded 5 Systems Design Fö 5 9 of 75 10 of 75 11 Embedded Systems Design Fö 5 8 of 75 Example A producer and a consumer process communicating through a buffer: 12 Example Petri Net Example A producer and a consumer process communicating through a buffer: prod. rec. prod. rec. prod. rec. B B B send cons. send cons. send cons. prod. rec. prod. rec. prod. rec. B B B send cons. send cons. send cons. Embedded Systems Design Fö 5 17 of 75 13 Example Petri Net Example A producer and a consumer process communicating through a buffer: prod. rec. prod. rec. prod. rec. B B B send cons. send cons. send cons. prod. rec. prod. rec. prod. rec. B B B send cons. send cons. send cons. Embedded Systems Design Fö 5 23 of 75 14 Notice that the buffer is considered to be infinite (tokens accumulate in B). Example Petri Net Example A producer and a consumer process communicating through a buffer: prod. rec. prod. rec. prod. rec. B B B send cons. send cons. send cons. Embedded Systems Design Fö 5 26 of 75 15 Example Petri Net Example A producer and a consumer process communicating through a buffer: prod. rec. prod. rec. prod. rec. B B B send cons. send cons. send cons. Embedded Systems Design Fö 5 26 of 75 Notice that the buffer is considered to be infinite (tokens accumulate in B). 15 The buffer size is three (number of initial tokens in B’) • Number of tokens in B’: how many free slots are available in the buffer; • Number of tokens in B: how many messages (tokens) are in the buffer. Total number of tokens in B and B’ is constant (= 3). Example Petri Net Example Here we have the same model as on the previous slides, but with limited buffer. We have the same model,The but buffer with limitedsize is three buffer. (number of initial tokens in B’) prod. rec. B B’ send cons. Nr. of tokens in B’: how many free slots are available in the buffer; Nr. of tokens in B: how many messages (tokens) are in the buffer. Total number of tokens in B and B’ is constant (= 3). Embedded Systems Design Fö 5 28 of 75 16 Example Petri Net Example Here we have the same model as on the previous slides, but with limited buffer. We have the same model,The but buffer with limitedsize is three buffer. (number of initial tokens in B’) prod. rec. B B’ send cons. The buffer size is three (number of initial tokens in B’) Nr. of tokens in B’: how many free slots are available in the buffer; • Number of tokens in B’:Nr. how of manytokens free in B: slots how are many available messages in the (tokens) buffer; are in the buffer. • Number of tokens in B:Total how manynumber messages of tokens (tokens) in B and are B’ inis constant the buffer. (= 3). Total number of tokens in B and B’ is constant (= 3). Embedded Systems Design Fö 5 28 of 75 16 Example Petri Net Example Here we have the same model as on the previous slides, but with limited buffer. TheWe buffer have the size same is three model, (number but withof initial limited tokens buffer. in B’) prod. rec. prod. rec. prod. rec. B B B B’ B’ B’ send cons. send cons. send cons. prod. rec. prod. rec. prod. rec. B B B B’ B’ B’ send cons. send cons. send cons. Embedded Systems Design Fö 5 33 of 75 17 Formal Definition A Petri net is a four-tuple: PN = hP; T ; I ; Oi, where P \ T = ; • P: a finite set of places, fp1; p2;:::; png • T : a finite set of transitions, ft1; t2;:::; ts g • I : an input function, T × P ! f0; 1g • O: an output function, T × P ! f0; 1g M0: an initial marking, P ! N 18 As an uninterpreted model, Petri Nets can be used for several, very different classes of problems. Some Features and Applications of Petri Nets Intuitive: • Easy to express concurrency, synchronisation, nondeterminism. • Nondeterminism is an important difference between Petri nets and sequential models. 19 Some Features and Applications of Petri Nets Intuitive: • Easy to express concurrency, synchronisation, nondeterminism. • Nondeterminism is an important difference between Petri nets and sequential models. As an uninterpreted model, Petri Nets can be used for several, very different classes of problems. 19 Some Features and Applications of Petri Nets Industrial production systems, Information systems, Computer architectures, Operating systems, Concurrent programs, Distributed systems, Hardware systems 20 • You can check that available resources are not exceeded. Liveness: A transition t is called live if for every possible marking there exists a chance for that transition to become enabled. The whole net is live, if all its transitions are live. • Important in order to check that the system is not deadlocked. Reachability: given a current marking M and another marking M0, does there exist a sequence of transitions by which M0 can be obtained? • You can check that a certain desired state (marking) is reached.