# Timed Colored Petri Net-Based Event Generators for Web Systems Simulation
## 3 Systematization of the Generator Models  
As shown in Section 2, the models of web systems described in the literature usually implement some kind of generator. Sometimes such a generator is separated from the main  
Figure 4: QPN model. and \(i\)-th list element is a pair \((e_{i},n_{i})\), where \(e_{i}\) is the element color and \(n_{i}\) denotes its multiplicity. The untimed deterministic model is presented in Figure 5. It is a simple design with only one transition generate. An exemplary initial marking (Figure 4(a)) declares the generation of 30 events of type Evt1 and Evt2, as well as 40 events of type Evt3. The transition generate fires only once that leads to the expected final marking shown in Figure 4(b). To transform the configuration initial marking to the target marking of Events, the following SML function is used  
fun generateEvents([]) = empty | generateEvents((e,n)::r) = (n'e) ++ generateEvents(r); which recursively maps the head list element (e,n) to the multiset n'e. The untimed stochastic model is presented in Figure 6. The configuration color set CFG (*1\") is reused again in this model, but its interpretation changes. Now, the \(i\)-th element \((e_{i},f_{i})\) of the configuration list specifies the event color \(e_{i}\) followed by its relative frequency \(f_{i}\). In the initial marking (Figure 5(a)) the transition init is ready. Its firing moves the configuration token from Config to Cfg2 and additionally calls the function  
fun fsum([]) = 0 | fsum((e,f)::r) = f+fsum(r) calculating the sum \(f_{\text{sum}}=\sum_{i=1}^{N_{\text{tp}}}f_{i}\), where \(N_{\text{tp}}\) denotes the number of event colors, i.e., the length of the configuration list. The result is inserted to the place FSum. After that, only the transition generate remains active, as the marking of Config is empty. Each firing of generate produces one new event by insertion the related token to the place Events. It is controlled by the function  
fun generateEvent(c,s,[]) = empty | generateEvent(c,s,(e,f)::r) = if c<=s andalso c+f>s then 1'e  else generateEvent(c+f,s,r)  
In the function call expression (see the inscription of the arc from generate to Events), an integer from \(\mathcal{U}_{\text{d}}(0,f_{\text{sum}}-1)\) is assigned to the variable \(s\). The function recursively inspects intervals  
\[I_{i}=\left[\sum_{k=1}^{i-1}f_{k},\sum_{k=1}^{i}f_{k}\right),\qquad i=1,2, \ldots,N_{\text{tp}},\]  
and returns the event \(e_{i}\) if \(s\in I_{i}\). Therefore, \(f_{i}\) has indeed the meaning of the relative frequency of \(e_{i}\) in the stochastic process. In other words, the probability of \(e_{i}\) has the value  
Figure 5: Untimed deterministic CPN-based event generator. \[\pi_{i}=\frac{f_{i}}{\sum\limits_{i=1}^{N_{\text{pv}}}f_{i}}.\]  
Note that if \(\sum_{i=1}^{N_{\text{pv}}}f_{i}=100\), then \(f_{i}\) directly expresses the probability in percents. Let \(N_{\text{evt}}\) be the initial marking of the place Num. Each firing of generate consumes one token from Num, so the considered model generates \(N_{\text{evt}}\) events. In particular, it is 1000 events in the presented example (Figure 5(b)). Assuming an ideal stochastic process, the expected number of events of type \(e_{i}\) equals \(\pi_{i}N_{\text{evt}}\). The actual number of such events \(\eta_{i}\) is a random variable of binominal distribution \(\mathcal{B}(N_{\text{evt}},\pi_{i})\). It is well known that if \(\pi_{i}N_{\text{evt}}\) and \((1-\pi_{i})N_{\text{evt}}\) are large enough, in practice greater than 5, this distribution is well approximated by the normal distribution [34]  
\[\mathcal{N}_{\eta}\bigg{(}\mu_{i}=\pi_{i}N_{\text{evt}},\ \sigma_{i}=\sqrt{\pi_{i}N_{ \text{evt}}(1-\pi_{i})}\bigg{)}. \tag{1}\]  
Let us evaluate the model against the expected distribution.