I Introduction
In motorsport events, strategic decisions may have a relevant impact on the result of the competition. Particularly, with reference to World Endurance Championship (WEC) [6], there are four vehicle categories characterised by very different performance. This results in the formation of traffic congestion, obliging the fastest category, i.e. Le Mans Prototype 1 (LMP1), to overlap other vehicles many times during the six hours of an event. LMP1 consists in hybrid vehicles that have to respect constraints set by the technical regulation [10] for the usage of both the electrical and thermal energy. Race engineers define how to use the energy budget in an optimal way along the track with the aim to minimise the lap time.
In the last years, many stateoftheart works have addressed the problem of lap strategy optimisation for race electric [2, 25, 5, 16, 7, 8] and hybrid [11, 22, 24] vehicles. In the majority of the cases, the formulations include very detailed and complex models of the powertrain, but do not include the presence of competitors in the driving scenario, which instead represents a fundamental aspect for what said above. Competitors are therefore neglected due to the difficulties in effectively simulating their behaviour, as well as including this information into the optimisation problem, which may become burdensome and not realtime solvable. However, this may result in overtakings being performed in points along the track where a significant deviation from the precomputed optimal trajectory is necessary, thus determining relevant time losses.
Statement of contributions. To bridge this gap, we propose a computationally efficient procedure to offline identify the best strategy for the energy budget utilisation along the track, taking into account realistic traffic conditions. By best strategy we refer to the one that statistically minimises the lap time while respecting the technical regulation.
Our contribution is threefold.
Statistical modelling of the competitors’ behaviour
we perform a statistical analysis to practically describe the behaviour of the competitors along the track in WEC events, in terms of travel time and their mutual interactions, i.e. overtaking probability. The statistical analysis is necessary since we do not know the behavioural model of the competitors. Statistical analyses of previous events have been carried out to extract the free sector times and overtaking probability distributions. The latter refers to the probability of occurrence of overtakings between two vehicle categories along the track. This information is later employed to generate realistic simulations of the competitors’ behaviour.
Computation of trafficfree optimal strategies
theoretically, it would be necessary to define the best points of application of the electric motor in real time according to the actual traffic conditions, but this task is computationally too expensive to guarantee sufficiently fast cycle times. Therefore, the following solution is proposed.
We generate a set of possible trafficfree optimal solutions, which aim to minimise the lap time while respecting the constraints imposed by the technical regulation. The set of varied solution is obtained by imposing different extra constraints on the distribution of the powertrain energy budget along the track, according to engineering expertise. The optimisations are solved using Genetic Algorithms, for their computational quickness and ease of tuning. This choice is supported by a comparison with a more classical Mixed Integer Quadratically Constrained Program (MIQCP). In both cases, the egovehicle is described through a longitudinal model. The set of trafficfree candidate optimal strategies will be finally tested in real traffic conditions to determine the most suitable one, as explained in the next point.
Optimal strategy in presence of traffic
to identify the optimal strategy in presence of traffic, we propose an evaluation metrics based on Stochastic Dynamic Programming (SDP)
[20, 21]. The dataset used by SDP is generated through the Monte Carlo (MC) [1] simulations, relying on a multiagent influence/reaction model and on the previously computed statistics of the competitors.Sections organisation. The remainder of this paper is organised as follows. Sec. II presents stateoftheart related work. In Sec. III, we perform the statistical analysis of the past WEC events, to compute the free sector times and overtaking probability distributions. Sec. IV details the longitudinal vehicle model that is used to solve the powertrain energy budget optimisation problem. The latter, considering trafficfree conditions, is then formulated and solved in Sec. V, comparing a Mixed Integer Quadratically Constrained Program (MIQCP) formulation and Genetic Algorithms. In Sec. VI, we show how to generate Monte Carlo numerical simulations of the competitors’ positions along the track, employing the free sector times and the overtaking probabilities distributions, as well as a multiagent model. Finally, in Sec. VII, the previously computed trafficfree strategies are combined with the trafficaware Monte Carlo simulations, and Stochastic Dynamic Programming is employed to evaluate the statistically best strategy in presence of traffic. Finally, conclusions are discussed in Sec. VIII.
Ii Related work
Simulating the competitors’ motion in racing events is an active field of research. A realistic simulator for circuit motorsports is proposed in [15]. It includes the effects of tire degradation, fuel mass loss, pit stops and overtaking. However, it employs a lapwise discretisation, which is incompatible with the goal of our work. In fact, we aim to generate an optimal lap strategy that is sectionwise. A discreteevent simulation model is developed in [4], which is suitable for decision making to define the race strategy. The track is divided into sections. For each of them, the vehicle and environment characteristics, such as the fuel mass and the air resistance penalty, are taken into account. However, the computation of the lap time is performed using a deterministic approach, without considering the uncertainty related to the interactions between the vehicles, which is our target.
Many stateoftheart works deal with energy management for electric and hybrid vehicles under a lowerlevel perspective compared to our work. Timeoptimal energy management and gear shift for hybrid race cars is investigated in [11]. Given fuel and battery consumption targets, they implement a computationally efficient algorithm to solve the problem, mixing convex optimisation, Dynamic Programming and the Pontryagin’s minimum principle. In [23], a similar problem is solved for realtime control of the Formula 1 power unit using a twolevel Model Predictive Control scheme. Minimumlaptime optimisation for allwheel drive electric race cars is presented in [8]. An optimal adaptive race strategy for FormulaE cars is presented in [2]. It is based on an adaptive equivalent consumption minimisation strategy (AECMS) approach, and compared with a global optimal benchmark provided by Dynamic Programming. In [25]
, they introduce a lap strategy optimisation method based on a Big Bang  Big Crunch approach for Solar cars in longdistance races. Finally, for Solar cars, heuristic methods are compared in
[5]. One of the implemented methods is Genetic Algorithms, which is adopted in our framework.The works presented here accurately represent the dynamics of the vehicle powertrain. They cannot however be employed in our framework since they neglect competitors and overtakings, which affect higherlevel strategic decisions.
Iii Statistical analysis of the competitors’ performance
One of the key contributions of the proposed methodology for lap strategy optimisation is modelling competitors’ motion along the track. Modelling and simulating the behaviour of the competitors allows in fact to design and evaluate lap strategies that can be effectively actuated in realistic racing situations. In this section, we detail how to extract a set of useful statistical indices from the publicly available fraction of data collected in previous races by WEC. The set of statistical indices is meant to synthetically describe the competitors’ performance during the race, and they will be lately used to simulate their motion along the track.
Being WEC events longlasting races, the generated amount of data provides a relevant statistical basis for our scope. However, since GPS data of the vehicles are provided by Federation Internationale de l’Automobile (FIA) to every team (for their own vehicle only) during the race but they are not publicly available, the proposed approach relies on an alternative procedure. Based on the statistical distribution of sector times data, we aim to describe the behaviour of each competitor during the race in a probabilistic fashion. The following sections illustrate the entire procedure.
Iiia Dataset and data cleaning
In motorsport competitions, circuits are typically divided into three main sectors. The sector times indicate the time interval spent by a car in each sector of the circuit for a specific lap. Differently from the GPS data, the sector time database is freely available^{1}^{1}1http://fiawec.alkamelsystems.com/. An example of the database structure is reported in Table I, where the columns , and contain the three sector times.
#  Lap  Stop  Elapsed  Class  Group  Team  

