## 4 Validation of the Simulation Framework
### Optimization Based Tuning Process  
In [17], constrained minimization was used in the tuning process of the controller to allow the controller to become flexible, so it can respond in a robust fashion to changes in the inputs, and be used for different purposes by optimally retu  
Figure 6: Tuning the simulation using variably sized windows applied based on the driving cycle. subject to different constraints. In [18], a constrained nonlinear optimization was carried out using a sequential quadratic programming (SQP) algorithm to tune PID gains to allow the controller to adapt to changes in the plant; this not only offered superior performances when compared to traditional PID tuning, the tuning process was much quicker. Similarly, linear programming was utilized in [19] to tune the weights of a symmetric finite impulse response (FIR) filter of low-bandwidth controllers for a linear time and spatial invariant (LTSI) systems; a hybrid genetic algorithm (GA) followed by constrained nonlinear minimization was used in [20] to optimize in real time the autopilot gain of an unmanned aerial vehicle (UAV); the GA ensured a global minimum, but without running the GA process to its conclusion, and the \(\mathrm{f}_{\mathrm{micon}}\) function utilized to finetune the results of the GA at a higher speed. In this study, the meta-heuristic algorithm, improved simple optimization (iSOPT) [21], was used to tune the EMS and CMS of the electric bus powertrain model, to ensure a global minimum within the fastest possible time, so that the tuning can be carried out in real-time. The set of parameters that were tuned for the EMS are:  
* Cutoff velocity for regenerative braking activation
* Passenger load in the bus (broad categories: full load, half load, driver only) The set of parameters that were tuned for the thermal management system (TMS) are:
* Cabin setpoint temperature The set of parameters that were tuned for the CMS are:
* Cutoff SoC between CC and CV charging mode
* The current decay factor for CV charging mode
* The charging duration and power
* Initial Battery ageing  
The final two parameters that were tuned are the passenger load estimate in the bus and the cabin setpoint temperature. Thus, a total of seven parameters makes up the solution space. An initial population size of 11 with random combinations of the seven parametric values was generated, and the algorithm described in [5] is followed till its conclusion. The maximum number of iterations was set to 50. The optimization is handled via MATLAB scripts, which populates the variables of the Simulink model with updated values every iteration while simulating the demonstration scenario. The following constraints were applied to the optimization, and a penalty was added to the optimization score if one or more of these constraints were exceeded in any way:  
* The current decay factor, cutoff velocity, and cutoff SoC were positive
* The cutoff SoC was below 100%
* The RCD was below 25%
* The charging duration exceeds 1 min and charging power was positive
* The battery SoC should not drop below 10% during the simulation  
The advantage of using optimization techniques to tune the model is that it preserves the integrity of the model, with the only factor being changed is the set of parameter values of the respective modules that are being tuned. The improvements of the optimization methodology followed in this research compared with [5] are twofold. The first is an improvement in speed of optimization. In all cases, it is noticed that \(\mathrm{T}_{\mathrm{opt}}<\mathrm{n}\)\({}^{*}\)\(\mathrm{T}_{\mathrm{sim}}\), where \(\mathrm{n}\) was the number of iterative simulations required during the optimization before convergence and \(\mathrm{T}_{\mathrm{sim}}\) is the duration of one complete simulation.