# On the Impact of the Rules on Autonomous Drive Learning
## 3 Model
### Cars  
A _car_ simulates a real vehicle that moves on the road graph \(G\): its position can be determined at any time of the simulation in terms of the currently occupied road element and current lane. The car movement is determined in terms of two speeds--the _linear speed_ along the road element and the _lane-changing speed_ along the lanes of the same element. At each time step, the car state is defined by the tuple \((p,x,y,v_{x},v_{y},s)\), where \(p\in\{S,I\}\) is the current road element, \(x\in[0,l(p)]\) is the position on the road element, \(y\in\{1,\dots,w(p)\}\) is the current lane, \(v_{x}\in[0,v_{\max}]\) is the linear speed, \(v_{y}\in\{-1,0,1\}\) is the lane-changing speed, and \(s\in\{\text{alive},\text{dead}\}\) is the status (time reference is omitted for brevity). All the cars have the same length \(l_{\text{car}}\) and the same maximum speed \(v_{\max}\). At the beginning of a simulation, all cars are placed uniformly among the road sections, on all the lanes, ensuring that a minimum distance exists between cars \(i,j\) on the same road element \(p_{i}=p_{j}\), such that: \(|x_{i}-x_{j}|>x_{\text{gap}}\). The initial speeds for all the cars are \(v_{x}=v_{y}=0\), and the status is \(s=\text{alive}\). At the next time steps, if the status of a car is \(s=\text{dead}\), the position is not updated. Otherwise, if the status is \(s=\text{alive}\), the position of a car is updated as follows. Let \(\left(a_{x}^{(t)},a_{y}^{(t)}\right)\in\{-1,0,1\}\times\{-1,0,1\}\) be the driver action composed, respectively, of \(a_{x}^{(t)}\) accelerating action and \(a_{y}^{(t)}\) lane-changing action (see details below). The linear speed and the lane-changing speed at time \(t+1\) are updated accordingly with the driver action \(\left(a_{x}^{(t)},a_{y}^{(t)}\right)\) at time \(t\) as:  
\[v_{x}^{(t+1)} =\min\left(v_{\max},\max\left(v_{x}^{(t)}+a_{x}^{(t)}a_{\max} \Delta t,0\right)\right) \tag{1}\] \[v_{y}^{(t+1)} =a_{y}^{(t)} \tag{2}\]  
where \(a_{\max}\) is the intensity of the _instant acceleration_ and \(\Delta t\) is the discrete time step duration. The car linear position on the road graph at time \(t+1\) is updated as:  
\[x^{(t+1)}= \begin{cases}x^{(t)}+v_{x}^{(t+1)}\Delta t&\text{ if }v_{x}^{(t+1)} \Delta t\leq x_{\text{stop}}^{(t)}\\ v_{x}^{(t+1)}\Delta t-x_{\text{stop}}^{(t)}&\text{ otherwise}\end{cases}  \tag{3}\]  
where \(x_{\text{stop}}\) is the distance ahead to the next road element, and is computed as:  
\[x_{\text{stop}}^{(t+1)}=l\left(p^{(t+1)}\right)-x^{(t+1)} \tag{4}\]  
The car lane position at time \(t+1\) is updated as:  
\[y^{(t+1)}=\min\left(w(p^{(t+1)}),\max\left(y^{(t)}+v_{y}^{(t+1)},1\right)\right) \tag{5}\]  
The road element at time \(t+1\) is computed as:  
\[p^{(t+1)}= \begin{cases}p^{(t)}&\text{if }v_{x}^{(t)}\Delta t\leq x_{\text{stop}}^{ (t)}\\ \sim U\left(n\left(p^{(t)}\right)\right)&\text{otherwise}\end{cases}  \tag{6}\]  
where \(U\) is the uniform distribution over the next road elements coming from \(p\) In other words, when exiting from an intersection, a car enters an intersection chosen randomly from \(n\left(p^{(t)}\right)\). Two cars collide, if the distance between them is smaller than the cars length \(l_{\text{car}}\). In particular, for any cars \((p,x,y,v_{x},v_{y},s)\), \((p^{\prime},x^{\prime},y^{\prime},v^{\prime}_{x},v^{\prime}_{y},s^{\prime})\), the status at time \(t+1\) is updated as (we omit the time superscript for readability):  
\[s= \begin{cases}\text{dead}&\text{if }\big{(}p=p^{\prime}\wedge|x-x^{\prime}|<l_{ \text{car}}\big{)}\vee\big{(}p^{\prime}\in n(p)\wedge x_{\text{stop}}+x^{\prime }<l_{\text{car}}\big{)}\\ \text{alive}&\text{otherwise}\end{cases}  \tag{7}\]  
When a collision occurs, we simulate an impact by giving the leading car a positive acceleration of intensity \(a_{\text{coll}}\), while giving the following car a negative acceleration of intensity \(-a_{\text{coll}}\), for the next \(t_{\text{coll}}\) time steps.