[s]  [s]  [s]  [s]  
1  1  33.978  38.779  32.358  105.115  LMP1  H  Porsche  
1  2  33.846  37.727  31.753  208.441  LMP1  H  Porsche  
1  3  33.340  37.789  36.823  316.393  LMP1  H  Porsche  
⋮  ⋮  ⋮  ⋮  ⋮  ⋮  ⋮  ⋮  ⋮  
77  30  40.246  46.643  40.224  3833.398  LMGTE Am  ⋮  Porsche  
77  31  B  40.622  47.265  45.367  3966.652  LMGTE Am  ⋮  Porsche 
77  32  121.453  45.261  38.340  4171.706  LMGTE Am  ⋮  Porsche 
To eliminate spurious laps from the dataset, f.i. laps led by the safety car, the corresponding sector times have been clustered through the DBSCAN algorithm [13]
, and only the data belonging to the cluster with the fastest sector times have been considered for successive analyses. The clusters of fast sector times and the outliers are shown in Figure
1 for each car.IiiB Forecasting the competitors’ speed profiles
Resorting to the sector times, we aim to estimate the speed profile of each competitor. Then, it is straightforward to derive an estimate of the competitors position during the race, which is fundamental to statistically model their behaviour.
The proposed procedure to estimate the speed profiles is now described. Considering a lap performed by our vehicle in absence of traffic and without using KERS, we extract a reference profile from GPS data, as shown in Fig. 2. We then scale it according to the measured sector times to estimate the speed profile of each competitor. The adopted linear scaling equation is
(1) 
where

is the th sector time performed by the car in the reference video;

is the speed of the car in the reference video, at the frame of the th sector;

is the th sector time of the th lap performed by the th competitor;

is the reconstructed speed of the th competitor, at the frame in the th sector of the th lap;

indicates the three sectors;

, with being the total number of laps performed by the competitor ;

, with being the total number of competitors.
IiiC Statistics of the competitors’ behaviour
Referring to the predicted speed profiles, the following statistics have been extracted from the cleaned dataset:

the free sector times distributions;

the overtaking probabilities.
The free sector times are defined as the sector times performed by a competitor with the preceding vehicle far at least 100 m for the whole duration of the sector. Under these conditions, it is possible to assume that the competitor performance and behaviour have not been influenced by the other competitors. Free sector times are useful to forecast the performance of competitors in absence of interactions. In Figure 3, an example of the sector times distribution is shown for a competitor.
The overtaking probabilities are modelled as functions of the section and category of the two competitors involved. These statistics are useful to practically describe the interactions between competitors along the sectors. Sections are a finer subdivision of the circuit with respect to the sectors and they allow to distinguish between straights and curves, which are typically characterised by very different probabilities of overtaking. Figure 4 represents an arbitrary subdivision of the circuit of Bahrain into sections, which has been considered as the test circuit to validate the proposed approach.
Denoting with the category of the vehicle that is attempting an overtake and with the category of the vehicle that may be overtaken, the overtaking probability of the pair along section is computed as
where is the number of overtakings of on in section , and is the number of times A and B have been in section with at most meters distance one from the other. Let us define the following notation:

