## 4 Differential Evolution Algorithm for the ATO over ERTMS Eco-Driving Problem
### Differential Evolution Algorithm  
The DE procedure starts with the initialisation process. The initial population is created producing random individuals defined by a \(C_{m}\) that fulfils the minimum speed and minimum position of the final coast command. This population is evaluated using the detailed train simulator described in Section 4.3 to obtain the energy consumption, passing times at the timing points and the fitness of each individual. Then, the population is sorted in rising fitness value.  
After that, the algorithm creates for each individual a donor/mutant vector. The donor vector is created perturbing the best solution of the population with the difference between two randomly selected individuals [85]. It can be obtained using the following expression:  
\[DV_{j}=X_{best}+F\big{(}X_{R_{1}}-X_{R_{2}}\big{)} \tag{3}\]  
where \(DV_{j}\) is the donor vector of the individual \(j\), \(X_{best}\) is the best individual of the population, \(F\) is a parameter called scaling factor, \(R_{1}\) and \(R_{2}\) are two different randomly generated integer numbers, \(X_{R_{1}}\) is the individual in the position \(R_{1}\)in the population and \(X_{R_{2}}\) is the individual in the position \(R_{2}\) in the population.  
\(DV_{j}\) is built by means of the differences between each component of the command matrixes (speed commands and changing command positions) of two members of the population that are added to the best individual found. Thus, the differences between two members of the population are, in most cases, bigger at the beginning of the optimisation. It allows the exploration of the solution space in early iterations. However, as the iterations goes, the differences are minor, promoting the exploitation of the near-optimal space.  
Crossover operator is applied after obtaining the donor vectors for all the individuals in the population. Crossover consists in mixing the components of the donor vector with the components of the individual associated, also called target vector. Thus, the trial or offspring vector is generated. The crossover mechanism is performed on each of the components of the solutions. At each component, a randomly generated number between 0 and 1 is compared with a parameter \(C_{r}\), called crossover rate. If the random number is less or equal to the crossover rate, the trial vector will inherit the corresponding component of the donor vector. Otherwise, it inherits the component of the trial vector. The scheme can be formulated as follows:  
\[TV_{j}^{h}=\left\{\begin{array}{cc}DV_{j}^{h}&\text{if }h=K\text{ or }rand[0,1]\leq C_{r}\\ X_{j}^{h}&\text{otherwise}\end{array}\right. \tag{4}\]where \(TV_{j}^{h}\) is the component \(h\) of the trial vector associated with the individual \(j\), \(DV_{j}^{h}\) is the component \(h\) of the donor vector associated with the individual \(j\), \(X_{j}^{h}\) is the component \(h\) of the individual \(j\) and \(K\) is a randomly generated number between 1 and the number of components. The equality \(h=K\) ensures that, at least, one component of the donor vector will be present in the trial vector.  
Once all the trial vectors are generated, they are simulated to obtain the results on energy consumption, passing times at the timing points and the fitness of each of them. The simulation is carried out using the simulation model described in Section 4.3. After that, the selection process is performed. Selection consists in comparing the fitness of each individual with the fitness of its associated trial vector. If the fitness of the trial vector is less or equal to the fitness of the individual, the trial vector replaces the individual in the population. Otherwise, the individual is retained and the trial vector is erased.