## 2 Modeling of Vehicles Interactions Due to Simultaneity
### An Optimized Monte Carlo Algorithm for Traffic Generation Considering Multi-Lane Simultaneity  
As just anticipated, taking full advantage of the results obtained in Section 2.3, an enhanced Monte Carlo algorithm can be implemented duly considering vehicles traveling simultaneously on two or more lanes. The algorithm is structured according to the following steps:  
1. Gather input data: Number of lanes taken into account: \(r\); modified annual flow \(N_{s}^{*}\) on each lane (Equation (13)) and its composition in terms of isolated vehicles and convoys, as for example resulting from the algorithm described before in Section 2.2; total annual flow on the \(r\) lanes (Equation (21)): \(N^{*}\); arrival rate of vehicles \(\mu\), i.e., number of vehicles in the time unit: \[\mu\ =\ N^{*}/\Big{(}3.1536\ \times\ 10^{7}\Big{)}\ \ \ \ \ \text{ vehicles}/\text{s};\] (40) average vehicle speed: \(v\) [m/s]--for example: \(v\ =\ 15\ -\ 20\ \text{m}/\text{s}\); reference length: \(L\) [m];
2. Evaluate: The rate of the distribution: \(\alpha\ =\ v/L\);
3. Compute: The probabilities: \(P_{r,i}\;0\;\leq\;i\;\leq\;r\) (Equation (26)); the probabilities: \(\underline{P}_{r,i}\;1\;\leq\;i\;\leq\;r\) (Equation (27)); the expected annual flows on each lane involved in simultaneity in \(i\) lanes over \(r\): \(\underline{N}_{(l_{j},i)\star}\) (Equation (31)); the annual flows on each lane: \(\underline{N}_{(l_{j},mod)}\) (Equation (32)) the total modified annual flow involved in simultaneity in \(i\) lanes: \(\underline{N}_{mod,i}\) (Equation (34)); the total modified annual flow: \(\underline{N}_{mod}\) (Equation (34)); the ratios: \[b_{i}\;=\;\frac{\sum_{j\;=\;1}^{i}\underline{N}_{mod,j}}{\underline{N}_{mod}} \;\;\;\;\;\;1\;\leq\;i\;\leq\;r.\] (41)
4. Compute: The binomial coefficients \(\left( \begin{array}{c}r\\ i\end{array} \right)\) and associate an integer \(1\;\leq\;j\;\leq\;\left( \begin{array}{c}r\\ i\end{array} \right)\) to each set of \(i\) lanes in combination, \(c(i,j)\): \[c(i,j)\;=\;\{l_{1},l_{2},\ldots,l_{i}\}\;\;\;\;\;\;1\;\leq\;i\;\leq\;r\;\;\;\; \;\;\;\{l_{1},l_{2},\ldots,l_{i}\}\in\left( \begin{array}{c}\{1,2,\ldots,r \}\\ i\end{array} \right).\] (42) in such a way that each combination of \(i\) lanes can be univocally identified by means of \(c(i,j)\); the ratios: \[c_{i}\;=\;\frac{\underline{N}_{mod,i}}{\underline{N}_{mod}\left( \begin{array} []{c}r\\ i\end{array} \right)}\;\;\;\;\;\;1\;\leq\;i\;\leq\;r.\] (43)
5. Fix \(b_{0}=0\) and define the step function \(f_{1}(x)\): \[f_{1}(x):\;(0,1\,]\rightarrow\{(i,c(i,j))\}\;\;\;\;\;\;f_{1}(b_{i\;-\;1}\;<\;x \;\leq\;b_{i\;-\;1}\;+\;j\,c_{i})\;=\;(i,c(i,j)),\] (44) in such a way the number of lanes in combination, \(i\), and the lanes involved in the combination are univocally associated to a given value of \(x\;\in\;(0,1\,]\), so that they can be determined as the result of a single trial. Equation (41) has been written considering equiprobable combinations of \(i\) lanes, but it can be trivially modified to consider combinations which are most likely to occur. A possible graphical representation of function (44) is given in Figure 8, referring to the case of four lanes (\(r\;=\;4\)). Start the generation. It must be remarked that only one vehicle or vehicle convoy must be generated per occupied lane, because simultaneity on single lanes has been previously considered;  
7. Extract a random number \(x\in(0,1]\) and evaluate the step function \(f_{1}(x)\), to identify the number of lanes and the lanes involved in the combination itself: \((i,c(i,j))\). Depending on the value of \(i\) enter different subroutines: \(\bullet\) If \(i\ =\ 1\) go to step 8; \(\bullet\) if \(i>1\) than go to step 9. 8. Since \(i\ =\ 1\) simultaneity does not occur and \(c(1,j)\) is the unique occupied lane: Generate the vehicle or the vehicle convoy on the lane; \(\bullet\) go to step 10. 9.