## 2 Modeling of Vehicles Interactions Due to Simultaneity
### An Optimized Monte Carlo Algorithm for Traffic Generation Considering Single Lane Simultaneity  
As anticipated, the method illustrated in Section 2.1 can be efficiently applied to derive an optimized Monte Carlo algorithm for production of traffic samples, next described step by step. In the implementation of the algorithm, the inter-vehicle distances are generated to suitably fit the theoretical probability that exactly \(i\) vehicles are traveling simultaneously on the lane. The algorithm is structured according to the following steps:  
1. [label=0., ref=0]
2. Gather input data: Number of vehicle types or vehicle categories: \(q\); annual flow of the \(j\)-th vehicles on the \(s\)-th lane: \(N_{js}\); total annual flow on the \(s\)-th lane (Equation (1)): \(N_{s}\); arrival rate of vehicles \(\delta\), i.e., number of vehicles in the time unit: \[\delta\;=\;N_{s}\big{/}\big{(}3.1536\;\times\;10^{7}\big{)}\;\;\text{ vehicles}\,\text{/s};\] (18) average vehicle speed: \(v\) [m/s]--for example: \(v\;=\;15\)-\(20\) m/s; reference length: \(L\) [m]; the minimum distance \(d\) between two consecutive vehicles--for example: \(d\;=\;25\)-\(40\) m, which is the sum of the length of the vehicle plus some safety clearance. 3. Evaluate: The rate of the distribution: \(\alpha\;=\;v/L\); the maximum number of vehicles on \(L\) (Equation (3)): \(w\;=\;\text{int}(L/d)\); the waiting time rates (Equations (4) and (5)): \(\varphi_{k}(t)\;=\;\big{(}\alpha^{-1}\;-\;k\;t\;^{*}\big{)}^{-1}\;1\;\leq\;k \;\leq\;w\;-\;1\). 4. Compute: The probabilities: \(P_{i}\;0\leq i\leq w\) (Equation (10)); the probabilities: \(\underline{P_{i}}\;1\leq i\leq w\) (Equation (11)); the expected annual flow: \(\underline{N_{s_{i}}}\;1\leq i\leq w\) (Equation (12)); the total modified annual flow: \(N_{s}^{*}\) (Equation (13)); the ratios: \[a_{i}\;=\;\frac{\sum_{j\;=\;1\;N_{s_{i}}}^{i}}{N_{s}^{*}}\;\;\;1\;\leq\;i\; \leq\;w.\] (19)
5. Fix \(a_{0}\;=\;0\) and define the step function \(f(x)\) (Figure 3): \[f(x):\;(0,1]\rightarrow\{1;2;\ldots;i;\ldots;w\}\;\;\;\;\;f(a_{i-1}\;<\;x\; \leq\;a_{i})\;=\;i\,.\] (20)
6. Assign a suitable probability distribution function (pdf) describing the position of the vehicle in a given interval: For example, referring to this aspect, adoption of an uniform pdf could be a simple and somewhat natural choice, but there are no restrictions. 7. Start the generation. Extract a random number \(x\in(0,1]\) and evaluate the step function \(f(x)\) representing the number of vehicles simultaneously traveling the lane. Depending on the value of \(f(x)\) enter different subroutines:  
* If \(f(x)=1\) then go to step 8;
* if \(f(x)=2\) than go to step 9;
* if \(f(x)>2\) than go to step 10. * The case \(f(x)=1\) is rather obvious:
* Generate, if necessary, the vehicle typology \(j\)
* then fix equal \(L\) the distance \(\overline{d}\) between the rear axle of the actual vehicle and the first axle of the next vehicle, otherwise generate it imposing \(\overline{d}\geq L\);
* subsequently, go to step 11. It must be remarked that in studying actions on bridges, the choice \(\overline{d}=L\) is the optimal one, as it is the minimum distance for which simultaneity does not occur, but in transportation problems it could not be the most appropriate. * The case \(f(x)=2\) is illustrated in Figure 4:  
* Generate, if necessary, the vehicle typologies of the two vehicles;
* consider that the first vehicle is at the end of the lane: in this situation (Figure 4a), the available positions for the second vehicle are those in the interval, \((d,L)\);
* generate the position \(x_{2}\in(d,L)\) of the second vehicle (Figure 4b);
* since no other vehicles need to be generated, store the data concerning this two-vehicle convoy and go to step 11. * Although they are treated in identical ways, for the sake of clarity, it seems opportune to consider first the case \(f(x)=3\) and then the most the general one \(f(x)=i>3\).