LMP1: Le Mans Prototype 1;

LMP2: Le Mans Prototype 2;

LMGTE Pro: Le Mans Grand Touring Endurance Professionals;

LMGTE Am: Le Mans Grand Touring Endurance Amateurs.
Then, we can represent the overtaking probabilities for each pair of vehicle categories and each section. An example is provided in Figure 5, for the classes LMP1 and LMP2.
Iv Egovehicle model
The statistics derived in the previous section are used to model the behaviour of the competitors, whose actual dynamics is unknown due to lack of information. Considering the egovehicle instead, for which we aim to design the optimal lap strategy, the necessary information to model its dynamics is supposed to be available. Therefore, we propose here a dynamic model of the egovehicle, which is used to study the effect of the electrical energy usage on the speed profile. In the next section, the model will be used to compute optimal lap strategies.
The designed model is the result of a tradeoff between computational complexity and accuracy in the description of the relevant dynamics. The longitudinal dynamics of the vehicle is modelled as
(2) 
where

m is the total vehicle mass, accounting also for the fuel and the driver;

g is the gravity acceleration;

is the ground slope;

is the vehicle speed;

h is the height with respect to the road at which the vehicle centre of mass is located;

is the resistive rolling force at the front wheels;

is the resistive rolling force at the rear wheels;

is the aerodynamic resistive force;

is the thrust applied to ground by the electric motor through the front tires;

is the thrust applied to ground by the combustion engine through the rear tires;

and are the aerodynamic downforces, split between the front and rear tires, respectively;

and are the front and rear vertical tire forces, respectively;

is the distance between the front and rear axles.
A schematic representation of the involved quantities is depicted in Figure 6.
Being the torque curves of the electric motor and of the combustion engine known, it is possible to write
(3) 
(4) 
With reference to (3) and (4), represents the theoretically available thrust at the rear wheels provided by the combustion engine, is the engine torque, is the engine speed in rpm, is the gear ratio and is the gear selected by the driver. Similarly, represents the theoretical thrust provided by the electric motor at the front wheels, having in this case just one transmission ratio available.
The amount of thrust transferred from the motors to ground depends on the maximum forces that can be generated by the tires through friction. The absolute value of the maximum tire forces and at the front and rear wheels, respectively, are given by
(5a)  
(5b) 
being
the tireroad friction coefficient. The vertical forces can be calculated through moments equilibrium as
(6a)  
(6b) 
where
(7) 
is the air density, is the lift coefficient and is the reference surface. The aerodynamic force is given by
(8) 
where is the drag coefficient. Finally, the resistive rolling forces are
(9) 
being the rolling resistance coefficient.
The maximum longitudinal thrust that each tire can generate through friction can be calculated by vector difference between the maximum tire force and the lateral tire force experienced during curves. The lateral tire forces
and at the front and rear tires, respectively, can be computed with fair approximation considering a curve with a radius of curvature and constant vehicle speed as(10) 
Therefore, the absolute value of the maximum longitudinal forces and exchangeable with ground by the front and rear tires, respectively, are
(11) 
The driving/braking torques commanded by the vehicle powertrain depend on the usage mode. In the WEC events under analysis, there are four different modes. The vehicle central unit can decide whether to power the electric motor and combustion engine at the same time (mode 1), power the combustion engine only (mode 2), undergo sailing^{2}^{2}2Sailing is the condition for which the combustion engine is automatically powered off by the control unit to satisfy the technical constraint on the fuel usage, even if the driver applies full throttle. In this powertrain usage mode, the vehicle is decelerated by the aerodynamic forces and by the intervention of the KERS, as explained later. (mode 3) or actuate the brakes (mode 4). Different modes imply different longitudinal tire forces, and thus different vehicle accelerations. In modes 1 and 2, the absolute value of the longitudinal tire forces can be computed as the minimum value between the thrust that the motors are capable to provide and the thrust that the tires are capable to transfer, that is
(12a)  
(12b) 
In mode 3, the total longitudinal force is equal to the force deriving from the electric torque during sailing
(13) 
Finally, during braking the total longitudinal force is
(14) 
where is the deceleration force generated by brakes.
Considering a spatial discretisation of m, the speed profile is reconstructed using the longitudinal model and compared to a reference one. Given the vehicle velocity and the throttle/brake commands at the current spatial discretisation point, all of the quantities are evaluated through (2)(14), so as to obtain the vehicle acceleration , and then the velocity at the next discretisation point. The procedure is repeated iteratively for each discretisation point.
Hereinafter, the speed profile computed for the Bahrain circuit is compared with the real one that the reference car experienced during the real race. The results are shown in Fig. 7.
It is evident that the longitudinal vehicle model generates an overestimated speed profile with respect to the real one. This is due to different effects that have not been taken into account by the model. Therefore, three corrective coefficients are introduced into the model and properly tuned to better fit the real data. The corrective coefficients are:

the engine coefficient, which scales the thrust provided by the combustion engine;

the adherence coefficient, which scales the friction coefficient in lowspeed curves;

