## 4 Algorithm Implementation  
### Estimation of the Energy Consumption through an ANN  
To train our ANN, we use historical traffic data from October to November of 2022 to obtain hourly traffic city simulations. The impact of traffic was incorporated by utilizing the mean velocity recorded for the specific segment during that timeframe. We assign the maximum speed permitted there if traffic data are missing for some segments. As previously indicated, we compute the estimated energy needed for each edge in the graph. Within each hour interval in the two months of data used, we simulated 200 routes throughout the city and determined the most energy-efficient route using the Bellman-Ford algorithm to minimize the estimated consumption. The implementation of Bellman-Ford used is extracted from the NetworkX Python Library. The vehicle of reference for the energy estimation of (5) and (6) is the Nissan eNV200 van, which is relatively representative of delivery vehicles within a city. Its vehicle parameters have been extracted from [PERSON] et al. [7], and the inner losses given by (7) and (8) are taken from [PERSON] et al. [8] since this term does not present huge differences among vehicles, as the aerodynamics is not relevant in their description. The parameters are set to: \(m=1480\) kg; \(\rho=1.24\) kg/m\({}^{3}\); \(c_{rr}=0.01\); \(A=3.26\) m\({}^{2}\); \(c_{w}=0.31\); \(\eta_{M}=0.95\); \(\eta_{G}=0.6\); \(P_{0}=0.5\) kW. To maintain consistency and reliability in our measurements, we have chosen not to consider acceleration when evaluating electric consumption, as it depends on the driving style of individual drivers. For each obtained route, we recorded the hour of the day, the day of the week, if it is a working day or not, the latitude, longitude, and altitude of both the starting and ending points and the energy cost used to travel along that route. These data points were used to train the model and make predictions based on traffic patterns and the city's topology. \"Hour\" and \"weekday\" are different categories. We divided the data into training and test sets in an 80-20 ratio. The ANN used to predict energy consumption was created using the Keras library for Python. It comprises an input layer of 38 neurons (24 for coding hours, 7 for the day, 4 for coordinates, and 2 for height), and three hidden layers containing 64 neurons each, as shown in Figure 7.  
During the development, various architecture combinations were tested. It was discovered that increasing the number of neurons could lead to overfitting. On the other hand, reducing the number of neurons allowed the model to converge faster during training but often resulted in lower performance on the test data. Moreover, decreasing the number of hidden layers in the network decreased the model's performance. By reducing the number of layers, the model has fewer opportunities to learn these higher-level representations, which can result in a less accurate prediction. A rectified linear unit (ReLU) function was used for activation since it allows for modeling nonlinear relationships between input and output variables [34]. Moreover, we have used Adam optimizer [35] that computes adaptive learning rates for each ANN parameter, allowing for a faster convergence and better optimization of the model. After several trials, we took a learning rate of 0.001. We employed the early stopping technique to prevent overfitting and determine the ideal number of epochs [36]. By using early stopping, we ensure that the model is not overfitting and is able to generalize well to new data. The model stopped improving at epoch 151, with a patience of 50. The performance of our ANN was evaluated on the test set, resulting in a root-mean-squared error (RMSE) of 95.1565 and an \(R^{2}\) coefficient of determination of 0.9869. The model's predictive performance can be visually observed through the scatter plot in Figure 8, illustrating the distribution of predicted versus actual values. The number of samples in the test data is 58,560 routes.