4.3 IDD-based On-the-fly Matrix Generation
4.3.2 Enumeration of State Transitions
Now, as we are able to enumerate the lexicographic indices related to a set of states, we can think about the enumeration of the state transitions, i.e. the ma- trix entries, each specified by a row and a column index and a real value. In previous approaches, the indices and the value of a matrix entry are computed either given an explicit (e.g. sparse matrices) or an implicit matrix representa- tion (MxD, MTBDD). In any case, information concerning the row and column indices and the matrix entries are held in the same data structure.
Devours and Sanders [45] proposed an explicit matrix-free approach for several high-level formalisms, among them GSPN. The state transitions were computed on-the-fly, meaning that for a given state the effect of transition firing is utilized to determine the successor states and thereby the set of the related state tran- sitions. To the best of my knowledge there is no published symbolic adaption of this approach.
The general idea. The operation Fire in Section 2.2.2 (and analogously RevFire) can be adapted to an operation which just extracts state transitions. Instead of creating for the states S and the transition t the IDD representation GF ire(S,t)
of the successor set, it computes the indices and the assigned value of the corre- sponding state transitions. Algorithm 17 shows the procedure EnumerateTransi- tions which enumerates all state transitions induced by the firing of the transition t in the state set S.
The procedure extracts recursively the states encoded in the IDD GS. Similar
to Algorithm 13 and Algorithm 15, it extracts simultaneously a state s (src) in the LIDD ˆGS and computes its lexicographic index ıs. Moreover it determines
the successor state s′ (dest) and its index ıs′. Therefor it exploits the enabling
token interval (a.enabled) and the change of tokens (a.shif t) on each place p ∈ Envt provided by the related element in the action list al. The algorithm
simultaneously computes for each state transition sÐ→ st ′ 1. the path of the state s in the IDD GS,
2. the path of the state s in the LIDD ˆGS and its lexicographic index ıs,
3. the path of the state s′ in the LIDD ˆGS and its lexicographic index ıs′.
It remains to compute the actual matrix entry M(s,s′) = ft(s), i.e. the value
which is assigned to the state transition and defined by the possibly state- dependent function ft of the Petri net transition. At this point I do not require
4.3 IDD-based On-the-fly Matrix Generation
Algorithm 17 (Enumerate – State transitions)
1 proc AuxEnumerateTransitions(v , ˆvsrc, ˆvdest : unsigned, isrc , idest : IndexT, 2 al : ActionList , f : Function , args: FunctionArguments, op∶ OP)
3
4 if op.firstUse(v , ˆvsrc, ˆvdest, isrc, idest,al ,f ,args) then
5 return
6 fi
7 for 1≤ j ≤ ∣p(ˆv)∣ do
8 for inf(Ij) ≤ ssrc< sup(Ij) do
9 al′:= al
10 if al ≠⊥ then
11 a := head(al )
12 if var(v ) = a.var then
13 if ssrc/∈ a.enabled then continue fi
14 sdest := ssrc+ a.shift
15 op.setArgument(var(ˆv),args, ssrc,sdest)
16 al′ := tail(al ) 17 fi 18 fi 19 v′ := cj(v ) 20 isrc′ := isrc+r(ˆvsrc,ssrc) 21 ˆvsrc′ :=c(ˆvsrc,ssrc)
22 if not isValid(ˆvsrc′ ) then continue fi 23 idest′ := idest+r(ˆvdest,sdest)
24 ˆvdest′ :=c(ˆvdest,sdest)
25 if isValid(ˆvdest′ ) then
26 AuxEnumerateTransitions(v′,ˆvsrc′ ,ˆvdest′ ,isrc′ ,idest′ , al′,f ,args,op)
27 fi
28 od
29 od
30 op.secondUse(v , ˆvsrc, ˆvdest, isrc, idest,al , f ,args) 31 end
32 proc EnumerateTransitions (GS : IDD , t : transition, op∶ OP)
33 args : ft.createArgs()
34 al := op.selectActionList(alt,revAlt);
35 AuxEnumerateTransitions(GS.root, ˆGS.root , ˆGS.root ,0, 0,al ,F(t),args,op) 36 end
4 Advanced Matrix Representation
a special semantics of ft (and thus M). It may define a rate of a timed transi-
tion, the weight of an immediate transition or a secondary probability as R(s,sE(s)′) (P) or R(s,sλ ′) (PU). In any case, the procedure must collect the function argu-
ments specified by the individual sub-states. The interface for Functions and FunctionArguments was already specified in Algorithm 5.
The procedure EnumerateTransitions is parameterized with the type of opera- tion (OP) which is finally applied to each extracted state transition. The actual work is done by the parametrized auxiliary function AuxEnumerateTransitions. The special feature of AuxEnumerateTransitions is in particular the processing of the variable of the visited IDD node with respect to the firing of the transition t. If the variable represents a place from t′s environment (line 12), it checks the
enabledness of t in the current sub-state (line13). If t is enabled, the value of the
variable of the resulting state sdest is computed (line 14) and used to determine
the child node in the LIDD ˆGS (line 24). The rest should be self-explanatory. For
reasons of performance I restrict the set of permitted function variables to the environment of the corresponding Peri net transition (line 15).
I assume that the state set S is a subset ofS. However, when firing the transition backwards, the algorithm may explore states which are not in S. This situation is treated in line 25, where in the case of an invalid assignment the function
c(ˆvdest,sdest) returns the 0-terminal node.
The given procedure can be used to enumerate the entries of the matrix M or its transpose MT. The latter can be easily achieved by firing all transitions in
backward direction. The operation type OP specifies further the traversal policy and must take care of the following aspects:
A first evaluation of the node v. Thus the procedure firstUse must be de-
fined. If v is for instance the 1-terminal node, a state transition has been extracted and the actual operation is performed. Its return value tells AuxEnumerateTransitions whether to continue the traversal with the eval- uation of the outgoing arcs. The procedure has also to define the basic operation which is applied to an extracted state transition.
A second evaluation of the node v after traversing the outgoing arcs. The
procedure secondUse must be defined if it is required to perform actions after the recursive traversal. The functions firstUse and secondUse are es- pecially important for the optimization I will discuss in the remainder.
The fire direction of the transition which is represented by the used action
4.3 IDD-based On-the-fly Matrix Generation
The selection of the function arguments by the procedure setArgument. If
the transition fires backwards, the argument depends on the successor state s′.
At this point it should be mentioned that the formulation of the algorithms is meant to clearly illustrate the underlying ideas. The actual implementation is of course much more optimized.
Example 12
Let us consider again the LIDD in Figure 4.2, the selected states s1, s2
and s3 in Example 11 and two Petri net transitions in Figure 3.3.
When applying Algorithm 17 with the reachable states GS and the
transition produce choose b2 the fourth extracted path is ρs1 as its
lexicographic index ıs1 is 3. In node v9, node v11 and node v15 the
algorithm emulates the firing of the Petri net transition. It ”removes” a token from the place ready and ”puts” a token on place item and on place to2. The path of the target state s′1 is in this case
v15 1 Ð→ v14 0 Ð→ v12 1 Ð→ v10 0 Ð→ v8 0 Ð→ v6 2 Ð→ v5 0 Ð→ v2 1 Ð→ 1
which we already know as ρs2. It also computes the associated value
as
0.1⋅ 1/(1 + s1(b1) + s1(b2)) = 1/(1 + 0 + 2) = 0.03.
This gives the rate matrix entry R(s1, s2) = R(3,23) = 0.03.
The application of the algorithm for transition consume fetch b2 1 gives, among others, the entry R(s1, s3) = R(3,2) = 1. In total, Al-
gorithm 17 enumerates 73 state transitions for the reachable state S and all Petri transitions .
Observation. A transition which changes the marking of the top- place induces state transitions with a large index jump concerning the row and the column index. A transition which only changes the marking of places in lower levels causes small index jumps.
☀
Algorithm 17 permits to realize the operations for the numerical analysis of SPN. I will discuss their implementation in Chapter 5. For now I illustrate its use to print the rate matrix R of a CTMC, given as SPN NS and the LIDD
4 Advanced Matrix Representation
representation ˆGS of its reachable state S. We use the procedure PrintRates
and the related functor given in Algorithm 18. The entries of the matrix will not been printed line-by-line. The algorithm prints the state transitions induced by the Petri net transition ti before those of the transitions tj ∈ T ∶ j > i. A
line-by-line enumeration is only observable when applying the algorithm for a single transition. Numerical solvers as Gauss-Seidel which require to extract the matrix entries line-wise can not be realized with such an enumeration policy.
Algorithm 18 (Print the rates)
1 struct PrintRates
2 func firstUse(v , ˆvsrc, ˆvdest : unsigned, isrc , idest : IndexT,
3 al : ActionList , f : Function , args: FunctionArgument)
4 if v = 1 then
5 print(isrc+ ’,’+idesr+′∶′+f (args))
6 return true
7 fi
8 if v = 0 then return true fi
9 //otherwise the traversal can not be stopped
10 return false
11 end
12
13 proc secondUse(v , ˆvsrc, ˆvdest : unsigned, isrc , idest : IndexT,
14 al : ActionList , f : Function , args: FunctionArgument)
15 //nothing to do
16 end
17 proc setArgument(var : unsigned, args: FunctionArguments,
18 src : unsigned, dest : unsigned)
19 args.setArgument(var, dest);
20 end
21 func selectActionList(al : ActionList, revAl : ActionList)
22 return al
23 end
24 end
25 proc PrintRates(GS : IDD, CTMC : [ ˆGS,NS])
26 pr : struct PrintRates
27 for t∈ NS.T do
28 EnumerateTransitions(GS,t ,pr )
29 od
4.3 IDD-based On-the-fly Matrix Generation