the downforce coefficient, which scales the lift coefficient in highspeed curves.
After introducing the corrective coefficients into the model, the two speed profiles result to be coherent, as shown in Figure 8.
V Trafficfree lap strategy optimisation
Having developed and validated the egovehicle model, it is now possible to formulate and solve an optimisation problem for the lap time minimisation, through the management of the powertrain energy budget. We remark that, at this stage, we aim to identify the best points of activation of the electric motor in a lap, considering absence of traffic.
Theoretically, the optimal strategy should be computed online during the real race, in order to take into account the actual traffic conditions. However, being this computation time consuming, we offline compute a set of trafficfree energy management strategies, and subsequently evaluate the best one in simulated traffic conditions (see Sec. VII).
The optimisation problem was initially solved using a MIQCP formulation. Although the method can provide optimal solutions, it has many shortcomings. First of all, it is time consuming, even for the resolution of a single optimisation problem. Therefore, generating a set of offline strategies would have been intractable. Moreover, numerical issues can degrade the performance of the solver, e.g. the presence of dense columns in the resulting matrices. The solver detects and eliminates as many dense columns as possible before optimising, but this may cause numerical instability. Finally, the problem could be illconditioned, which may lead to inconsistent results.
These issues may be attenuated by tuning the solver parameters, which is a difficult and timeconsuming operation. To cope with this, we propose an alternative method to solve the optimisation problem, based on Genetic Algorithms (GA), which provides suboptimal solutions whereas it does not suffer from the aforementioned problems. The MIQCP approach is presented just to provide a baseline for assessing the suitability of the GA. Then, the optimisation is solved multiple times with GA, varying the constraints on the electric motor usage, to generate the set of candidate lap strategies.
The basic optimisation problem, written according to the spatial discretisation, is given by
(15a)  
subject to  (15b)  
(15c)  
(15d)  
(15e) 
where

is the lap time;

is the optimisation variable, and represents the powertrain usage mode at each spatial discretisation point along the track through a onehot encoding vector of four elements;

is the consumed electrical energy in a lap;

is the maximum allowed electrical energy consumption in a lap;

represents the kilograms of fuel consumption in a lap;

represents the maximum allowed kilograms of fuel consumption in a lap;

is the amount of recovered electrical energy in a lap;

