**4. Driving Model**

A closed-loop PI controller is used to emulate the manual driving by controlling the train dynamics. It takes into account the maximum acceleration and service deceleration of the train, the jerk limitation, the maximum tractive effort, the speed limits and the energy that has to be regenerated by braking in neutral zones. The control loop minimizes the difference between an objective speed *vobj* and the train speed *v*. At every time step the objective speed is computed in terms of the driving commands and the track speed limits. To do so, the braking curves to the next ceiling speed reduction, *vb*(*s*), and to the next stop at a station, *vf b*(*s*), are calculated by using Equations (10) and (11).

$$w\_b(s) = \sqrt{v\_{nxt}^2 + 2 \cdot d\_{srrrice} \cdot (s\_{nxt} - s)},\tag{10}$$

$$w\_{fb}(s) = \sqrt{2 \cdot d\_{\text{servica}^\*}(s\_{end} - s)},\tag{11}$$

where *vnext* is the next ceiling speed of the track, *dservice* is the service deceleration of the train, *s* is the position of the train, *snext* is the position of the next ceiling speed corrected with the train length if necessary and *send* is the next stopping point.

The objective speed *vobj* is therefore computed in terms of the maximum admissible speed *vmax*, which is the minimum between the next braking curve and the ceiling speed at the position of the train *vceiling*(*s*),

$$\upsilon\_{\text{max}}(t) = \min \{ \upsilon\_{\text{celling}}(s), \upsilon\_{b^\circ}(s), \upsilon\_{fb^\circ}(s) \}, \tag{12}$$

$$v\_{obj}(t) = \min(v\_{\max}(t), v\_c) \quad \text{if } s \le s\_c \tag{12}$$

$$v\_{obj}(t) = 0 \quad \text{if } s\_c < s \tag{13}$$

The control variable *Ureg* is defined as the traction or brake demand of the PI controller. To calculate it, at every time step the proportional and integral control components are calculated as described in Equations (14)–(18). For the standard driving the control variable is computed using Equation (17), while for the eco-driving strategy Equation (18) is used instead.

$$
\varepsilon(t) = \upsilon\_{obj}(t) - \upsilon(t) \tag{14}
$$

$$\mathcal{U}L\_P(t) = K\_P \cdot e(t) \tag{15}$$

$$\mathcal{U}I\_I(t) = \frac{K\_P}{K\_I} \cdot \frac{\left(e(t) + e(t - \Delta t)\right)}{2} + \mathcal{U}\_I(t - \Delta t) \tag{16}$$

