# Timed Colored Petri Net-Based Event Generators for Web Systems Simulation
## 3 Systematization of the Generator Models
### Timed Models  
Events generated in timed simulation could be defined in many ways. A basic idea is to describe events of the \(i\)-th type by the data structure  
\[\big{(}e_{i_{i}},t_{i,1},t_{i,2},\ldots,t_{i,n_{i}}\big{)},\]  
where \(e_{i}\) is the event color and the values \(t_{i,j}\), \(j=1,2,\ldots,n_{i}\) directly specify the times at which the event has to be generated. Such an approach could be based on a simple CPN model, similar to the one presented in Figure 5, so the solution is not going to be presented. The scenario considered here shows that generator configuration determines the frequency of events on given time intervals, while the individual events are generated automatically. It is a more practical variant, useful in many simulations, e.g., for system performance analysis, but it is also more complex for implementation. The \(i\)-th element of the configuration list has the form  
\[\big{(}e_{i},[(d_{i,1},p_{i,1}),(d_{i,2},p_{i,2}),\ldots,(d_{i,j},p_{i,j}), \ldots,(d_{i,m_{i}},p_{i,m_{i}})]\big{)}, \tag{4}\]  
where \(d_{i,j}\) specifies the duration of the interval during which events are generated with the period \(p_{i,j}\). When the time of the \(j\)-th interval expires, the generation switches to the \((j+1)\)-th one, and so on, with the exception that \(j=m_{i}\) is followed by \(j=1\). In this way, the generation process is a cycle. More precisely, the events of type \(e_{i}\) are issued at the times  
\[t_{i}\in\mathbb{T}_{i}=\bigcup_{S=0}^{\infty}\bigcup_{h=0}^{\infty}\bigcup_{ h=0}^{\left\lfloor\frac{-1+d_{i,(g\bmod m_{i})+1}}{P_{i,(g\bmod m_{i})+1}} \right\rfloor}\Bigg{\{}hp_{i,(g\bmod m_{i})+1}+\sum_{k=1}^{m_{i}}\bigg{\lfloor} \frac{m_{i}+g-k}{m_{i}}\bigg{\rfloor}d_{i,k}\Bigg{\}}, \tag{5}\]  
where \(g+1\) indicates the generated interval number and \(h+1\) is the event number in the interval. To implement the generator in the form of a CPN model, the following additional color set definitions are needed  
colset INT2 = product INT * INT; (*2*)  
Figure 8: Distribution of \(\delta_{i}\) for \(N_{\text{evt}}=10\),000.  
colset INT2_L=list INT2; (*3*)  colset ECFG=product EVT*INT2_L; (*4*)  colsetCFG=list ECFG; (*5*)  colset EVT_T=EVT timed; (*6*)  colset INTV=product EVT*INT*INT*INT; (*7*)  colset INTV_T=INTV timed; (*8*) ```
The declarations (*2*)-(*5*) construct the color set compatible with (4). The color set (*6*) is a timed version of the event type. The declarations (*7*)-(*8*) introduce untimed and timed variants of auxiliary 5-tuple describing a single interval of generated events. The TCPN model of the generator is presented in Figure 9. Most of the arc inscriptions are 5-tuple adjacent to the color set INTV. They are interpreted as  
\[\big{(}e_{i},j,a_{i,j},d_{i,j},p_{i,j}\big{)}, \tag{6}\]  
where the meaning of \(e_{i}\), \(j\), \(d_{i,j}\), \(p_{i,j}\) is consistent with (4), and \(n_{i,j}\) indicates the number of the next interval in the repetitive cycle, namely  
\[n_{i,j}= \begin{cases}j+1,&j<m_{i}\\ 1,&j=m_{i}\end{cases} . \tag{7}\]  
Each firing of the transition init1 consumes one configuration element from Config and splits it into separate interval representations adjacent to (6) using the function
``` funsplitCfg(j,(evt,[(dur,per)])) =1'(evt,j,1,dur,per) |splitCfg(j,(evt,(dur,per)::r)) =1'(evt,j,j+1,dur,per)++splitCfg(j+1,(evt,r)) ```
Note that this function derives the values of \(n_{i,j}\) (the third tuple element) according to (7). Firings of the transition init2 move the tokens describing the intervals with \(j=1\) to Intvs and the remaining tokens from StartIntvs are moved to ActiveIntv as a result of the transition init3 firings. All the transitions init1/2/3 have all their input arcs from the places of untimed types, so they execute at the global time 0 and initialize the generation mechanism. After the initialization, the generation of the events comes down to firing the transition generate over and over again. For example, consider the configuration imposed by the initial marking of Config in Figure 9, specifically, the part related to Evt1.