is the minimum allowed amount of recovered electrical energy in a lap.
The constraints (15c) and (15d) are set by the WEC technical regulation. Referring to the Bahrain International Circuit, the corresponding limits are and . Instead, the constraint (15e) is necessary to keep the state of charge of the battery greater than or equal to a constant value at the end of each lap. Thus, the minimum amount of recovered electrical energy must be equal to the amount of consumed electrical energy, that is
(16) 
Since the electrical energy can be recovered through both the Heat Energy Recovery System (HERS), , and the Kinetic Energy Recovery System (KERS), , we can write
(17) 
where the amount recovered through the HERS is track dependent and fixed for each lap.
In the next sections, the terms in (15) will be linked to the longitudinal vehicle dynamics. Lap time optimisation based on a MIQCP formulation is detailed in Sec. VA, whereas the GA approach is presented in Sec. VB.
Va MIQCP solver
We decide to divide the track into subportions with spatial discretisation m. The cost function and constraints are then reformulated as functions of the optimisation variables.
VA1 Cost function
We first link the vehicle acceleration to the lap time, whose minimisation is the objective of (15). The kinetic energy of the vehicle satisfies
(18) 
where refers to the generic curvilinear abscissa. Identifying with the discretisation points along the curvilinear abscissa, i.e. for the generic variable it holds that , the above equation can be discretised using the forward Euler method, obtaining
(19) 
where
(20) 
Computing the vehicle speed through the above equation would involve a square root operator. In order to preserve linearity, which is convenient for solving optimisation problems, the method presented in [12]
is employed. It is possible to prove that a geometric mean inequality constraint written as
(21) 
where , can be reformulated as a secondorder conic constraint
(22) 
Relaxing (20) as
(23) 
and taking the square root from both sides we obtain
(24) 
Hence, it is possible to reformulate the relaxed constraint as the following convex quadratic constraint
(25) 
linking the speed and the kinetic energy. The inverse of speed is usually defined as ‘lethargy’,
(26) 
that is the spatial derivative of time. Since (26) is a nonlinear constraint, we relax it and transform into a convex quadratic constraint
(27) 
Finally, the lap time can be expressed as
(28) 
Therefore, the relationship between the control inputs , and the objective is fully described by (19), (25) and (27), resorting to the intermediate variables and .
VA2 Constraints
To make the constraints of (15) explicit, it is necessary to calculate the consumed fuel and used/recovered electrical energy in each portion of the track. The technical regulation defines the maximum fuel consumption per second at full thrust, that is . Given the combustion engine torque , the amount of consumed fuel kilograms can be computed as
(29) 
From the thrust provided by the electric motor and its efficiency in traction , it is straightforward to compute the used electrical energy usage as
(30) 
The electrical energy can be recovered through the KERS both during sailing or in the braking phase. In the first case, the KERS intervenes to partly recover the kinetic energy (). In the second case, instead, the energy is recovered through a braking force , lower in module than the maximum value that can be guaranteed by the brakes and the adherence with ground. Hence, according to the situation, the recovered electrical energy can be estimated using one of the two expressions
(31a)  
(31b) 
where is the efficiency of the electric motor in recuperation phase. The constraints of (15) can be finally reformulated as
(32a)  
(32b)  
(32c) 
The optimisation problem was built using the toolbox YALMIP [18]. The resulting Mixed Integer Quadratically Constrained Program (MIQCP) was then solved with IBM^{®} ILOG^{®} CPLEX^{®} version 12.8.0. The optimised speed profile is shown in Figure 9, as compared with the reference one. There is significant coherence between the reference speed profile and the one resulting from optimisation. Finally, the points of activation of the electric motor are highlighted in Figure 10, from which we can conclude that the solver decides to use the electric motor in the first part of the straights, achieving the highest possible speed in the shortest time. This is coherent with the behaviour of professional human drivers.
VB GeneticAlgorithmsbased solver
As previously mentioned, we now propose an alternative resolution method for the optimisation problem based on Genetic Algorithms. The circuit is divided into regions, each one from the beginning of a straight to the beginning of the following one. Differently from the MIQCP approach, whose optimisation variable embodies the powertrain usage mode directly, we consider optimisation variables for each region, that is the electrical energy consumption and the fuel consumption . The total number of optimisation variables in a lap is therefore . We further assume that the energy budget of each region, encoded by the optimisation variables, is actuated continuously from the beginning of the region (straight) until it is completely consumed. This assumption is supported by the fact that the optimal way to apply energy is to use it in the first part of the acceleration region, as known to the experts of the field. Finally, we highlight that, given an instance of the optimisation variables and the previous assumption, it is possible to uniquely identify the corresponding powertrain usage mode, speed profile and lap time.
With reference to the traditional nomenclature of GA, an instance of the optimisation variables constitutes the genome of an individual of the population. We employ a discretisation step of kJ for the electrical energy consumption and g for the fuel consumption, and select the optimisation variables ranges as and , respectively. The discretisation speeds up mutations and crossovers to reach the optimised solution, and constitutes a fair approximation being the step sizes three orders of magnitude lower than the maximum value that the variables can take. The inequality constraints (15c) and (15d) are then enforced through linear inequalities on the optimisation variables. Finally, the fitness function is the lap time generated by the genome.
A reasonable initial population was provided to the GA to hot start the optimisation and improve computational times. The simplest way to obtain a hotstart genome in the population is to compute the amount of electrical energy and fuel consumed in each region of the circuit in a real lap. The chosen reference lap was performed in absence of interactions with competitors and with the lowest lap time possible, so as to be close to the optimal solution. Another important hyperparameter to be carefully selected is the population size, which is critical for the convergence of the GA. Literature provides some heuristic methods to select the dimension of the population. Anyway, for the majority of the problems they indicate that an increase in the population size statistically reduces the error between the solution found by the GA and the exact solution
[14], at the expense of an increase in the computational time. The most common rule of thumb establishes that the dimension of the population needs to be at least equal to the size of the genome. Converting the variables from decimal to binary, as typical for GA, we obtain(33) 
from which the initial population needs to have at least individuals. After analysis of the results, we finally changed the population size to individuals to obtain stable and repeatable solutions.
Differently from the previous method based on the MIQCP formulation, which generates a single optimal solution in absence of competitors, we employ the GA to create a set of optimal energy strategies, whose efficacy will be then evaluated in realistic traffic conditions. The evaluation is performed in the next section. The set of strategies is obtained by launching the GA many times, each with different constraints on the electrical energy usage. The underlying reasoning for heuristically imposing extra constraints is the following. Since the strategies will be evaluated in complex traffic scenarios, activating the electric motor where overtaking is easier to be performed, e.g. a straight, can be beneficial to reduce the time loss related to the maneuver and the lap time. Table II shows the constraints applied in each strategy and the corresponding optimal lap time. It can be noticed that the applied constraints have an action range of at least 100 meters. This is done to respect the sensitivity/capability of the driver to manually intervene on the poweroff/on button of the electric motor. Some exemplary optimal strategies are shown in Figure 11.
Strategies #  Lap time (s)  Electrical Energy constraints 

