Real-Time Systems Lecture 9, 10 Modeling Real-Time systems : Petri Nets [email protected] Contents Introduction Petri Nets Modeling with Petri nets Timed Petri Nets Introduction Petri Nets provide for a mathematical approach to modelling and analysis of the systems. We can model the following aspects of the HRT system : • Concurency • Synchronization • Non-determinism Introduction Petri nets are applicable to: Communication protocols Manufacturing systems Computer networks Industrial process control Introduction References: 1. Nissanke N., Realtime Systems, Prentice Hall, 1997 2. Szmuc T., Zaawansowane metody tworzenia oprogramoweania systemów czasu rzeczywistego, Katedra Automatyki AGH, Kraków 1998, Zeszyt nr 15. Petri Nets Definition: A Petri net is a bipartite graph which consist of two sets of vertices(places and transitions) and a set of arcs between pairs of vertices. Petri Nets Places ( P ) {p1, p2, ..., pi} Transitions ( T ) {t1, t2, ..., tj} Petri Nets • Input arcs : Set i P x T , (pi, tk) • Output arcs : Set o T x P , (tk, pi) • Weight of the arc: W : ((P x T) (T x P)) N, where: dom W = i o Petri Nets The simplest Petri net : p1 1 t1 1 p2 Petri Nets The simplest Petri net : p1 1 t1 1 p2 Petri Nets The simplest Petri net : p1 1 t1 1 p2 Petri Nets The simplest Petri net : p1 1 t1 1 p2 transition Petri Nets „time invariant” „time variant” (P, T, i, o, W) Marking function: M:PN {M0, M1, M2 ... } PN = (P, T, i, o, W, M0) Petri Nets Firing the transition: • Only enabled transition may fire. • When transition fires, W((pi, t)) tokens are removed from each pi and W((po, t)) tokens are deposited at each po. Petri Nets • Only enabled transition may fire. Transition is enabled only when every input place p has at least W((p, t)) tokens. 1 2 4 Petri Nets • Only enabled transition may fire. Transition is enabled only when every input place p has at least W((p, t)) tokens. 1 2 4 Petri Nets • When transition fires ... W((pi, t)) tokens are removed from each pi and W((po, t)) tokens are deposited at each po 1 2 4 Petri Nets • When transition fires ... W((pi, t)) tokens are removed from each pi and W((po, t)) tokens are deposited at each po 1 2 4 Petri Nets • When transition fires ... Transition function : M0 t1 M1 t2 M2 t3 M3 ... Mi+1 = (Mi , ti) Marking Mi+1 is directly rechable from the marking Mi Modeling with Petri Nets The model The system Places Potential conditions of the system Transitions Potential events in the system Input arcs Relating events to preconditions Modeling with Petri Nets The model The system Output arcs Relating events with postconditions Tokens Fulfillment of the conditions Firing Occurence of the given event Modeling with Petri Nets The model The system Marking Current system state Initial marking Initial system state Change of marking Transition between system states Modeling with Petri Nets Concurency t1 2 p3 p1 p4 p2 t2 p5 Modeling with Petri Nets Conflict t1 p1 p4 p2 p5 p3 t2 Modeling with Petri Nets Symmetric confusion t1 p1 p3 t2 p4 p2 p5 t3 Modeling with Petri Nets Asymmetric confusion p4 p1 p5 t1 t2 p2 p6 p3 t3 Modeling with Petri Nets Properties: Reachability Marking Mn is reachable from marking M0 iff n = 0 or there exists a sequence of transitions l=<t1, t2, ..., tn> altering the marking M0 into Mn. R(PN, M0) – set of all possible markings for the given Petri net PN Modeling with Petri Nets Properties: Reachability Marking Mn is reachable from marking M0 iff n = 0 or there exists a sequence of transitions l=<t1, t2, ..., tn> altering the marking M0 into Mn. L(PN, M0) – set of all possible sequences of transitions for the given Petri net PN Modeling with Petri Nets Properties: k-Boundness A Petri net is k-bounded when M(p) k for some kN, MR(PN, M0) and pP Modeling with Petri Nets Properties: Boundness A Petri net is bounded when exists kN, that PN is k-bounded. Modeling with Petri Nets Properties: Safety A Petri net is safe if it is 1-bounded. Modeling with Petri Nets Properties: Liveness Let be given a Petri net PN. We can say, that the transition tT is L0-live (dead) iff we cannot fire it for any sequence lL(PN, M0) Modeling with Petri Nets Properties: Liveness Let be given a Petri net PN. We can say, that the transition tT is L1-live iff we are able to fire it at least once for some sequence lL(PN, M0) Modeling with Petri Nets Properties: Liveness Let be given a Petri net PN. We can say, that the transition tT is L2-live iff we are able to fire it k-times (k>0) for some sequence lL(PN, M0) Modeling with Petri Nets Properties: Liveness Let be given a Petri net PN. We can say, that the transition tT is L3-live iff transition t appears infinite times inside some sequence lL(PN, M0) Modeling with Petri Nets Properties: Liveness Let be given a Petri net PN. We can say, that the transition tT is L4-live iff transition t is L1-live for every marking MR(PN, M0) Modeling with Petri Nets Properties: Liveness Let be given a Petri net PN. We can say, that PN is Lk-live iff its every trasnsition is Lk-live, where k = 0, 1, 2, 3, 4. A Petri net is said to be live if it is L4live. It means, that there is no deadlock in the net. Modeling with Petri Nets Properties: Persistence A Petri net PN is persistent iff for every pair of enabled transitions, firing one of those transitions doesn’t disable the other one. Modeling with Petri Nets Analysing properties: Coverage tree Coverage tree consists of the finite number of tree-nodes and branches, where: • Tree-node: a marking MnR(PN, M0) • Tree-branch: a transition tiT If Mi+1 = (Mi, tj) then there is an arc inside the tree from Mi to Mi+1 labeled by tj. Modeling with Petri Nets Analysing properties: Coverage tree t1 M0 M1 t2 t1 M3 M2 t3 M4 Modeling with Petri Nets Analysing properties: Coverage tree Repeated sequence of transitions p1 t2 t1 p2 Modeling with Petri Nets Analysing properties: Coverage tree Repeated sequence of transitions (1,0) t1 (0,1) t2 (1,0) t1 (0,1) ... Modeling with Petri Nets Analysing properties: Coverage tree Repeated sequence of transitions (1,0) t1 (0,1) t2 (1,0) t1 (0,1) ... Stop – repeated state ! Modeling with Petri Nets Analysing properties: Coverage tree Increasing number of tokens p1 t1 p2 Modeling with Petri Nets Analysing properties: Coverage tree Increasing number of tokens (1,0) t1 (1,1) t1 (1,2) t1 (1,3) ... Modeling with Petri Nets Analysing properties: Coverage tree Increasing number of tokens (1,0) t1 (1,) where has the following properties: > n, n = , (for any nN) Modeling with Petri Nets Analysing properties: Coverage tree Algorithm for creating the coverage tree: Step 1: Let marking M0 be the root-node of the tree. Mark it as a new-node. Step 2: If exists any new-node do the following: Modeling with Petri Nets Analysing properties: Coverage tree Step 2.1: Take any new-node Mi. Step 2.2: If there is a node Mj on the path from M0 to Mi and Mj = Mi then mark Mi as repeated-node and return to step 2. Step 2.3: If there is no enabled transition for the node Mi, mark the node as the end-node and return to step 2. Modeling with Petri Nets Analysing properties: Coverage tree Step 2.4: For every enabled transition tj related to the node Mi do the following: Step 2.4.1: Calculate Mi+1=(Mi, tj) Step 2.4.2: if there exists marking Mk on the path from M0 to Mi, such that: Modeling with Petri Nets Analysing properties: Coverage tree pP : Mk(p) Mi+1(p) pP : Mk(p) < Mi+1(p) Mi+1(p) = Step 2.4.3: Insert node Mi+1 into the tree (it is connected to the node Mi via the branch labeled by tj) and mark it as a new-node. Return to step 2. Modeling with Petri Nets Analysing properties: Coverage tree p1 t2 t1 p3 t3 p2 Modeling with Petri Nets Analysing properties: Coverage tree 1, 0 ,0 t1 Modeling with Petri Nets Analysing properties: Coverage tree p1 t2 t1 p3 t3 p2 Modeling with Petri Nets Analysing properties: Coverage tree 1, 0 ,0 t1 1, 1 ,0 t1 Modeling with Petri Nets Analysing properties: Coverage tree 1, 0 ,0 t1 1, ,0 t1 Modeling with Petri Nets Analysing properties: Coverage tree p1 t2 t1 p3 t3 p2 Modeling with Petri Nets Analysing properties: Coverage tree 1, 0 ,0 t1 1, ,0 t1 1, ,0 t2 Modeling with Petri Nets Analysing properties: Coverage tree p1 t2 t1 p3 t3 p2 Modeling with Petri Nets Analysing properties: Coverage tree 1, 0 ,0 t1 1, ,0 t1 1, ,0 t2 0, ,1 t3 Modeling with Petri Nets Analysing properties: Coverage tree p1 t2 t1 p3 t3 p2 Modeling with Petri Nets Analysing properties: Coverage tree 1, 0 ,0 t2 t1 1, ,0 t1 1, ,0 t2 0, ,1 t3 0, ,1 Modeling with Petri Nets Analysing properties: Coverage tree p1 t2 t1 p3 t3 p2 Modeling with Petri Nets Analysing properties: Coverage tree 1, 0 ,0 t2 t1 0, 1 ,1 1, ,0 t1 1, ,0 t2 t3 0, ,1 t3 0, ,1 Modeling with Petri Nets Analysing properties: Coverage tree p1 t2 t1 p3 t3 p2 Modeling with Petri Nets Analysing properties: Coverage tree 1, 0 ,0 t2 t1 0, 1 ,1 1, ,0 t1 1, ,0 t2 t3 0, ,1 0, 0 ,1 t3 0, ,1 Modeling with Petri Nets Analysing properties: Coverage tree The properties of the Petri net: 1. PN is bounded iff there is no symbol inside the coverage tree. 2. PN is safe iff only 0,1 digits are used inside all the markings Mi. Modeling with Petri Nets Analysing properties: Coverage tree The properties of the Petri net: 3. Transition tj is dead iff there is no arc labeled by tj inside the coverage tree. 4. Marking Mi is reachable from the marking M0 iff there is a node Mi in the coverage tree and there exists a path inside the tree from the node M0 to the node Mi. Modeling with Petri Nets Analysing properties: Example Try to model the „4 readers and a writer” problem using Petri nets. Then build the coverage tree for this problem. Timed - Petri Nets Augmenting Petri nets with time : • Assign time to transitions • Assign time to places • Time Basic Nets (TBN) Timed - Petri Nets TBN model • Time offsets (Ti) related to the transitions • Time-stamps related to the tokens • Time intervals related to the transitions as a function of time-stamps and time offsets (time conditions) Timed - Petri Nets TBN model – firing the transition Transition is enabled iff: 1. There are necessary number of tokens in all input places 2. Time values in time interval related to the given transition are greater than, or equal to, the largest time stamp on input tokens. Timed - Petri Nets TBN model – firing the transition Enabling time - the greatest value of the tokens’ time-stamp in all the input places related to the particular transition. Firing period – modified time interval related to the given transition (its values are greater than, or equal to the enabling time). Timed - Petri Nets TBN model – firing the transition 1. Only enabled transitions may fire. The firing can happen somewhere during the firing period. 2. The proper number of tokens is removed from the input places and populated to the output places with the time-stamp equal to the firing time (the weights of arcs are preserved during this process). Timed - Petri Nets TBN model – firing the transition 3. The other rules are exactly the same like in the untimed Petri net. Timed - Petri Nets TBN model – example A server : There is given a server with 1 CPU. When a task comes to the system, its execution must be started within T3=5 seconds, otherwise the request is discarded. The task’s processing time lasts from T1=4 to T2=10 seconds. The system becomes ready to accept a new task after T4=2 seconds. Timed - Petri Nets TBN model – example t1 p1 t3 p3 p2 t2 Timed - Petri Nets TBN model – example request start discard ready being processed finish Timed - Petri Nets TBN model – example Tran. Offsets Input places Time conditions t1 T3, T4 p1, p3 [time(p3)+T4, time(p1)+T3) t2 T1, T2 p2 [time(p2)+T1, time(p2)+T2) t3 T3 p1 [time(p1)+T3, ) time(p3) – time-stamp of the token stored in place p3. Timed - Petri Nets TBN model – example t1 p1 t3 p3 p2 t2 Timed - Petri Nets TBN model – example time(p1) = 2 (let it be a time of the request) time(p3) = 0 Enabled Time conditions transitions t1 [0+2, 2+5) = [2, 7) t3 [2+5, ) = [7, ) Timed - Petri Nets TBN model – example t1 p1 t3 p3 p2 t2 Timed - Petri Nets TBN model – example After firing t1 at time 4 (the task is started) time(p2) = 4 Enabled Time conditions transitions t2 [4+4, 4+10) = [8, 14) Timed - Petri Nets TBN model – example t1 p1 t3 p3 p2 t2 Timed - Petri Nets TBN model – example After firing t2 at time 10 (the task is finished) time(p3) = 10 No enabled transitions – system is waiting for another request. At last .....
© Copyright 2026 Paperzz