$$\mathcal{U}\_{\text{reg}}\,(\_{\text{std}}(t) = \mathcal{U}\_P(t) + \mathcal{U}\_I(t) \tag{17}$$

$$\begin{aligned} \text{i}\mathcal{U}\_{\text{reg (cco)}}(t) &= \mathcal{U}\_{\text{P}}(t) + \mathcal{U}\_{\text{I}}(t) & \text{if } v(t) \ge v\_{\text{max}}(t) \text{ or } \mathcal{U}\_{\text{P}}(t) + \mathcal{U}\_{\text{I}}(t) \ge 0 \\ \mathcal{U}\_{\text{reg (cco)}}(t) &= 0 & \text{if } v(t) < v\_{\text{max}}(t) \text{ and } \mathcal{U}\_{\text{P}}(t) + \mathcal{U}\_{\text{I}}(t) < 0 \end{aligned} \tag{18}$$

where *e*(*t*) is the difference between the objective and the train speeds, whose absolute value has to be minimized by the control. *UP*(*t*) and *UI*(*t*) are the proportional and integral components of the control variable *Ureg*(*t*). *KP* and *KI* are the proportional and the integral gains, respectively. Δ*t* is the simulation time-step. If the control variable is positive, the control demands tractive effort, while if it is negative, it demands braking. If it is zero, the control demands coasting. In the eco-driving strategy (Equation (18)), the control demand is set to coasting when the train speed is below the maximum admissible speed and the control would demand braking under the current condition.

Once that the control variable has been obtained, the engine maximum traction and brake limits; comfort constraints—maximum acceleration and jerk; and the presence of neutral zones, have to be taken into account. Strong accelerations are considered to be unpleasant for passengers, so the maximum acceleration and deceleration have to be controlled. *FmaxAcc*(s, *v*) and *FmaxDec*(s, *v*) model the forces corresponding to the maximum admissible acceleration and deceleration respectively with corrections for the running and track geometry resistances. Equations (19) and (20) are used for calculating these forces.

$$F\_{\text{maxAcc}}(\mathbf{s}, \upsilon) = a\_{\text{max}} \cdot \rho \cdot m + \left(F\_r(\upsilon) + F\_{\mathcal{S}}(\mathbf{s})\right) \tag{19}$$

$$F\_{\text{maxDcc}}(\mathbf{s}, \boldsymbol{\upsilon}) = d\_{\text{max}} \cdot \boldsymbol{\rho} \cdot \boldsymbol{m} + \left( F\_r(\boldsymbol{\upsilon}) + F\_{\mathcal{S}}(\mathbf{s}) \right) \tag{20}$$

where *amax* and *dmax* are the maximum admissible acceleration and deceleration rates in absolute values, respectively.

The rate of change of the train acceleration, jerk, can also affect passengers' comfort [49,81–83]. The maximum and minimum admissible effort due to the jerk limitation, *FmaxJerk*(t) and *FminJerk*(t), are calculated by using Equations (21) and (22).

$$F\_{\text{max}\downarrow crk}(t) = F\_m(t - \Delta t) - F\_b(t - \Delta t) + (j\_{\text{max}} \cdot p \cdot m) \cdot \Delta t \tag{21}$$

$$F\_{\rm min\,\rm{left}}(t) = F\_m(t - \Delta t) - F\_b(t - \Delta t) - (j\_{\rm max} \cdot \rho \cdot m) \cdot \Delta t \tag{22}$$

where jmax is the maximum admissible jerk.

The total traction or braking effort demanded to the train after applying the comfort restrictions and engine maximum traction and brake effort, *FTB*(*t*), is computed by evaluating Equation (23) or Equation (24).

$$\begin{aligned} F\_{TB}(t) &= \min\{lL\_{\text{reg}}(t), F\_{\text{max}}(v), F\_{\text{max}\text{Acc}}(s, v), F\_{\text{max}\text{fer}}(t)\} \\ \text{if } \mathsf{UL}\_{\text{reg}}(t) &\geq 0 \text{ and } s \notin \left(\mathsf{s}\_{\text{NZ}\_{\text{start}}^{k}} s\_{\text{NZ}\_{\text{end}}} k\right) \text{ for } k \in \{1, 2, \dots, z\}, \end{aligned} \tag{23}$$

$$F\_{TB}(t) = \max\{\mathcal{U}\_{\text{reg}}(t), F\_{\text{max\,Dcr}}(\mathbf{s}, \mathbf{v}), F\_{\text{min\,lcrk}}(t)\}\tag{24}$$
 
$$if \,\mathcal{U}\_{\text{reg}}(t) < 0 \,\text{and} \,\mathbf{s} \notin \left(\mathbf{s}\_{\text{NZ}}\mathbf{z}\_{\text{start}}^k, \mathbf{s}\_{\text{NZ}}\mathbf{z}\_{\text{end}}^k\right) for \, k \in \{1, 2, \dots, z\}.$$

If the train is on a neutral zone, it has to use the regenerative brake to maintain the comfort and auxiliary systems; therefore, the total braking effort to be applied is

$$F\_{TB}(t) = \max\{\min\{\mathcal{U}\_{\text{reg}}(t), F\_{\text{NZ}}(\mathbf{v})\}, F\_{\text{maxDoc}}(\mathbf{s}, \mathbf{v}), F\_{\text{minick}}(t)\}\tag{25}$$
 
$$\text{if } \mathbf{s} \in \left(\mathbf{s}\_{\text{NZ}}\mathbf{z}\_{\text{start}}, \mathbf{s}\_{\text{NZ}}\mathbf{z}\_{\text{cmd}}^k\right), \qquad k \in \{1, 2, \dots, z\}$$

where *FNZ*(*v*) is the minimum force required for keeping the auxiliary systems on; *sNZ<sup>k</sup> start* and *sNZ<sup>k</sup> end* are the initial and final points of the *k*-th neutral zone; and *z* is the total number of neutral zones in the considered line.

Finally, the values of the tractive and brake forces to be applied in the train are obtained from the total traction or braking effort simply by considering that if *FTB*(*t*) is positive the train will apply traction and it will brake if *FTB*(*t*) is negative, as described in Equations (25) and (26).

$$\begin{array}{ll} F\_m(t) = F\_{TB}(t), & \text{if } F\_{TB}(t) \ge 0, \\ F\_m(t) = 0 & \text{if } F\_{TB}(t) < 0, \end{array} \tag{26}$$

$$\begin{array}{ll} F\_b(t) = 0 & \text{if } F\_{TB}(t) \ge 0, \\ F\_b(t) = -F\_{TB}(t) & \text{if } F\_{TB}(t) < 0. \end{array}$$