1  104.028  No constraints 
2  104.092  No KERS first 100 meters straight 
3  104.152  No KERS first 100 meters straight 
4  104.273  No KERS first 110 meters straight 
5  104.290  No KERS first 100 meters straight 
6  104.310  No KERS first 200 meters straight 
7  104.373  No KERS first 100 meters straight 
8  104.396  No KERS first 300 meters straight 
9  104.402  No KERS first 100 meters and straights 
10  104.415  No KERS first 100 meters and straights 
11  104.417  No KERS first 200 meters straight 
12  104.566  No KERS first 100 meters and straights 
13  104.603  No KERS first 200 meters straight 
14  104.674  No KERS first 70 meters straight 
15  104.733  No KERS first 140 meters straight 
Vi Multiagent simulations of the competitors’ behaviour
The approach presented in Sec. V generated a set of offline strategies for the lap time minimisation in absence of competitors. To evaluate them in realistic race conditions, where competitors are present along the track and mutually interact with each other, it is necessary to simulate their behaviour. In this section, we explain how to build multiagent Monte Carlo simulations of the competitors’ behaviour from the statistics computed in Sec. III.
The forecasts have to consider a time horizon that is long enough to allow the egocar to complete the lap. For this reason, we decide to perform twolapslong forecasts starting from the initial condition. The positions of the competitors in absence of mutual interactions are forecast by means of the free sector times probabilistic distributions, derived from Sec. III. With reference to Figure 3, we remark that the associated probability distributions are not Gaussian. To cope with this, we perform random sampling, with enough extractions to guarantee that the probabilistic distributions of the competitors’ behaviour can be reliably approximated. The forecast position along the track of an exemplary competitor for different simulations is shown in Figure 12.
At this point, we introduce the interactions between the competitors. To do so, a multiagentbased model has been developed, resorting to the Influence/Reaction principle [19, 3, 9]. Each competitor is considered as a rational agent that tries to minimise its lap time. If a competitor gets closer to the preceding one, it perceives its influence and has to react, performing overtaking or following. When an overtaking may be performed, the category of the involved vehicles is evaluated and, taking into account the section along the circuit where the overtaking may occur, the overtaking probability is computed from the statistics derived in Sec. III. A random number in the range is extracted and compared to the overtaking probability. If it is lower, then overtaking succeeds, otherwise the car keeps on following the preceding car for the entire length of the section. The procedure is then repeated at the successive section.
Repeating these steps for all possible overtakings involving the competitors along the circuit generates a Monte Carlo numerical simulation. Two examples of Monte Carlo simulation are reported in Figure 13.
To reliably forecast the behaviour of the competitors, it is necessary to generate a significant number of Monte Carlo numerical simulations. This means performing a large amount of random samplings of free sector times and overtaking probabilities. These computations may however be time consuming. Indeed, they have to be performed in real time at the beginning of each lap, as they depend on the actual positions of the competitors along the circuit. A solution to this issue can be addressed through parallel computing, since the simulations are completely independent from each other. The statistical analysis of the outputs and evaluation of the optimal strategy in presence of realistic traffic conditions is described in the next section.
Vii Stochastic lap strategy optimisation in traffic conditions
Optimal strategies for the powertrain energy budget in absence of traffic have been presented in Sec. V. On the contrary, the Monte Carlo approach defined in VI allows to forecast the positions of the competitors, accounting for their mutual interactions. We now propose a novel way to combine the two features and build a stochastic optimal solver, aiming to identify the strategy that statistically guarantees the minimum lap time in presence of traffic.
Stochastic Dynamic Programming (SDP), which is the method we employ in this work, is an optimisationbased method for making sequential decisions under uncertainty. In our framework, uncertainty is associated to the occurrence of overtakings. Being SDP a discrete decisionmaking process and considering stages , the following ingredients are defined at each timestep :

an initial state , where is the set of feasible states at stage ;

a decision variable , where is the set of feasible actions that can be chosen at stage ;

an immediate cost or reward function , representing the incurred cost or the gained reward at stage if an action is chosen at the state ;

a state transition function , defining the state change from towards ;

a discount factor ;

a conditional probability , representing the probability to move into state given the current state and the chosen action .
The optimal control problem can be iteratively described through the value function at the generic stage as
(34) 
which represents the expected optimal cost that can be attained from the state if the optimal action is chosen.
According to (34), the optimal strategy is the one that minimises the value function at the initial stage of the problem, and can be computed resorting to policy iteration. However, we have already selected fifteen strategies a priori in Sec. V, through the energy budget optimisation problem. Thus, we do not perform policy iteration, but policy evaluation: the value function deriving from each of the precomputed strategies is evaluated. Finally, the best strategy is identified as the one that minimises the value function at the first stage.
To apply this technique, we first test each of the fifteen optimal energy strategies in each of the Monte Carlo numerical simulations. Figure 14 reports an example of this procedure.
The parameters of this technique have been defined in the following way. The variable , representing the state of the system, consists in the negative number of the possible overtakings to be performed in the reference lap. Indeed, the positions of the reference car and of the competitors are known from respectively the optimisation problem and the Monte Carlo numerical simulations. Thus, for each combination of optimal strategies and numerical simulations it is possible to compute the number of possible overtakings that the reference car can perform in the lap. For instance, with reference to Figure 14, three overtakings can occur. This implies that the state of the system is initialised to . When an overtaking occurs, the state is augmented by 1. The decision variable consists in the usage of the powertrain energy budget, either coming from the combustion engine and from the electric motor. The variable refers to the probability of changing the state from to , once a specific decision variable is chosen. Since we have defined the state as the number of possible overtakings to be performed in a lap, this probability is exactly the overtaking probability that we have drawn from the analysis of previous years events as a function of the category of the involved vehicles and of the section where the overtaking may occur.
The variable is defined as a cost. When the reference car approaches a competitor, according to the categories and the section where the vehicles are, there is a specific overtaking probability. If overtaking is not performed, the egovehicle needs to slow down, which involves a time loss. The latter can be computed as the difference between the time instant at which the reference car has reached the end of the section behind the preceding car and the instant of time at which the reference car would have reached the end of the section without traffic. Moreover, if the reference car is obliged to stay behind the preceding car in a section, it has to reduce its speed. Once it is able to overtake the slower vehicle in a successive section, it needs time before reaching its reference optimal speed profile again. This time loss is also added to the cost.
The parameter is a factor that discounts future costs, which is typically employed in infinitetime problems. Since we deal with a finitetime problem, the parameter is set equal to .
The stages of SDP coincide with the sections defined for the computation of the overtaking probabilities in Sec. III
. In each section the algorithm evaluates whether the reference car may perform an overtaking. If a competitor is close enough, there is a specific probability of performing the overtaking. If overtaking succeeds, the state is augmented by one and there is no associated time loss. On the contrary, the reference car is obliged to follow the preceding vehicle, the state does not change, and a time loss is introduced in the cost function It is convenient to graphically represent all of the probabilistic events rising from overtakings in a lap. In this regard, we adopt a suitable and common representation called Decision Tree. To build Decision Trees, the possible occurrence of an overtaking is evaluated in each section from the beginning to the end of the track (forward pass
[17]). Then, a backward pass computes the value function at the initial stage of the problem, i.e. . It consists in multiplying the probability of an event with the associated cost values, and summing them up stage by stage from the end to the beginning, according to (34). A portion of the Decision Trees for the optimal strategy is reported in Figure 15.The value functions at time zero of each strategy are reported in Table III. The fifth strategy results to be the optimal one, having the lowest time loss. Despite this strategy is approximately 0.3 s slower than the first one in absence of traffic conditions, i.e. the reference car, it is statistically faster of approximately 0.5 s considering traffic conditions. Moreover, the fifth strategy has a high statistical significance, since it resulted to be the optimal strategy in approximately 70% of the Monte Carlo numerical simulations. Further graphical interpretations are provided in Figures 16 and 17 to support our approach. They both show that the optimal strategy tends to save electric power and release it to perform overtakings only in portions of the track where they produce lower time losses.
Strategy #  

