## 2 Designed Methodology
### FL EMS
#### 2.8.3 Optimization of the RB and FL EMSs  
In this section, some parameters of the RB and FL EMSs are optimized in order to perform better. The optimization of the EVCS charging schedule and the BESS charging/discharging management parameters is performed in parallel.  
Optimization Function  
In order to minimize the cost of the entire charging system, two criteria are considered: the grid price at which energy is charged in the buses and the BESS degradation cost, C\({}_{BESSdeg}\):  
\[f=\sum_{n=1}^{N}\left(\sum_{t=1}^{T}P_{EVCS}(n,t)\cdot\boldsymbol{\epsilon}_{ G}(t)\cdot S_{D}(n,t)\cdot\eta_{C}^{-1}\right)+C_{BESSop} \tag{14}\]  
The optimization processes presented in the following sections are carried out with the GA.  
RB EMS Optimization  
As mentioned in [8], the tuning of RB EMS parameters has a significant impact on results, especially when the rules are simple. Here, five parameters of the RB EMS are optimized: \(P_{BESSmax}\), \(P_{BESSstep\_max}\), \(SOC_{BESSmin}\), \(SOC_{BESSmax}\), and \(\boldsymbol{\epsilon}_{Gthr}\). Indeed, the maximum and minimum values of the SOC and \(P_{BESS}\) can be adjusted inside some limits imposed in the BESS data sheet. The genetic evolution of the power parameters is carried out as a block, as \(P_{BESSstep\_max}\) is limited by \(P_{BESSmax}\).  
The GA that looks for the optimization of the abovementioned parameters is processed in parallel with the GA that optimizes the charging schedule of the buses (Figure 6). Thus, each charging schedule has one specific RB EMS, and the best individuals linked to the last schedule and RB EMS survive to the next generation.  
Regarding the initialization, an array of fixed values on feasible range is defined. The maximum BESS power limits are defined between a very low power value of 30 kW (better regarding the degradation of the BESS [27]) to 2560 kW. Then, the maximum power step limits are defined between a low power value of 30 kW and a random value lower than or equal to the maximum power defined before. Regarding the maximum and minimum SOC values, they have to be between 0.7 and 0.95, and 0.3 and 0.05, respectively. Finally, the threshold price limits are between 0.16 and 0.22 EUR/kWh, near the average price value.  
Concerning the crossover step, two crossover probabilities are calculated, one for the power parameters and another one for the \(SOC\) and \(\xi_{Gthr}\) parameters. Then, two random values are computed and compared with the respective probability. If the random value is lower than the probability number, the crossover is performed. The crossover technique used is the same one as for the charging schedule, where a technique between single, double, and uniform crossover is selected randomly at each iteration.  
Regarding the mutation, as in the crossover, a random value is computed for each group of parameters and, depending on if they are bigger than the fixed probability of mutating for each parameter, the mutation is performed individually on each parameter. The mutation of the parameters is carried out by randomly choosing a value within feasible limits, as in the initialization process.  
Once all the steps are performed, a new population is created with X chromosomes and an RB EMS for each one. Then, the best individuals are selected from the last and current population to survive for the next generation. The process is repeated a fixed number of times (generations). At the end, the best combination of charging schedule and RB parameters is chosen. The parameters used for the crossover probabilities (\(P_{cP}\) and \(P_{cSOC}\)) and mutation probabilities (\(P_{mP}\) and \(P_{mSOC}\)) are those given previously in Table 1[24].