Chapter 3. Petri Net Transition Mergence
3.4 Transition Mergence Algorithm
The construction-based algorithm for transition mergence is discussed in this section, where the two algorithms discussed in last two sections are used to explain the concept of transition mergences.
Algorithm 3.3: PNTransitionMergenceV2(PetriNet PN , PetriNet PN1 2, MergingRelation MR)
1 generate result Petri net PN;
2 s1pool = {∅} is a set of marking;
3 s2pool = {∅} is a set of marking;
4 add MPN1,PN2(m1, m2) into O-graph OG and s1pool where m1 is the initial marking of PN1 and m2 is the initial marking of PN2;
5 WHILE (s1pool or s2pool is not empty) 6 WHILE (s1pool is not empty)
35 remove all labels on v;
This algorithm does a transition mergence according to the merging relation MR between two Petri nets PN1 and PN2 and returns the result Petri net and its O-graph, which is built by a construction-based way in this algorithm. All inputs must conform to the definitions about transition mergences. The detail of this algorithm is shown in the appendix Algorithm A.
This algorithm builds the new O-graph OG starting from the initial marking and continuing generating the arcs and the markings that can reach from the markings in OG (i.e.
the arcs conforming with Proposition 3.4 (9) or (10) and the markings conforming with Proposition 3.4 (14)). It has not the problem about loops existing in Algorithm 3.2 because the unreachable markings are never put into OG to build unreachable paths to them self.
Line 1 in the algorithm constructs places, transitions, and the flow relations of PN while the rest of the Lines generate OG, the O-graph of PN. Lines 2 and 3 initial two pools used in
the rest of this algorithm. s1pool records the markings that have not been examined with the O-graph belonging to PN1 while s2pool records the markings that have not been examined with the O-graph belonging to PN2 but have already been examined with that belonging to PN1. Line 4 creates the initial marking merged from the two initial markings in two original nets then put it into s1pool. Lines 5 to 37 describe a loop which jumps out when s1pool and s2pool are both empty, which indicates that all current markings in OG are already examined with two original nets and OG has been completely built.
The loop from line 6 to line 19 is executed if any marking exists in s1pool. It removes a marking v = MPN1,PN2(v1, v2)from s1pool at line 7 and deals with this marking at a time. The loop from line 8 to line 17 checks an arc a1 that starts at v1 in PN1 corresponding to v at a time.
If a1 is corresponding to a transition to be merged, line 10 labels a1 on v sets a related flag recording this transition pair and the arc RPN1,PN2(a1, v) is not created (by Proposition 3.4 (5), the arc does not exist in the new O-graph). If a1 is corresponding to a transition that is not to be merged (the arc satisfies the conditions of Proposition 3.4 (10)), a related new arc RPN1,PN2(a1, v) is generated and put into OG at line 12. If the marking pointed by RPN1,PN2(a1, v) (the marking satisfies the conditions of Proposition 3.4 (11)) does not exist in OG, it is generated and added into OG and s1pool at line 14. v is added into s2pool at line 18 after the examining mentioned above is done.
The loop from line 20 to line 35 is executed if any marking exists in s2pool. It removes a marking v = MPN1,PN2(v1, v2) from s2pool and deals with this marking at a time. Although this loop is like that from line 6 to line 19 but to check with PN2, there are still some different points. Lines 21 and 22 check that if the transition t2 corresponded by a2 must be merged with t1 and there is an arc (v1, t1, w1) labeled on v (this situation satisfies the conditions of Proposition 3.4 (9) where v1 = v). If so, line 23 creates a new arc (v, (t1, t2), MPN1,PN2(w1, w2) )
where w2 is the marking pointed by a2 in PN2. If MPN1,PN2(w1, w2) does not exist in OG, it is generated and added into OG and s1pool at line 25.
Since only v1 belongs to V in Proposition 3.4 items (9) and (10) and (v1, t, vb) belongs to A in item (11), all other conditions in these items only relate with the elements in the O-graph before the transition mergence (which can create from the two original O-graphs by functions M and R), the current state of the new O-graph under the algorithm operated does not influence the examination of a marking corresponding to v1 according to the three items. So, each marking only needs to be checked with the two original nets one time. This algorithm uses the two pools to make sure that each marking in new O-graph is checked exactly one time by two original nets. Since all markings in an O-graph are reachable from its initial marking, there is no marking or arc being lost by the algorithm.
Now, Algorithm 3.3 can be compared with the original algorithm ([2]) that constructs the O-graph directly from its corresponding Petri net.
10 END
Node(v) is a procedure that creates a new node (marking) v and adds v into Waiting, a set
of markings, and the new O-graph. If v exists in the O-graph already, the procedure does nothing. Next(v1) is used to denote the set of all possible “next moves” from v1. I.e., Next(v1)
= {(t, v2) ∈ T × V | v2 is the marking after firing t on v1}. Arc(v1, t, v2) is a procedure that creates a new arc (v1, t, v2) and adds it to the new O-graph.
Let n be the number of nodes in the result O-graph. The loop from line 3 to line 10 repeats n times because each node contained in the result O-graph should be added into Waiting and examined one time in this loop. Let t be the number of transitions in the Petri net.
Since the set Next(v1) must be known at line 5, each transition in the result net must be examined whether it is enabled by v1 or not. This indicates that the complexity of finding the set Next(v1) is O(t). Because Node(v) does nothing if v exists in the result O-graph already, the procedure Node(v) checks if v is already in O-graph and the complexity of this search is O(n). So, the complexity of this algorithm is O(n * t * n). This complexity is also shown in [16].
Now, check the complexity of Algorithm 3.3. Since all markings that must be added into the result O-graph should be checked one time with two subnets, the loop from line 6 to 19 and that from 20 to 36 will run n * 2 times totally when considering the loop from 5 to 37. Let t1 be the number of transitions in PN1 and t2 be the number of transitions in PN2. The loop from line 8 to line 17 runs t1 times at most because each marking in the O-graph of PN1 can have t1 arcs as output at most. With similar reason, the loop from line 20 to line 34 runs t2
times at most. While t1, t2 ≤ t, the complexity of the two loops are O(t). Note that each marking usually enables a small part of all the transitions only, so the running times of the two loops usually are much fewer than t. The complexity of Algorithm 3.3 is O(n * t).
Although the complexity of Algorithm 3.3 is smaller than the complexity of the original algorithm, there are still situations which influence the time of generating the final result Petri net by merging a set of nets while applying a transition mergence have some differences with applying the original algorithm. These situations are discussed in Section 4.2.