(s)  
1  2.131 
2  1.987 
3  1.792 
4  1.884 
5  1.662 
6  2.092 
7  2.176 
8  2.338 
9  2.359 
10  2.421 
11  2.428 
12  2.619 
13  2.211 
14  2.886 
15  2.534 
The analysis can be extended to a sequence of laps, i.e. a stint of the race. Considering the fifth stint of the Bahrain 2017 event, we launch a Monte Carlo numerical simulation starting with the initial positions of the competitors, and identify the best among the fifteen precomputed strategies through SDP. The positions of the egocar during the real race are then replaced by the space profile deriving from the optimal strategy. Then, SDP is employed a second time to evaluate the statistical time loss due to overtakings that would have been generated through the optimal strategy. Figure 18 shows that our method can lead to a time gain of s compared to the original strategy used during the race. Running the procedure multiple times, we obtained an upper bound equal to s and a lower bound of
s, with confidence interval
. Figure 19 represents the temporal gain lap by lap, with associated confidence interval. It is evident that the application of the proposed method can have a significant impact on the result of an event, since the time difference between the winner and the competitors is usually of a few seconds.Viii Conclusions
In this work, we have presented an efficient procedure to generate optimal lap strategies for LMP1 hybrid electric vehicles in WEC events. Particularly, the framework computes the optimal energy budget utilisation that statistically minimises the egovehicle lap time in presence of competitors, while complying with the technical regulations.
Our approach relies on multiple contributions. First, we have shown how to extract meaningful statistics regarding the competitors’ motion along the track, using the limited amount of publicly available data from previous races. The statistics model the sector times and overtaking probability distributions of each vehicle type. They are used to develop realistic Monte Carlo simulations of the agents motion and interactions in a lap. Second, we have computed a set of candidate trafficfree solutions to the egovehicle lap strategy optimisation problem using Genetic Algorithms, presenting them as a more computationally efficient alternative to the classical MIQCP formulation. Finally, the trafficaware optimal solution is statistically identified among the candidate trafficfree policies using Stochastic Dynamic Programming. Relying on several Monte Carlo simulations of the competitors’ motion, Stochastic Dynamic Programming is used to evaluate the best strategy among the candidate ones.
To validate our approach, we have applied it to a stint of a real race. The results show that our approach leads to an average time gain of s, compared to the strategy that was actuated during the real race. The time gain is particularly significant, since the time difference between the winner and the leading vehicles is usually of a few seconds in WEC events.
Finally, we highlight that our strategy can be easily extended to other types of racing events. In fact, it only relies on an egovehicle longitudinal model and on the sector times data of the vehicles from previous races, which are commonly available. The extension to different types of events is left to future works.
Acknowledgment
This work has been developed in collaboration with Dr. Ing. h.c. F. Porsche AG. We would like to thank the Porsche Motorsport Team for providing sensitive data on WEC events and their vehicle. A sincere thanks to Stephen Mitas, Porsche Chief Race Engineer, and to Emiliano Giangiulio and Vincenzo Scali, Porsche engineers, for contributing to the establishment of this work and for their support.
References
 [1] (2011) Monte carlo scalable algorithms for computational finance. Procedia Computer Science 4 (Complete), pp. 1708–1715 (English). External Links: Document Cited by: §I.
 [2] (2021) Optimal adaptive race strategy for a FormulaE car. Proceedings of the Institution of Mechanical Engineers, Part D: Journal of Automobile Engineering, pp. 09544070211047343 (en). Note: Publisher: IMECHE External Links: ISSN 09544070, Document Cited by: §I, §II.
 [3] (2017) An adaptive agentbased approach to traffic simulation. Transportation Research Procedia 25, pp. 1238–1248. Note: World Conference on Transport Research  WCTR 2016 Shanghai. 1015 July 2016 External Links: ISSN 23521465, Document Cited by: §VI.
 [4] (2009) Planning formula one race strategies using discreteevent simulation. Journal of the Operational Research Society 60 (7), pp. 952–961. External Links: Document Cited by: §II.
 [5] (201710) Heuristic Optimization for the Energy Management and Race Strategy of a Solar Car. Sustainability 9 (10), pp. 1576 (en). External Links: ISSN 20711050, Document Cited by: §I, §II.
 [6] (2018) CHAPTER 3 World Endurance Championship: 2012 to Present. In Prototype Powertrain in Motorsport Endurance Racing: an SAE Technical Paper Compilation, pp. 15–23. Note: Conference Name: Prototype Powertrain in Motorsport Endurance Racing: an SAE Technical Paper Compilation External Links: ISBN 9780768091601 Cited by: §I.
 [7] (202109) A Convex Optimization Framework for Minimum Lap Time Design and Control of Electric Race Cars. IEEE Transactions on Vehicular Technology 70 (9), pp. 8478–8489. Note: Conference Name: IEEE Transactions on Vehicular Technology External Links: ISSN 19399359, Document Cited by: §I.
 [8] (202111) Minimumlaptime Control Strategies for Allwheel Drive Electric Race Cars via Convex Optimization. Note: Comment: Submitted to ECC 2022 External Links: Link Cited by: §I, §II.
 [9] (2005) A multiagent theory for simulation. In International Conference on Modelling, Simulation and Optimization, Oranjestad, Aruba. Cited by: §VI.
 [10] (2018) Regulations. External Links: Link Cited by: §I.
 [11] (2021) Timeoptimal gearshift and energy management strategies for a hybrid electric race car. Applied Energy 282, pp. 115980 (en). External Links: ISSN 03062619 Cited by: §I, §II.
 [12] (2018) Timeoptimal control strategies for a hybrid electric race car. IEEE Transactions on Control Systems Technology 26 (1), pp. 233 – 247 (Undetermined). External Links: Document Cited by: §VA1.
 [13] (1996) A densitybased algorithm for discovering clusters in large spatial databases with noise. In Proceedings of the Second International Conference on Knowledge Discovery and Data Mining, KDD’96, pp. 226–231. Cited by: §IIIA.
 [14] (2002) Optimal population size and the genetic algorithm. Cited by: §VB.
 [15] (201811) A Race Simulation for Strategy Decisions in Circuit Motorsports. In 2018 21st International Conference on Intelligent Transportation Systems (ITSC), pp. 2986–2993. Cited by: §II.
 [16] (202009) Minimum RaceTime PlanningStrategy for an Autonomous Electric Racecar. In 2020 IEEE 23rd International Conference on Intelligent Transportation Systems (ITSC), pp. 1–6. External Links: Document Cited by: §I.
 [17] (2002) Operations research models and methods. 1 edition, John Wiley & Sons Inc.. Cited by: §VII.
 [18] (2004) YALMIP : a toolbox for modeling and optimization in matlab. In 2004 IEEE International Conference on Robotics and Automation (IEEE Cat. No.04CH37508), Vol. , pp. 284–289. External Links: Document Cited by: §VA2.
 [19] (2007) The irm4s model: the influence/reaction principle for multiagent based simulation. In AAMAS ’07, Cited by: §VI.
 [20] (2005) Markov decision processes: discrete stochastic dynamic programming. 1 edition, John Wiley & Sons Inc.. Cited by: §I.
 [21] (1983) Introduction to stochastic dynamic programming. Academic Press Inc.. Cited by: §I.
 [22] (201712) RealTime Control Algorithms for a Hybrid Electric Race Car Using a TwoLevel Model Predictive Control Scheme. IEEE Transactions on Vehicular Technology 66 (12), pp. 10911–10922. Note: Conference Name: IEEE Transactions on Vehicular Technology External Links: ISSN 19399359 Cited by: §I.
 [23] (2017) Realtime control algorithms for a hybrid electric race car using a twolevel model predictive control scheme. IEEE Transactions on Vehicular Technology 66 (12), pp. 10911–10922. External Links: Document Cited by: §II.
 [24] (201711) Timeoptimal Control Policy for a Hybrid Electric Race Car. IEEE Transactions on Control Systems Technology 25 (6), pp. 1921–1934. Note: Conference Name: IEEE Transactions on Control Systems Technology External Links: ISSN 15580865, Document Cited by: §I.
 [25] (201311) Strategy optimization of a solar car for a longdistance race using Big Bang — Big Crunch optimization. pp. 521–526. External Links: Document Cited by: §I, §II.