650 likes | 826 Views
Hardware/Software Codesign of Embedded Systems. PETRI NETS II. Voicu Groza SITE Hall, Room 5017 562 5800 ext. 2159 Groza@SITE.uOttawa.ca. References.
E N D
Hardware/Software Codesign of Embedded Systems PETRI NETS II Voicu Groza SITE Hall, Room 5017 562 5800 ext. 2159 Groza@SITE.uOttawa.ca
References • T. Murata, (1989) “Petri Nets: Properties, Analysis and Applications” Proceedings of IEEE, Vol.77, No 4 pp 541-580. (http://www.cs.unc.edu/~montek/teaching/spring-04/murata-petrinets.pdf) • Renâe David, Hassane Alla, “Discrete, continuous, and hybrid Petri Nets,” Springer, Berlin ; New York, 2005. • Peter Marwedel, “Embedded system design,” Kluwer Academic Publishers, Boston : 2003.
Definition Petri nets are a modeling tool designed to reveal information about the structure and dynamics of the modeled system. A Petri Net is represented by a bipartite directed graph, with weighted arcs. The graph has two kinds of nodes: places and transitions. The weighted arcs are either from a place to a transition or from a transition to a place. A place that has an outgoing arc to a transition t is called input place of transition t. A place that has an incoming arc from a transition t is called output place of transition t. Arcs are labeled with their weight, which are positive integers. Labels for unitary weight are usually omitted.
Dynamics • The dynamics of a PN is described by means of the concept of marking. • A marking is a function that assigns to each place a nonnegative integer, called token. • If we use the concept of conditions and events, places represent conditions and transitions represent events. A transition (an event) has a certain number of input places representing the pre-conditions and a certain number of output places representing the post-conditions. • Suppose a transition t has: • one input place p1 marked with k1 tokens and the weight of the output arc w1 • one output place p2 marked with k2 tokens and the weight of the output arc w2 • Transition t is enabled to fire if its input place p1 is marked with at least w1 tokens. (w1 ≥ k1) • Firing t, it removes w1 tokens from its input place p1 and adds w2 to its output place p2.
Interpretation Transition type A transition is said to be pure if it has no self-loop. An impure transition is said to be isolated if all its input and output arcs are null. Some typical interpretation of places and transitions
Modeling exampleCommunication Protocols A very simple model of communication protocol between two processes.
Synchronization Control • In a multiprocessor or distributed-processing system, resources and information are shared among several processors. This sharing must be controlled or synchronized to insure the correct operations of the overall system. Petri nets have been used to model a variety of synchronization mechanisms, including the mutual exclusion, readers-writers, and producers-consumers problems. • The Petri net shown in figure represents a readers-writers synchronization, where the k tokens in place p1 represent k processes (programs) which may read and write in a shared memory represented by place p3. • Up to k processes may read concurrently, but when one process is writing, no other process can read or write. It is easily verified that up to k tokens (processes) may be in place p2 (reading) if no token is in place p4. Only one token (process) can be in place p4 (writing) since all k tokens in place p3 will be removed through the k-weight arc when t2 fire once.
Reachability Boundedness Liveness Reversability and Homestate Coverability Persistence Structural Liveness Controllability Structural Boundedness Conservativeness Repetitiveness Consistency Properties Two types of properties can be studied using Petri nets: Properties dependent on initial marking M0can be referred to as behavioral properties Properties that are depend on the topological structures ofPetri nets, and, i.e., independent of the initial marking M0are called structural properties. They can be often characterized in terms of incidence matrix.
Reachability • A marking Mn is said to be reachable from a marking M0 if there exist a sequence of firings that transforms M0 into Mn. • A firing sequence is denoted by: = M0 t1 M1 t2 M2 ..… tn Mn or simply = t1 t2 ….. tn • In the case Mn is reachable from M0 by we write M0[] Mn • The set of all possible markings reachable from M0 in a net (N, M0) is denoted by R(M0). • The set of all possible firing sequences from M0 in a net (N, M0) is denoted by L(M0). • The reachability problem for Petri nets is the problem of finding Mn R(M0) for a given marking Mn and a set (N, M0).
Boundedness • A Petri net (N, M0) is said to be k-bounded or simply bounded if the number of tokens in each place does not exceed a finite number k for any marking reachable from M0. • Ex: M(p) k for every place p and every marking M R(M0) • A Petri net is said to be safe if it is 1-bounded. • Places in Petri nets are often used to represent buffers and registers for sharing intermediate data. By verifying that the net is bounded or safe it is guaranteed that there will be no overflows in the buffers or registers, no matter what firing sequence is taken.
Liveness • This concept is closely related to the complete absence of deadlocks (i.e., two or more components reciprocally condition their actions so that no action take place). • A Petri net (N, M0) is said to be live (or equivalently M0 is said to be a live marking for N) if no matter what marking have been reached from M0, it is possible to ultimately fire any transition of the net by progressing through some further firing sequence. • This means that a live Petri net guarantees dead-lock free operation, no matter what firing sequence is chosen. • Strong property, different levels of liveness are defined (L0=dead, L1, L2, L3 and L4=live)
Reversibility and Home State • A Petri net is said to be reversible if for any marking M R(M0) (=set of all possible markings reachable from M0), M0 is reachable from M. In a reversible net we can always get back to the initial marking or state. • In many applications it is not necessary to get back to the initial state as long as we can get back to some (home) state. A marking M’ is said to be in a home state if for each marking M R(M0), M’ is reachable from M.
Coverability • A marking M in a Petri net (N, M0) is said to be coverable if there exist a marking M’ R(M0)(= the set of all possible markings reachable from M0) such that M’(p) M(p) for each place p in the net. • Coverability is closely related to liveness. • Let M be the minimum marking needed to enable a transition t. • The transition t is dead if and only if M is not coverable or • transition t is live if and only if M is coverable.
Structural PROPERTIES • Structural Liveness • A Petri net N is said to be structurally live if exists a live initial marking for N. • Every marked graph is structurally live. • Controllability • A Petri net N is said to be completely controllable if any marking is reachable from any other marking. • Structural Boundedness • A Petry Net N is said to be structurally bounded if it is bounded for any finite initial marking M0.
Conservativeness • A Petri net N is said to be conservative if there exists a positive integer y(p) for every place p such that the weighted sum of tokens, MT y = M0T y = constant, for every M R(M0) and for initial marking M0. • In other words, a Petri net N is conservative if there exists an m-vector y of positive integers such that A y = 0, y 0. • A Petri net N is said to be partially conservative if there exists a nonnegative (positive or zero) integer y(p) for some place p such that the weighted sum of tokens, MT y = M0T y = constant, for every M R(M0) and for initial marking M0. • In other words, a Petri net N is partially conservative if there exists an m-vector y of nonnegative (positive or zero) integers such that A y = 0, y 0
Analysis Methods • One can identify three groups of methods for analysis of Petri nets: • Coverability treesconsist in enumeration of all reachable markings or their coverable markings. It is limited to small nets because of the complexity. • Matrix equation approach is powerful but in many cases is applicable only to special subclasses of Petri nets. • Reduction or decompositionends with a general program to reduce Petri nets.
Coverability (reachability) tree 1 • Tree representation of all possible markings • root = M0 • nodes = markings reachable from M0 • arcs = transition firings • If net is unbounded, then tree is kept finite by introducing the symbol • Properties • a PN is bounded iff doesn’t appear in any node • a PN is safe iff only 0’s and 1’s appear in nodes • a transition is dead iff it doesn’t appear in any arc • if M is reachable form M0, then exists a node M’ that covers M
Coverability Tree 2 1) Label the initial marking M0 as the root and tag it “new.“ 2) While “new” markings exist, do the following: 2.1) Select a new marking M. 2.2) If M is identical to a marking on the path from the root to M, then tag M “old“ and go to another new marking. 2.3) If no transitions are enabled at M, tag M ”dead-end.” 2.4) While there exist enabled transitions at M, do the following for each enabled transition t at M: 2.4.1) Obtain the marking M’ that results from firing t at M. 2.4.2) On the path from the root to M if there exists a marking M” such that M’(p) ≥M”(p) for each place and M’≠M”, i.e., M” is coverable, then replace M’(p) by w for each p such that M’(p) > M”(p). 2.4.3) lntroduce M’ as a node, draw an arc with label t from M to M’, and tag M’ “new.“
Coverability (reachability) Tree 3 For the initial marking M0 = (1 0 0), the two transitions t1, and t3 are enabled. Firing t1, transforms M0 to M1 = (0 0 1), which is a “dead-end“ node, since no transitions are enabled at M1. Now, firing t3 at M0 results in M3 = (1 1 0), which covers M0 = (1 0 0). Therefore, the new marking is M3 = (1 ω0), where two transitions t1 and t3 are again enabled. Firing t1 transforms M3 to M, = (0 ω 1), from which t2 can be fired, resulting in an “old” node M5 = M4. Firing t3 at M3 results in an “old” node M6 = M3.
Coverability tree example M0=(100) p1 t3 p2 t1 t0 t2 p3
Coverability tree example M0=(100) t1 p1 t3 M1=(001) “dead end” p2 t1 t0 t2 p3
Coverability tree example M0=(100) t1 t3 p1 t3 M1=(001) “dead end” M3=(10) p2 t1 t0 t2 p3
Coverability tree example M0=(100) t1 t3 p1 t3 M1=(001) “dead end” M3=(10) t1 p2 t1 t0 M4=(01) t2 p3
Coverability tree example M0=(100) t1 t3 p1 t3 M1=(001) “dead end” M3=(10) t1 t3 p2 t1 t0 M4=(01) M3=(10) “old” t2 p3
Coverability tree example M0=(100) t1 t3 p1 t3 M1=(001) “dead end” M3=(10) t1 t3 p2 t1 t0 M4=(01) M6=(10) “old” t2 t2 p3 M5=(01) “old”
Coverability tree example M0=(100) 100 t1 t3 t1 t3 M1=(001) “dead end” M3=(10) 001 10 t1 t3 t1 t3 M4=(01) M6=(10) “old” 01 t2 t2 M5=(01) “old” coverability graph coverability tree
Incidence Matrix • For a Petri net N with n transitions and m places, the incidence matrix A = [aij] is an n x m matrix of integers and its typical entry is given by aij = aij+ - aij- where • a+ = w(i,j ) is the weight of the arc from transition i to its output place j and • a- = w(j,i ) is the weight of the arc to transition i from its input place j . Petri net representation of mutual exclusion A | abcd e ---|------------------- t1 | -1 1 0 0 -1 t2 | 1 -1 0 0 1 t3 | 0 0 -1 1 -1 t4 | 0 0 1 -1 1
State Equation Let be marking Mk an m x 1 column vector. The j-th entry of Mkdenotes the number of tokens in place j immediately after the k-th firing in some firing sequence. The k-th firing or control vector ukis an n x 1 column vector of n - 1 0's and one nonzero entry, a 1 in the i-th position indicating that transition i fires at the k-th firing. Since the i-th row of the incidence matrix A denotes the change of the marking as the result of firing transition i , we can write the following state equation for a Petri net. Mk = Mk-1 + AT • uk k = 1, 2, 3, Suppose that a destination marking Mdis reachable from M0through a firing sequence {u1, u2, … , ud } . Writing the state equations for i = 1 , 2 , . . . , d and summing them, we obtain AT • x = ΔM where: ΔM = Md – M0 and x is the firing count vector. The i-th entry of x denotes the number of times that transition i must fire to transform M0to Md. An integer solution of the homogenous equation ATx = 0 (i.e., M0 =Md)is called T-invariant. An integer solution of the transposed homogenous equation yTAT=Ay=0 is called S-invariant.
State Equation - Example A | p1 p2 p3 p4 ---|------------------- t1 | -2 1 1 0 t2 | 1 -1 0 -2 t3 | 1 0 -1 2 Mk = Mk-1 + AT • uk, k = 1, 2, 3, … For k=1, the transition t3fires to result in the marking M1= (3 0 0 2)Tfrom M0= (2 0 1 0)T
Necessary and Sufficient Conditions for some Structural Properties
S-invariants An m-vector y of integers is called an S-invariant (place invariant) if A y = 0 For any firing sequence S from M0, the marking reached is given by Mk= M0 + AT• s. Left multiplication of both terms by yT leads to: yT • Mk.= yT • M0 + yT • AT • s. Thus, if yT • AT = 0, we have yT • Mk= yT • M0 whatever s may be, i.e., for every . Since yT • M0 is a scalar quantity, yT • Mk is a marking invariant. In other words, the number of tokens in the set of places P(y) weighted by vector y, is constant. U|AT | 1234 -----|-------------------------------- a | 1 0 0 0 0 -1 1 0 0 b | 0 1 0 0 0 1 -1 0 0 c | 0 0 1 0 0 0 0 -1 1 d | 0 0 0 1 0 0 0 1 -1 e | 0 0 0 0 1 -1 1 -1 1 y1 = [0 1 0 1 1]T y2 = [0 0 1 1 0]T y3 = [1 1 0 0 0]T Since y 0, A y = 0 this Petri net is structurally bounded. Since y 0, A y = 0 this Petri net is partially conservative.
S-invariants For j=1 we add new rows a+b and b+e ------------------------------------- a+b | 1 1 0 0 0 0 0 0 0 b+e | 0 1 0 0 1 0 0 -1 1 Erase used rows a, b, e (having in col 1 elements not equal 0) So we have: U|AT | 1234 -------|-------------------------------- c | 0 0 1 0 0 0 0 -1 1 d | 0 0 0 1 0 0 0 1 -1 a+b | 1 1 0 0 0 0 0 0 0 b+e | 0 1 0 0 1 0 0 -1 1
S-invariants For j=3 we add new rows c+d and d+b+e c+d | 0 0 1 1 0 0 0 0 0 d+b+e | 0 1 0 1 1 0 0 0 0 Erase used rows c, d, b+e (having in col 3 elements not equal to 0) So we have: U|AT | 1234 -------|-------------------------------- a+b | 1 1 0 0 0 0 0 0 0 c+d | 0 0 1 1 0 0 0 0 0 d+b+e | 0 1 0 1 1 0 0 0 0 y1 = [0 1 0 1 1]T y2 = [0 0 1 1 0]T y3 = [1 1 0 0 0]T
Step 1. Let U be the dimension n unit matrix (n = number of places) and AT(transpose incidence matrix). Construct matrix [U | AT], Step 2. For each index jof transition Tj Step 2.1. Add to matrix [U | AT] as many lines i as there are linear combinations of two lines, with positive integer coefficients, such that element (i,j) is zero. Step 2.2. Eliminate from matrix [U | AT] all the lines k whose element (k, j) is not zero. Step 3. Let lU • lAdenote a line lof the matrix [U | AT] and P(lU) the support of lU(i.e., the set of places for which the weight is not zero). If there are two lines p and q of the matrix such that then line p is removed. Step 4. The minimal support S-invariants correspond to the non zero lines of A Step 1. The matrix of 4 lines (P1to P4) and 7 columns is obtained. Step 2. Step 2.1 for T1 (j=1):the line P1 + P2is added which is the sum of the first two lines. Step 2.2 for T1: lines P1and P2are removed • Step 2.1 for T2 (j=2): the line P3 + 2 P4is added (weight 1 for P3and weight 2 for P4). • Step 2.2 for T2: lines P3and P4are removed. • Step 2.1 for T3: no lines are added. • Step 2.2 for T3: line P1 + P2is removed. • Step 3. No lines can be removed. Example Step 4. Only line P3 + 2 P4remains, which indicates that there is a conservative component (P3, P4)with respective weights 1 and 2 for these two places, i.e., the only minimal S-invariant is x = (0, 0, 1, 2). Search for S-invariants
T-invariants A n-vector x of integers is called a T-invariant (firing invariant) if it is a non-trivial solution of ATx = 0 U|A | abcde ------|---------------------------------- t1 | 1 0 0 0 -1 1 0 0 -1 t2 | 0 1 0 0 1 -1 0 0 1 t3 | 0 0 1 0 0 0 -1 1 -1 t4 | 0 0 0 1 0 0 1 -1 1 The T-invariants are: x1= [0 0 1 1]T x2 = [1 1 0 0]T Mk= Mk-1 + AT xk = Mk-1
Reduction • To facilitate the analysis of large systems, we often reduce the system model to a simpler one, while preserving the properties to be analyzed. Conversely, techniques to transform an abstract model into a more refined one can be used for synthesis. • There exist many transformation techniques for Petri nets. • Due to theirs complexity it is important to develop methods of transformations which allow hierarchical reductions and preserve properties to be analyzed. In such an approach, subnets are reduced to single transition or places while keeping liveness and/or boundedness properties
Analysis methods • Reduction rules that preserve liveness, safeness and boundedness • Fusion of Series Places • Fusion of Series Transitions • Fusion of Parallel Places • Fusion of Parallel Transitions • Elimination of Self-loop Places • Elimination of Self-loop Transitions • Help to cope with the complexity problem
Place Reduction R1 A place pi can be eliminated if: 1) Its output transition has no other input places. 2) There is no transition that is simultaneous input and output. 3) At least one output transition of pi has at least an output place. The elimination process is associated with modifications of input and output transitions as well the marking.
Place Reduction (1) • If the place p to be eliminated has k outputs and is marked, then by eliminating process we obtain k distinct nets. • In each case the marking is placed in a place corresponding to an output transition. The properties conserved by R1 reduction are: boundedness, safeness, liveness, reversibility, conservability.
Implicit place reduction (R2) • A place pi is implicit if: • Its marking permits execution of any output transition which can be executed if pi is ignored. • Its marking can be determined from the other places marking. An implicit place can be eliminated together with its connected arcs The properties conserved by R2 reduction are: boundness, liveness, reversibility, conservability.
Null transition reduction (R3) • A transition is called null transition if and only if the set of its input places is the same with output places. • In the figure transition t5 is a null transition; it can be reduced together with its connecting arcs. • Properties of boundness, safeness, liveness and conservability holds for initial Petri net if and only if they hold for reduced Petri net.
Reduction with invariants conservation Pre(p, t) = ●t = the set of the input places of transition t. Post(t, p) = t● = the set of output places of transition t. Recall that: • A Petri net is said to be ordinary if all of its arcs weights are 1. • A Petri net is said to be generalized if it has some arcs with weight greater than 1. • A transition is said to be pure if it has no self-loop. In other words all its inner products Pre(pj, t) x Post(t, pj) == 0 • A transition is said to be impure if it has a place p in the same time as input node and output node. In other words, at least one inner product Pre(pj, t) x Post(t, pj) != 0
Identical transition reduction • Two transitions t1 and t2 is said to be identical if they have the same input places and the same output places. • It is possible to reduce one of them together with its input and output arcs. • The properties conserved by such a reduction are: boundedness, safeness, liveness, reversibility, conservability.
Reduction with invariants conservation The following transforms preserve the invariants: Ra reduction refers to impuretransitions. An impuretransitiont is a transition that has a place p which is, at the same time, an input node and an output node. We reduce it by: -eliminating arcs (p, t) and (t, p). -eliminating t if t becomes isolated. Rb reduction refers to a puretransition. It is absolutely necessary that the set of input places and the set of output places for this transition to be not void. The Rb reduction works as follow: - replace each pair of places pi Pre(p, t) and pj Post(t, p) with a new place pi + pj whose marking is M(pi) + M(pj). The input transitions of the place pi + pj are given by input transitions of pi input transitions of pj less transition t. The output transitions of the place pi + pj are given by output transitions of pi output transitions of pj less transition t.
Example • Rb reductions are applied successively for transitions t2, t3 and t4. • Then a Ra reduction is applied to transition t1. • The result consists in two S-invariants as follows: M(p1) + M(p2) + M(p4) = 1 M(p1) + M(p3) + M(p5) = 2 (a) initial Petri net; (b) after Rb(t2); (c) after Rb(t3); (d) after Rb(t4); (e) after Ra(t1)
Ra’ ImpureTran Reduction Algorithm Let t such a transition and a place p for which Pre(pj, t) = r > 0 and Post(t, pj) = q > 0. The reduction depends on the relation between r and q and consists in the reduction of the arc (p, t) or (t, p) as follows: if(r < q) reduce arc (p, t) set the weight of the arc (t, p) = |r – q| else if(r == q) reduce arc (p, t) reduce arc (t, p) else if(r > q) reduce arc (t, p) set the weight of the arc (p, t) = |r – p| Finally if transition t becomes isolated reduce it.
Rb’ PureTran Reduction Algorithm Let t a pure transition which has at least one input place and at least one output place. The process of elimination works as follows: -reduce the pure transition t. -for each pair (pj, pk) where: pj is an input place of transition t and pk is an output place of transition t we associate a place q pj + r pk, (where q = Post(t, pk) and r = Pre(pj, t)) having marking q M(pj) + r M(pk) -each input (output) transition of place pi (except t) becomes input (output) transition of the place q pj + r pk with weight multiplied by q. -each input (output) transition of place pk (except t) become input (output) transition of the place q pj + r pk with weight multiplied by r. The input transitions of the place q pj + r pk are given by: input transitions of pj input transitions of pk less transition t. The output transitions of the place pj + pk are given by: output transitions of pj output transitions of pk less transition t.