Stochastic Petri Net Serge Haddad LSV ENS Cachan & CNRS & INRIA haddad@lsv.ens-cachan.fr Petri Nets 2013, June 24th 2013 1 Stochastic Petri Net 2 Markov Chain 3 Markovian Stochastic Petri Net 4 Generalized Markovian Stochastic Petri Net (GSPN) 1/33
Plan 1 Stochastic Petri Net Markov Chain Markovian Stochastic Petri Net Generalized Markovian Stochastic Petri Net (GSPN) 2/33
Stochastic Petri Net versus Time Petri Net In TPN, the delays are non deterministically chosen. In Stochastic Petri Net (SPN), the delays are randomly chosen by sampling distributions associated with transitions.... but these distributions are not sufficient to eliminate non determinism. Policies for a net One needs to define: The choice policy. What is the next transition to fire? The service policy. What is the influence of the enabling degree of a transition on the process? The memory policy. What become the samplings of distributions that have not be used? 3/33
Stochastic Petri Net versus Time Petri Net In TPN, the delays are non deterministically chosen. In Stochastic Petri Net (SPN), the delays are randomly chosen by sampling distributions associated with transitions.... but these distributions are not sufficient to eliminate non determinism. Policies for a net One needs to define: The choice policy. What is the next transition to fire? The service policy. What is the influence of the enabling degree of a transition on the process? The memory policy. What become the samplings of distributions that have not be used? 3/33
Choice Policy In the net, associate a distribution D i and a weight w i with every transition t i. Preselection w.r.t. a marking m and enabled transitions T m Normalize weights wi of the enabled transitions: w i w i t j Tm wj Sample the distribution defined by the w i s. Let ti be the selected transition, sample D i giving the value d i. versus Race policy with postselection w.r.t. a marking m For every ti T m, sample D i giving the value d i. Let T be the subset of T m with the smallest delays. Normalize weights w i of transitions of T : w i w i t j T wj Sample the distribution defined by the w i s yielding some t i. (postselection can also be handled with priorities) 4/33
Choice Policy In the net, associate a distribution D i and a weight w i with every transition t i. Preselection w.r.t. a marking m and enabled transitions T m Normalize weights wi of the enabled transitions: w i w i t j Tm wj Sample the distribution defined by the w i s. Let ti be the selected transition, sample D i giving the value d i. versus Race policy with postselection w.r.t. a marking m For every ti T m, sample D i giving the value d i. Let T be the subset of T m with the smallest delays. Normalize weights w i of transitions of T : w i w i t j T wj Sample the distribution defined by the w i s yielding some t i. (postselection can also be handled with priorities) 4/33
Choice Policy: Illustration t 1 (D 1,w 1 ) t 2 (D 2,w 2 ) t 3 (D 3,w 3 ) w 1 =1 w 2 =2 w 3 =2 Preselection Race Policy Sample (1/5,2/5,2/5) Outcome t 1 Sample D 1 Outcome 4.2 Sample (D 1,D 2,D 3 ) Outcome(3.2,6.5,3.2) Sample(1/3,-,2/3) Outcome t 3 5/33
Server Policy A transition t can be viewed as server for firings: A single server t allows a single instance of firings in m if m[t. An infinite server t allows d instances of firings in m where d = min( m(p) p t) is the enabling degree. P re(p,t) A multiple server t with bound b allows min(b, d) instances of firings in m. 3 t 1 t 2 t 3 t 3 single server Sample (D 1,D 2,D 3 ) t 3 infinite server Sample (D 1,D 2,D 3,D 3,D 3 ) t 3 2-server Sample (D 1,D 2,D 3,D 3 ) This can be generalised by marking-dependent rates. 6/33
Memory Policy (1) d 1 <min(d 2,d 3 ) t 1 t 2 t 3 t 1 t 2 t 3 What happens to d 2 and d 3? Resampling Memory Every sampling not used is forgotten. This could correspond to a crash transition. 7/33
Memory Policy (2) d 1 <min(d 2,d 3 ) t 1 t 2 t 3 t 1 t 2 t 3 What happens to d 2 and d 3? Enabling Memory The samplings associated with still enabled transitions are kept and decremented (d 3 = d 3 d 1 ). The samplings associated with disabled transitions are forgotten (like d2 ). Disabling a transition could correspond to abort a service. 8/33
Memory Policy (3) d 1 <min(d 2,d 3 ) t 1 t 2 t 3 t 1 t 2 t 3 What happens to d 2 and d 3? Age Memory All the samplings are kept and decremented (d 3 = d 3 d 1 and d 2 = d 2 d 1 ). The sampling associated with a disabled transition is frozen until the transition become again enabled (like d 2). Disabling a transition could correspond to suspend a service. 9/33
Memory Policy (4) Specification of memory policy To be fully expressive, it should be defined w.r.t. any pair of transitions. 3 2 d 2 <min(d 1,d 1 ',d 1 '') t 1 t 2 t 1 t 2 What happens to d 1, d 1 ' and d 1 ''? Interaction between memory policy and service policy Assume enabling memory for t 1 when firing t 2 and infinite server policy for t 1. Which sample should be forgotten? The last sample performed, The first sample performed, The greatest sample, etc. Warning: This choice may have a critical impact on the complexity of analysis. 10/33
Plan Stochastic Petri Net 2 Markov Chain Markovian Stochastic Petri Net Generalized Markovian Stochastic Petri Net (GSPN) 11/33
Discrete Time Markov Chain (DTMC) A DTMC is a stochastic process which fulfills: For all n, Tn is the constant 1 The process is memoryless P r(s n+1 = s j S 0 = s i0,..., S n 1 = s in 1, S n = s i ) = P r(s n+1 = s j S n = s i ) P[i, j] A DTMC is defined by S 0 and P 0.3 1 0.7 2 1 0.2 0.8 3 P 0.3 0.7 0.0 0.0 0.0 1.0 0.2 0.8 0.0 12/33
Analysis: the State Status The transient analysis is easy and effective in the finite case: π n = π 0 P n with π n the distribution of S n The steady-state analysis (? lim n π n ) requires theoretical developments. Classification of states w.r.t. the asymptotic behaviour of the DTMC A state is transient if the probability of a return after a visit is less than one. Hence the probability of its occurrence will go to zero. (p < 1/2) A state is recurrent null if the probability of a return after a visit is one but the mean time of this return is infinite. Hence the probability of its occurrence will go to zero. (p = 1/2) A state is recurrent non null if the probability of a return after a visit is one and the mean time of this return is finite. (p > 1/2) 1 1-p 1-p 1-p 0 p 1 p 2 p 3... p 13/33
In a finite DTMC State Status in Finite DTMC The status of a state only depends on the graph associated with the chain. A state is transient iff it belongs to a non terminal strongly connected component (scc) of the graph. A state is recurrent non null iff it belongs to a terminal scc. 0.5 0.3 1 0.7 2 0.1 0.3 0.8 0.4 3 0.2 4 0.5 5 1 0.3 0.1 6 7 0.7 1 0.2 0.8 8 0.1 T={1,2,3} C 1 ={4,5} C 2 ={6,7,8} 14/33
Analysis: Irreducibility and Periodicity Irreducibility and Periodicity A chain is irreducible if its graph is strongly connected. The periodicity of an irreducible chain is the greatest integer p such that: the set of states can be partionned in p subsets S 0,..., S p 1 where every transition goes from S i to S i+1%p for some i. Computation of the periodicity 4 7 1 height 0 2 3 6 4 2 height 1 1 5 8 3 4 height 2 5 6 7 0 2 8 periodicity=gcd(0,2,4)=2 height 3 height 4 15/33
Analysis of a DTMC: a Particular Case A particular case The chain is irreducible and aperiodic (i.e. its periodicity is 1) π lim n π n exists and its value is independent from π 0. π is the unique solution of X = X P X 1 = 1 where one can omit an arbitrary equation of the first system. 0.3 0.7 1 2 0.2 3 1 0.8 = 1/8 7/16 7/16 π 1 = 0.3π 1 + 0.2π 2 π 2 = 0.7π 1 + 0.8π 3 π 3 = π 2 16/33
Analysis of a DTMC: the General Case Almost general case: every terminal scc is aperiodic π exists. π = s S π 0(s) i I preach i [s] πi where: 1. S is the set of states, 2. {C i} i I is the set of terminal scc, 3. π i is the steady-state distribution of C i, 4. and preach i [s] is the probability to reach C i starting from s. Computation of the reachability probability for transient states Let T be the set of transient states (i.e. not belonging to a terminal scc) Let PT,T be the submatrix of P restricted to transient states Let PT,i be the submatrix of P transitions from T to C i Then preachi = ( n N (P T,T ) n ) P T,i 1 = (Id P T,T ) 1 P T,i 1 17/33
Analysis of a DTMC: the General Case Almost general case: every terminal scc is aperiodic π exists. π = s S π 0(s) i I preach i [s] πi where: 1. S is the set of states, 2. {C i} i I is the set of terminal scc, 3. π i is the steady-state distribution of C i, 4. and preach i [s] is the probability to reach C i starting from s. Computation of the reachability probability for transient states Let T be the set of transient states (i.e. not belonging to a terminal scc) Let PT,T be the submatrix of P restricted to transient states Let PT,i be the submatrix of P transitions from T to C i Then preachi = ( n N (P T,T ) n ) P T,i 1 = (Id P T,T ) 1 P T,i 1 17/33
Illustration: SCC and Matrices P T,T = P T,1.1= 0.0 0.7 0.0 0.1 0.0 0.8 0.0 0.2 0.0 0.0 0.3 1.0 0.0 0.0 1.0 0.0 0.4 1.0 T={1,2,3},C 1 ={4,5},C 2 ={6,7,8} = 0.3 0.0 0.4 0.5 0.3 1 0.7 2 0.1 0.3 0.8 0.4 3 0.2 4 0.5 5 1 0.3 0.1 6 7 0.7 1 0.2 0.8 8 0.1 P T,2.1= 0.0 0.0 0.0 1.0 0.0 0.1 0.0 1.0 0.3 0.1 0.0 1.0 = 0.0 0.1 0.4 18/33
Continuous Time Markov Chain (CTMC) A CTMC is a stochastic process which fulfills: Memoryless state change P r(s n+1 = s j S 0 = s i0,..., S n 1 = s in 1, T 0 < τ 0,..., T n < τ n, S n = s i ) = P r(s n+1 = s j S n = s i ) P[i, j] Memoryless transition delay P r(t n < τ S 0 = s i0,..., S n 1 = s in 1, T 0 < τ 0,..., T n 1 < τ n 1, S n = s i ) = P r(t n < τ S n = s i ) = 1 e λiτ Notations and properties P defines an embedded DTMC (the chain of state changes) Let π(τ) the distribution de X(τ), for δ going to 0 it holds that: π(τ + δ)(s i ) π(τ)(s i )(1 λ i δ) + j π(τ)(s j)λ j δp[j, i] Hence, let Q the infinitesimal generator defined by: Q[i, j] λ i P[i, j] for j i and Q[i, i] j i Q[i, j] dπ Then: dτ = π Q 19/33
Continuous Time Markov Chain (CTMC) A CTMC is a stochastic process which fulfills: Memoryless state change P r(s n+1 = s j S 0 = s i0,..., S n 1 = s in 1, T 0 < τ 0,..., T n < τ n, S n = s i ) = P r(s n+1 = s j S n = s i ) P[i, j] Memoryless transition delay P r(t n < τ S 0 = s i0,..., S n 1 = s in 1, T 0 < τ 0,..., T n 1 < τ n 1, S n = s i ) = P r(t n < τ S n = s i ) = 1 e λiτ Notations and properties P defines an embedded DTMC (the chain of state changes) Let π(τ) the distribution de X(τ), for δ going to 0 it holds that: π(τ + δ)(s i ) π(τ)(s i )(1 λ i δ) + j π(τ)(s j)λ j δp[j, i] Hence, let Q the infinitesimal generator defined by: Q[i, j] λ i P[i, j] for j i and Q[i, i] j i Q[i, j] dπ Then: dτ = π Q 19/33
CTMC: Illustration and Uniformization A CTMC λ P λ' P' 5 2 0.3 1 0.7 2 1 0.2 0.8 3 1 10 10 0.65 1 0.35 2 0.2 0.02 0.08 0.9 3 10 1 3.5 2 2 0.2 0.8 3 0.8 A uniform version of the CTMC (equivalent w.r.t. the states) Q 20/33
Analysis of a CTMC Transient Analysis Construction of a uniform version of the CTMC (λ, P) such that P[i, i] > 0 for all i. Computation by case decomposition w.r.t. the number of transitions: π(τ) = π(0) n N (e λτ ) τ n n! Pn Steady-state analysis The steady-state distribution of visits is given by the steady-state distribution of (λ, P) (by construction, the terminal scc are aperiodic)... equal to the steady-state distribution since the sojourn times follow the same distribution. A particular case: P irreducible the steady-state distribution π is the unique solution of X Q = 0 X 1 = 1 where one can omit an arbitrary equation of the first system. 21/33
Analysis of a CTMC Transient Analysis Construction of a uniform version of the CTMC (λ, P) such that P[i, i] > 0 for all i. Computation by case decomposition w.r.t. the number of transitions: π(τ) = π(0) n N (e λτ ) τ n n! Pn Steady-state analysis The steady-state distribution of visits is given by the steady-state distribution of (λ, P) (by construction, the terminal scc are aperiodic)... equal to the steady-state distribution since the sojourn times follow the same distribution. A particular case: P irreducible the steady-state distribution π is the unique solution of X Q = 0 X 1 = 1 where one can omit an arbitrary equation of the first system. 21/33
Plan Stochastic Petri Net Markov Chain 3 Markovian Stochastic Petri Net Generalized Markovian Stochastic Petri Net (GSPN) 22/33
Markovian Stochastic Petri Net Hypotheses The distribution of every transition ti has a density function e λiτ where the parameter λ i is called the rate of the transition. For simplicity reasons, the server policy is single server. First observations The weights for choice policy are no more required since equality of two samples has a null probability. (due to continuity of distributions) The residual delay dj d i of transition t j knowing that t i has fired (i.e. d i is the shortest delay) has the same distribution as the initial delay. Thus the memory policy is irrelevant. 23/33
Markovian Stochastic Petri Net Hypotheses The distribution of every transition ti has a density function e λiτ where the parameter λ i is called the rate of the transition. For simplicity reasons, the server policy is single server. First observations The weights for choice policy are no more required since equality of two samples has a null probability. (due to continuity of distributions) The residual delay dj d i of transition t j knowing that t i has fired (i.e. d i is the shortest delay) has the same distribution as the initial delay. Thus the memory policy is irrelevant. 23/33
Markovian Net and Markov Chain Key observation: given a marking m with T m = t 1,..., t k The sojourn time in m is an exponential distribution with rate i λ i. The probability that ti is the next transition to fire is λ i ( j λj). Thus the stochastic process is a CTMC whose states are markings and whose transitions are the transitions of the reachability graph. t 1 λ 1 2 2 λ 2 λ 3 λ4 λ 5 t 2 t 3 λ 2 λ 3 λ 2 λ 3 λ 4 λ 5 λ 4 λ 5 t 4 t 5 λ 4 λ 2 λ λ 3 5 2 t 6 λ 4 λ 5 λ 6 24/33
Plan Stochastic Petri Net Markov Chain Markovian Stochastic Petri Net 4 Generalized Markovian Stochastic Petri Net (GSPN) 25/33
Generalizing Distributions for Nets Modelling delays with exponential distributions is reasonable when: Only mean value information is known about distributions. Exponential distributions (or combination of them) are enough to approximate the real distributions. Modelling delays with exponential distributions is not reasonable when: The distribution of an event is known and is poorly approximable with exponential distributions: a time-out of 10 time units The delays of the events have different magnitude orders: executing an instruction versus performing a database request In the last case, the 0-Dirac distribution is required. 26/33
Generalized Markovian Stochastic Petri Net (GSPN) Generalized Markovian Stochastic Petri Nets (GSPN) are nets whose: timed transitions have exponential distributions, and immediate transitions have 0-Dirac distributions. Their analysis is based on Markovian Renewal Process, a generalization of Markov chains. 27/33
Markovian Renewal Process A Markovian Renewal Process (MRP) fulfills: a relative memoryless property P r(s n+1 = s j, T n < τ S 0 = s i0,..., S n 1 = s in 1, T 0 < τ 0,..., S n = s i ) = P r(s n+1 = s j, T n < τ S n = s i ) Q[i, j, τ] The embedded chain is defined by: P[i, j] = limτ Q[i, j, τ] The sojourn time Soj has a distribution defined by: P r(soj[i] < τ) = j Q[i, j, τ] Analysis of a MRP The steady-state distribution (if there exists) π is deduced from the steady-state distribution of the embedded chain π by: π(s i ) = π (s i)e(soj[i]) j π (s j)e(soj[j]) Transient analysis is much harder... but the reachability probabilities only depend on the embedded chain. 28/33
Markovian Renewal Process A Markovian Renewal Process (MRP) fulfills: a relative memoryless property P r(s n+1 = s j, T n < τ S 0 = s i0,..., S n 1 = s in 1, T 0 < τ 0,..., S n = s i ) = P r(s n+1 = s j, T n < τ S n = s i ) Q[i, j, τ] The embedded chain is defined by: P[i, j] = limτ Q[i, j, τ] The sojourn time Soj has a distribution defined by: P r(soj[i] < τ) = j Q[i, j, τ] Analysis of a MRP The steady-state distribution (if there exists) π is deduced from the steady-state distribution of the embedded chain π by: π(s i ) = π (s i)e(soj[i]) j π (s j)e(soj[j]) Transient analysis is much harder... but the reachability probabilities only depend on the embedded chain. 28/33
t 4 t 5 t6 A GSPN is a Markovian Renewal Process Observations Weights are required for immediate transitions. The restricted reachability graph corresponds to the embedded DTMC. t 1 t 1 2 2 t t 2 t 3 4 t 5 t 2 t 3 t 2 t 3 t 2 t 3 t 4 t 5 t 4 t 5 t 4 t 5 2 t 6 tangible marking vanishing marking 29/33
Steady-State Analysis of a GSPN (1) Standard method for MRP Build the restricted reachability graph equivalent to the embedded DTMC Deduce the probability matrix P Compute π the steady-state distribution of the visits of markings: π = π P Compute π the steady-state distribution of the sojourn in tangible markings: π (m)soj(m) π(m) = m tangible π (m )Soj(m ) How to eliminate the vanishing markings sooner in the computation? 30/33
Steady-State Analysis of a GSPN (2) An alternative method As before, compute the transition probability matrix P. Compute the transition probability matrix P between tangible markings. Compute π the (relative) steady-state distribution of the visits of tangible markings: π = π P. Compute π the steady-state distribution of the sojourn in tangible markings: π (m)soj(m) π(m) = m tangible π (m )Soj(m ) Computation of P Let PX,Y the probability transition matrix from subset X to subset Y. Let V (resp. T ) be the set of vanishing (resp. tangible) markings. P = P T,T + P T,V ( n N P n V,V )P V,T = P T,T + P T,V (Id P V,V ) 1 P V,T Iterative (resp. direct) computations uses the first (resp. second) expression. 31/33
Steady-State Analysis: Illustration 1 c d/λ 1 p 2 p (p 2 ) 2 (p 3 ) 2 3 2dp 2 p 3 /(λ 4 +λ 4 ) p 2 p 3 p 2 p 3 2p 2 p 3 c(p 2 ) 2 2cp 2 p 3 c(p 3 ) 2 d(p 2 ) 2 /λ 4 d(p 3 ) 2 /λ 5 1 p 5 p 4 1 1 p 5 p 4 1 c((p 2 ) 2 +2p 5 p 2 p 3 ) c((p 3 ) 2 +2p 4 p 2 p 3 ) d((p 2 ) 2 +2p 5 p 2 p 3 )/λ 4 d((p 3 ) 2 +2p 4 p 2 p 3 )/λ 5 1 1 1 1 1 1 c d/λ 6 p 2 =w 2 /(w 2 +w 3 ) p 3 =w 3 /(w 2 +w 3 ) p 4 =λ 4 /(λ 4 +λ 5 ) p 5 =λ 5 /(λ 4 +λ 5 ) c and d are normalizing constants 32/33
Some References M. Ajmone Marsan, G. Balbo, G. Conte, S. Donatelli, G. Franceschinis Modelling with Generalized Stochastic Petri Nets Wiley series in parallel computing, John Wiley & Sons, 1995 Freely available on the Web site of GreatSPN S. Haddad, P. Moreaux Chapter 7: Stochastic Petri Nets Petri Nets: Fundamental Models and Applications Wiley pp. 269-302, 2009 33/33