Discrete event optimization of a vehicle charging station with multiple sockets

The relevance and presence of Electric Vehicles (EVs) are increasing all over the world since they seem an effective way to fight pollution and greenhouse gas emissions, especially in urban areas. One of the main issues related to EVs is the necessity of modifying the existing infrastructure to allow the installation of new charging stations (CSs). In this scenario, one of the most important problems is the definition of smart policies for the sequencing and scheduling of the vehicle charging process. The presence of intermittent energy sources and variable execution times represent just a few of the specific features concerning vehicle charging systems. Even though optimization problems regarding energy systems are usually considered within a discrete time setting, in this paper a discrete event approach is proposed. The fundamental reason for this choice is the necessity of limiting the number of the decision variables, which grows beyond reasonable values when a short time discretization step is chosen. The considered optimization problem regards the charging of a series of vehicles by a CS connected with a renewable energy source, a storage element, and the main grid. The objective function to be minimized results from the weighted sum of the (net) cost for purchasing energy from the external grid, the weighted tardiness of the services provided to the customers, and a cost related to the occupancy of the socket during the charging. The approach is tested on a real case study. The limited computational burden allows also the implementation in real-case applications.


Introduction
Greenhouse gas emissions, and pollution in general, are affecting negatively cities. Sustainable energy sources and new technologies can help to reconcile the huge energy demand with an acceptable climatic impact. A significant contribution to emissions is represented by transport and logistics. The use of Electric Vehicles (EVs) may produce a huge reduction of emissions when the power to feed the vehicles is produced by renewable resources. However, also when renewables are not used, the use of EVs may have positive impacts on pollution in cities because of the shift from traditional vehicles to EVs. Mass deployment of EVs may be a good solution (Shareef et al. 2016;Ferrero et al. 2016), but, unfortunately, wide usage of EVs may cause technical problems. As an example, the power grid can be harmfully affected by uncontrolled charging, long charging times, and interruptions (Sbordone et al. 2015;Qian et al. 2015). New technologies, such as Vehicle-to-Grid (V2G), Smart Charging (SC), and Vehicle to Building (V2B), would allow the vehicles to inject power into the electrical grid and/or modulating power during the charging process.
Another drawback is that the use of EVs is prevented by insufficient charging infrastructure, the high cost of vehicles, and the long times for charging. Moreover, to manage a large number of EVs, as highlighted in (Shaukat et al. 2018), there is an impelling need to introduce an aggregator as an intermediate between EVs and the grids. This new figure can also provide ancillary services to the distribution grid through the retail market, increasing network stability and reliability (Zhu et al. 2018;Islam et al. 2019).
At the city level, it is necessary to integrate the transportation and the electrical networks to plan the distribution over the territory of the charging stations and the definition of optimal scheduling policies for vehicle charging. In fact, many problems may arise such as: a) the electrical grid can become unstable due to distributed and intermittent loads; b) charging stations cannot be used at their maximum power capacity because they are positioned in a portion of the electrical grid in which there are high loads; c) electrical vehicles can be charged in a much longer time because the charging station is not able to manage multiple vehicles through optimized power management strategies; d) long queues can be present in some charging stations while others may suffer from a lack of demand.
In the present paper, attention is focused on the optimal scheduling of electric vehicles in charging stations with multiple sockets and in islands of recharge (for example parking areas equipped with renewables and storage systems). In the literature, several approaches that aim at the optimal scheduling of electric vehicles are based on discrete time decision models and result in problems difficult to be solved, especially for the high number of variables. For this reason, heuristics and metaheuristics have been applied as well as decision architectures based on decentralized optimization. Differently from the majority of papers in literature, following the same approach as in , in this paper, a discrete event approach is used to formalize the optimization model. The reason lies in the necessity of reducing the number of variables and computational time.
Differently with the respect to the above cited paper, in which only one vehicle can be under charge, at a given time instant, in this paper the case of a multiple charging service station is considered. That is, in the model presented in the following sections there is the possibility of simultaneously charging several vehicles, up to a maximum integer number, which is represented by the number of possible electrical connections (sockets) in the charging station. The necessity of limiting the number of vehicles simultaneously under charging gives rise to the necessity of introducing a set of binary variables, whose presence makes the optimization problem a (nonlinear) Mixed Integer Problem (MIP). This serious complication, with respect to the single-vehicle charging case, can still be managed for moderate size problem instances, like those that are expected to be solved in real cases (possibly in real-time).
The rest of the paper is structured as follows. In the next section, a brief survey of the state of the art is provided, based on the current scientific literature. In the third section, the proposed model is presented. In the fourth section, the optimization problem is introduced and discussed. In the fifth section, the application of the proposed approach to a case study is provided. In the sixth section, an extension of the model is considered in which power flow from vehicles is allowed (V2G). Even for this model, an application study is presented. Finally, some concluding remarks will end the paper.

State of the art
In recent literature, there are several papers related to EVs' charging and optimization. In (Shen et al. 2019), a survey is presented on EVs operations management. Different models and methods have been considered for the following topics: location of charging stations, charging operations (considering centralized and decentralized approaches), business models, and policy.
Other survey papers (Tan et al. 2016;Yang et al. 2015;Zheng et al. 2019) are focused on smart grids that integrate EVs. In (Tan et al. 2016), a review of papers on V2G technology integrated in smart grid is present, with a special focus on optimization-based approaches, while in (Yang et al. 2015) scheduling methods to integrate plug-in electric vehicles are reviewed, examined and categorized on the basis of different possible approaches (i.e. analytical scheduling, conventional optimization methods (e.g. linear, non-linear mixed-integer programming and dynamic programming), game theory, and meta-heuristic algorithms). A major problem is represented by multi-objective and high-dimension problems that result from the formalization of scheduling problems for EVs that integrate stochastic charging behaviors and intermittent renewable energy generation. In (Zheng et al. 2019), particular attention is paid to the V2G technology.
Another interesting paper (Rahman et al. 2016) reviews the use of optimization methods for the charging infrastructure related to plug-in hybrid electric vehicles (PHEVs) and EVs. The authors conclude that there is a need for optimization models with a specific application in solar-based charging stations to attain an optimal integration of EVs in the charging infrastructure while guaranteeing a reduction of emissions.
From an application point of view, the optimal management of EVs is performed in connection with different frameworks: energy market, microgrids, and transportation problems. As regards the energy market, attention is focused on the figure of an aggregator of EVs that has to bid in the energy market (Ferro et al. 2020a).
In (Song et al. 2019), the authors propose two stochastic programming models (for dayahead planning and real-time operation management) for the management of EVs fleet's charging and reservation assignment. In the day ahead, bids and spot market are determined by the fleet operator to the balancing market and then refined during the real-time operation management. In (Gupta et al. 2018), multiple aggregators are considered and the total profit and the number of scheduled EVs are maximized.
In (Hashemi et al. 2019), the aggregator profit is considered, taking into account network operation indices and Distribution System Operator's (DSO's) policies. In particular, the aggregator participates in day-ahead and real-time electricity markets offering power quality services to DSO.
Also in (Cao et al. 2020), the aggregator profit is considered for EVs' scheduling, and robust optimization techniques are used to face the uncertainty of grid price.
In the present paper, EVs are scheduled during the day at the local level and thus the profit of an aggregator is not considered. In fact, in our paper, the detailed scheduling process in terms of due dates, deadlines, and release times is considered.
Other articles study the optimal integration of EVs in smart cities, sustainable districts, and microgrids.
As reported in (Sachan and Adnan 2018), it is necessary to consider the technical constraints imposed by the electrical grid to reduce the network peak load demand and voltage violations. Then, it is also crucial to consider the needs of electric vehicles to define their optimal charging process. The authors in (Sachan and Adnan 2018) propose a coordinated scheme for the assessment of the optimal number of EVs that can be charged from a distribution network without reinforcing the grid or changing the grid infrastructure. In (Aujla et al. 2019), other important aspects are considered: energy trading and pricing for electrical vehicles in smart cities. An energy-trading scheme is proposed which allows EVs to obtain energy from any available CSs (Charging Stations) using a multi-leader multi-follower Stackelberg game and a multi-parameter pricing scheme. Then, as highlighted in (Amini et al. 2017), EVs and renewable resources should be coupled and managed together to have a reduction of emissions. Generally, EVs are seen as an intermittent forecasted load (or in some case deferrable) within a local Energy Management System (EMS) (Delfino et al. 2019). In (Ferro et al. 2018a), a first attempt to define an optimization model for EVs' scheduling in microgrids in terms of due dates, deadlines and release times is considered. (Khalkhali and Hosseinian 2020) present a scheduling framework based on stochastic programming and Model Predictive Control for EVs parking lots where both fast and slow charging modes are present.
Besides, there is a portion of literature that couples EVs charging and transportation systems. In particular, User Equilibrium (UE) traffic assignment approach is extended to the case in which a certain amount of traffic is generated by EVs (He et al. 2014;Xiang et al. 2016;Ferro et al. 2020b) and routing and charging algorithms are considered (Ferro et al. 2018b;Chen et al. 2018;Froger et al. 2017;Hiermann et al. 2016).
In the present paper, attention is focused on the optimal scheduling of charging of EVs, based on discrete event optimization. The proposed model is thought to manage charging stations with multiple sockets (or even multiple charging stations in an area of recharge) either from a remote control or directly installed in the charging station.
From a methodological point of view, different approaches have been considered (Yang et al. 2015) and different mathematical models have been formalized for optimal scheduling of EVs charging. In particular, some papers (Aliasghari et al. 2018;Ito et al. 2018;Sarikprueck et al. 2018;Ferro et al. 2018aFerro et al. , 2018b have used discrete time problem formalizations, solved by mathematical programming techniques, which have the drawback of a high number of variables with a consequent high computational time. In , the authors use a contract theoretic approach (i.e., a tool from microeconomics that allows agreeing two entities by providing economic incentives) for the optimal charging of a platoon of vehicles that maximizes the utilities of the CSs satisfying quality of service constraints. The algorithm is iterative, and the convergence is demonstrated. In (Atallah et al. 2018), the authors consider several supercharge facilities with multiple charging outlets and compare centralized and decentralized methods for the optimal scheduling of EVs. The centralized linear integer optimization model provides the best results in terms of waiting time, with a drawback of low scalability. Instead, the distributed game-theoretic approach overcomes the scalability issue obtaining promising results. In (Liu et al. 2018) the authors propose a day-ahead EV charging scheduling based on an aggregative game model in which the pure strategy Nash equilibrium is proved. The charging costs are minimized under constraints representing the users' requirements. The authors in (Shah et al. 2018) propose the application of an algorithm that is usually adopted for the control of communication networks' congestion: the Additive Increase Multiplicative Decrease algorithm. In (Liu et al. 2019) an aggregator of EVs is considered and a predictive transactive control is proposed to manage day-ahead electricity procurement and real-time EVs charging management to minimize its total operating cost, based on a quantification of the charging flexibility. In (Latifi et al. 2019), the authors want to maximize grid efficiency, minimize customers' costs, and maximize the capacity for ancillary services. A game-theoretic decentralized approach is proposed for the optimal scheduling of EVs. In (Wang et al. 2017) the customers' charging preferences are considered by developing an architecture that is based on both centralized and decentralized optimization and that uses a model predictive control-based adaptive scheduling strategy.
In recent literature, event-triggered approaches for the integrated management of EVs, and charging stations are present in many works as in (Linsenmayer et al. 2018) where a framework for decentralized control of platoons of vehicles using event-triggered communication is presented. In (Azar and Jacobsen 2016) a hierarchical event-triggered multi-agent system approach is proposed for coordinated scheduling of the charging process of electric vehicles.
However, as noted in , event-triggered approach present in the literature commonly consists of on-line scheduling algorithms capable of "correcting" a pre-existing schedule when a new vehicle requiring charging service arrives at the station. Instead, the approach presented in this paper consists in developing a predictive discrete event optimization model for the optimal scheduling of electric vehicles in charging stations with multiple sockets that can be used for parallel charging. This is essentially the same approach followed in ), but it is now extended to the case in which several vehicles may be charged simultaneously. Besides, a further extension is provided with respect to the model in , consisting of the possibility of power flows from the vehicles, that is, the so-called V2G model.

The model
The system architecture is presented in Fig. 1. We consider a charging station made of a charging unit plus a storage element and a renewable energy source. The charging unit may provide charging services simultaneously to various vehicles. The maximum number of vehicles that can be connected to the charging unit is N (we say that the charging station has N sockets).
The (monodirectional) power flow to the vehicle V j is denoted with f L, j (t), j = 1, …, M (obviously f L, j (t) = 0 if V j is not connected at time instant t). The total power flow provided to the charging station is f L, TOT (t), given by the sum of the power flows provided to the vehicles under charge.
The power flow drawn (delivered) from (to) the storage element is denoted as f S (t). This flow is bi-directional, and, by convention, it is assumed to be positive when the power is drawn from the storage.
Similarly, f G (t) is the power flow from (to) the main grid. Also, this flow is bi-directional and is retained as positive when power is obtained from the main grid. Besides, f R (t) is the (monodirectional) power flow coming from the renewable energy source. This function is assumed given for the whole optimization horizon of interest.
Finally, BP(t) and SP(t) are the time-varying buying/selling prices from/to the main grid. Also the function BP(t) and SP(t) are assumed as given.
Every vehicle V j requiring charging service is characterized by the following parameters: & Release date (rl j ), that is, the time instant at which the charging service may begin; for the sake of simplicity we can assume that this time instant coincides with the arrival time instant [h]; & Due date (dd j ), that is, the time instant at which the service should be completed [h]; & Deadline (dl j ), that is the time instant at which the service must be completed [h]; & Energy request (ER j ), that is the amount of energy required for the charging service [kWh]; & Penalty tardiness coefficient (α j ), that is, the cost paid for a unit delay (with respect to the due date dd j ) regarding the completion of the service, for a unit of energy requested; α j is expressed in € kWh⋅h Â .
The required energy must in any case be satisfied and no service can be denied. The optimization problem that is considered refers to a number M of vehicles that are already present within the system. In this paper, the formalization of the problem will be provided in a form that encompasses the case M ≥ N as well as the case M < N.
A discrete event approach is adopted in the formalization of the optimization problem. A continuous time approach would lead to a functional optimization problem, difficult to handle also for the presence of nonlinearities and constraints. On the counterpart, a discrete time formalization would require the introduction of a very large number of decision variables (one for each kind of variable and one for each discretization interval), thus leading to unmanageable problem sizes for real-world applications. This issue will be discussed more thoroughly later in the paper.
The discrete event approach is formalized in our model by dividing the time horizon of interest in time intervals (in general, of unequal length) separated by events corresponding to a (single) service completion time instant (as it is shown in Fig. 2). It is assumed that the order of the completion time instants is given, in accordance with some criterion a-priori defined, as, for instance, the arrival order of the customers.
Then, regarding time interval Of course, at any time instant, the following power balance equation holds where f L, TOT (t) is the function representing the total power flow delivered to vehicles at time t. However, in the formalization as a discrete event optimization problem, instantaneous constraints cannot be imposed. To transform constraint (1) into a constraint referring to time intervals, we must write, instead of constraint (1), where f S;i is defined as the average value of f S (t)in time interval (C i − 1 , C 1 ) and f R;i has a similar meaning, namely It is apparent that f R;i turns out to be a function of C i − 1 , C i . Note that (3) is a definition, whereas (4) is a constraint to be embedded within the statement of the optimization problem.
In the solution of the optimization problem that we are going to formalize, only the average values f S;i , i = 1, …, M will be determined (and not, of course, the function f S (t)). These average values will be constrained in order to avoid physically infeasible power flows from/to the storage. It is clear that such a constraint should be imposed on the values of f S (t), for any value of t. However, this is not possible, owing to the discrete event formalization of the model, and thus the bounds over f S;i are to be chosen in order to easily allow the fulfilment of the physical constraint on f S (t)for any time instant. Besides, note that we have imposed that functions f G (t), f L, j (t) (the latter is the power flow to vehicle V j ), as well asf L, TOT (t), are, in the solution of the optimization problem, piece-wise constant. Obviously, this is a somewhat restrictive condition, but it is necessary if we want to deal with parametric (and not functional) optimization problems.
Finally, for the formalization of the optimization problem, it is necessary to introduce a set of binary variables to indicate whether, in a considered time interval, a certain vehicle is under charging or not. Namely, we define Then, the following constraints must be introduced in order to impose that when the power flow f L, i, j is greater than zero, the binary variable y i, j takes value 1. Note that K is the so called "big M" constant whose value is arbitrarily chosen provided that it is considerably higher with respect to the possible values of the variables and parameters appearing in the statement of the problem. Clearly, constraint (5) does not prevent that y i, j is 1 even when f L, i, j is equal to 0, and thus (5) does not seem to be equivalent to the definition of y i, j . However, in the statement of the optimization problem in the next section, we will introduce a cost term that prevents that in an optimal solution there is y i, j = 1 and f L, i, j = 0.
Besides it is necessary to impose that the charging process cannot start before the arrival time of a vehicle, that is, its release time. This is equivalent to imposing The above condition can be also stated as In this way, when C i < rl j , that is, when vehicle V j is not yet ready for service at the end of time interval (C i − 1 , C i ), (1 − y i + 1, j ) must be equal to 1, hence y i + 1, j must be equal to 0, and thus vehicle V j cannot be under charging in time interval (C i , C i + 1 ). Note that writing this constraint as in (7) prevents the possibility of starting the service for a vehicle immediately after it has become ready for service. In fact, a vehicle ready for service before time instant C i but later than that time instant C i − 1 , cannot be put under charging, according to (7) before C i , and thus has to wait for service even in the case that some socket is free before C i . This fact seems in some way to reduce the responsiveness of the management policy adopted for the whole system, but it is of some help in reducing the number of time intervals (and thus of the decision variables) considered in the formalization of the problem.
The requirement that the entire energy request ER j is satisfied for any vehicle V j is accomplished by introducing the constraints The dynamics of the state variable x S (t) [kWh] representing the energy contents of the storage element can be traced by the discrete event equation or even, more simply, where the initial state x S (C 0 ) = x S (0) = x S, 0 is known. In (9) f þ S;i and f − S;i are the "positive" and "negative" components of f S;i , namely and η disch , η charge are coefficients considering losses in discharging and charging of the storage element, respectively. In particular, η disch is a (fixed and known) parameter greater than 1, whereas η charge is a (fixed and known) positive parameter lower than 1. Note that (10) and (11) are written by implicitly assuming that when f S;i > 0, then f S (t) ≥ 0 for C i − 1 ≤ t ≤ C i (and when f S;i < 0, then f S (t) ≤ 0 for in the same time interval). This assumption may be not verified in practical conditions. However, it is likely to be verified for large values of f S;i More important, its removal would greatly increase the complexity of the problem statement, since this would require the computation of the integral in (3) over separate time intervals, whose number and lengths can hardly be expressed, owing to the fact that variables C i are indeed decision variables, whose values are determined by solving the optimization problem. Note that there is no need to impose explicitly the complementarity condition Having defined in the previous section the model of the system, we can now define the optimal scheduling problem concerning the vehicle charging.

Problem
subject to (2), (4), (5), (7), (8), (9), (10) and 0≤ f L;TOT ;i ≤ F L;TOT; where all the variables, apart from f G, i , f S;i , FGCOST i , i = 1, …, M, are constrained to be nonnegative. The decision variables in the above problem formulation are: , M, and f L, i, j , y i, j , i = 1, …, M, j = 1, …, M. Some comments are needed as regards the statement of the above problem. First, note that the cost function to be minimized takes into account both economic costs/ revenues due to buying/selling power from/to the grid, the overall tardiness cost (where tardiness is "weighted" by the amount of the recharging request), plus a cost term penalizing the occupation of the sockets. Namely, the constant β [€/h] represents the (fixed) occupation cost of a socket per unit time, and is considered as independent from the value of the power flow for the specific considered time interval. Note that the presence of the third term in the cost to be minimized in (12) ensures that no socket is engaged when the relevant power flow is zero. In this way, the possibility that y i, j is 1 when f L, i, j is equal to 0 is removed. This clarifies the observation made in Section 3 about this point.
The meaning of variables f þ G;i and f − G;i appearing in (13) and (14) is straightforward.
We assume (as it is reasonable) that BP(t) > SP(t), for any time instant t. This rules out the possibility of having both f þ G;i and f − G;i nonzero for the same value of index i, owing to the structure of the function (12) to be optimized. In fact, having in the same time interval the couple (f þ G;i , f − G;i ) with both terms nonzero (say, for instance, f þ G;i > f − G;i ) would provide a higher value of FGCOST i , with respect to the choice of the couple (f þ G;i − f − G;i , 0). Assuming that the function BP(t) and SP(t) are perfectly known for all the time horizon of interest, any term of type FGCOST i results (through the evaluation of the two definite integrals appearing in (13)) to be a function of decision variable C i and C i − 1 .
Inequalities (15)-(18) are introduced to take into account physical constraints on the power flows. Note that constraints (16) are written considering different lower bounds depending on i and j. In particular, it is assumed that F L, i, j, MIN = 0 if i ≠ j and F L, i, j, MIN = F L, low if i = j. In this way, we ensure that the vehicle V i completing its charging at C i receives at least a power flow F L, low during time interval (C i − 1 , C i ). Constraints (19) and (20) prevent the attainment of too low and too high values of the state of charge of the storage element. In particular, (20) makes use of a final minimum value that must be properly specified. Constraints (17) represents the integral version of constraints (16), because the upper bound limit on the overall power flow may be tighter than the sum of the upper bounds relevant to the charging process of the various vehicles.
Constraints (21) are introduced to prevent the presence of zero-length time intervals. Constraints (22) are introduced to impose that the number of vehicles simultaneously under charge does not exceed the value N that is characteristic of the charging station.
Constraints (23) are necessary to give significance to the term tard j appearing in (12). Actually, tard j is the tardiness of the charging service provided to vehicle V j and is defined as Indeed, constraints (23) are equivalent to this definition, since tard j in constrained to be nonnegative, and the structure of the cost to be minimized in (12) prevents that constraints (23) is satisfied by a strong inequality. It is worth observing that the statement of the above problem does not ensure that there are optimal solutions in which no vehicle is waiting for service in the presence of free sockets. In the terminology of scheduling theory, this means that there is no guarantee that an optimal "semi-active" schedule exists. This observation is justified considering that it could be convenient to shift the service for a vehicle to a time interval with a lower energy cost.
Finally, note that, in the formulation of the cost function to be minimized, no benefit arises from the sale of energy to customers (vehicles). This can be justified within two possible modeling frameworks. In the first one, it is assumed that the charging service cannot be refused by the provider and that the energy selling prices (to customers) are fixed. In the second one, the vehicles are considered as a property of the company providing the charging service.

Case study application
In this section, the proposed approach is applied to a real case study referring to a set of facilities located in the Savona municipality. The vehicle demand is relevant to 10 electrical vehicles (M = 10) to be charged in a grid-connected microgrid characterized by the presence of renewable power production, an electrical storage, and an EV charging station equipped with 3 sockets (N = 3).
The optimal schedule of storage systems and EV charging is obtained by solving the mixed integer nonlinear optimization problem introduced in the previous section using Lingo optimization tool on a PC Intel i7, 16 GB RAM.
First, let us provide, in Table 1, the values of the parameters of the elements of the microgrid for this case study.
A forecast of the renewable power production f R (t) is available over a whole day with a time discretization step equal to 15 min. To be able to express f R;i as a Using the MATLAB tool, the following values for the parameters of the above function are found (see Table 2). In Fig. 3 the original pattern of the renewable power production f R (t) is represented, as well as the interpolating curve. Clearly, other kinds of interpolating functions could have been used, but, in our opinion, the quality of the proposed approximation is acceptable.
In Fig. 4 the time varying buying price, as well as the fourth order polynomial interpolation, is represented (even in this case, of course, other interpolating functions could have been chosen). Then, the first term in Eq. (8) can be computed as functions of C i − 1 , C i by determining the definite integrals of the fourth order interpolating function shown in Fig. 4 and given by   Table 3. Instead the selling price is assumed to be constant and equal to 0.08 [€/kWh]. Table 4 reports the data for the considered Base Vehicle Dataset. Numbers represent time instants expressed in hours, starting from an initial time instant put equal to 0. The initial time instant corresponds to 9.00 and the available data for renewables and buying prices refer to a time horizon from 9.00 to 24.00.
We consider three Scenarios: & Scenario 1: Base Vehicle Dataset with variable energy prices (as previously specified) and no renewable power source; & Scenario 2: same as Scenario 1 but with renewable power source (as previously specified); & Scenario 3: same as Scenario 2 but with different values for due dates and energy requests.

Scenario 1
The results obtained, providing the optimal schedule, are reported in Table 4, 5 and represented in the following Figs. 5, 6 and 7. The state of charge (SOC i ) of the storage represents the variable x S, i of Eq. (9) normalized using the capacity of the storage (equal to 120 [kWh]).   . 6 The pattern representing the power bought/sold from/to the external grid in the optimal solution for Scenario 1 As it can be seen from Fig. 5, the variable buying prices and the distribution of the due dates (clustered in two blocks) lead to an optimal solution characterized by a time period, relevant to the central hours of the time horizon, where only one EV is under charging and two sockets are free. The power from the main grid (Fig. 6) reflects this behavior since it is bought in the first hours and then in the last part of the time horizon while in the middle is zero because the vehicle is charged by means of the storage (Fig. 7). Note also that the service for charging vehicle 7 is preempted (Fig. 5).

Scenario 2
The second scenario is equal to the first one, but for the introduction of renewables. The results obtained, providing the optimal schedule are reported in Table 6.
As in the previous case the following Figs. 8, 9 and 10 represent the obtained solution.
In this case, it is possible to denote that the scheduling is different with respect to the first scenario but the central part of the time horizon is still characterized by only one vehicle charging. This is due to the same reason already presented in Scenario 1. The main difference brought by the renewables mainly regards the exchange with the main grid which is lower since part of the balance is satisfied by the PV plant.

Scenario 3
In this scenario the Vehicle Dataset is the same as for Scenarios 1 and 2, but for the values of due dates and energy requests reported in Table 7.   Table 8 and Figs. 11, 12 and 13 represent the results obtained providing the optimal schedule.
As it can be observed from the above figures, the results obtained for Scenario 3 present significant differences with respect to Scenario 2 in the schedule and in the storage behavior. In fact, the variation of the schedule is induced by the new values of the energy requests and due dates. Namely, one can note the earlier completion of the service for vehicle 6, and the fact that in the central hours there is only one free socket. The storage behavior differs from the previous cases since it is discharged between 12.00 and 14.30 to sustain the anticipated service of vehicle 6.
The computational times and the values of the objective function are reported in Table 9. Overall, these results show that the model is compatible with real-time applications. Fig. 8 The Gantt diagram representing the optimal schedule Scenario 2. The charging intervals of the 10 vehicles are clearly represented by various colours Fig. 9 The pattern representing the power bought/sold from/to from the external grid in the optimal solution for Scenario 2 Fig. 10 The pattern representing the state of charge of the storage in the optimal solution for Scenario 2  . 11 The Gantt diagram representing the optimal schedule Scenario 3 As regards the numbers of variables and constraints we report the results of Scenario 2. The total number of variables is 295, 180 of them are nonlinear and 55 are binary. Focusing on the binary variables, their number is equal to ∑ M i¼1 i, since in any time interval (C i − 1 , C i ) at most M − i + 1 vehicles can be under charging. This reduction in the number of binary variables (with respect to the expected value M 2 ) is achieved by introducing in the problem formalization an additional ("technical") constraints, namely A comparison with respect to a discrete time formalization of the problem has been carried out. First, we have to note that the discrete time formalization differs from the discrete event one at least for the following reasons: Fig. 12 The pattern representing the power bought/sold from/to the external grid in the optimal solution for Scenario 3 Fig. 13 The pattern representing the state of charge of the storage in the optimal solution for Scenario 3 & in the discrete time formalization, there is no need for approximating the original patterns of the power coming from the renewable sources and the buying prices; & in the discrete time formalization, there is no need of imposing that the power flows to vehicles, from/to the storage element, and from/to the main grid are piecewise constant (that is, constant within a time interval larger than the discretization time interval, such as, for instance, the charging time interval for a vehicle).
On the counterpart, as it has been already pointed out, the discrete time formalization is affected by a very high number of decision variables as compared with the discrete event one.
To be more precise, we have considered a time discretization interval of 0.125 [h], i.e., 7.5 min. With this discretization interval, using the same software platform above mentioned, we have not been able to solve problem instances corresponding to 10 vehicles in reasonable computational times (after 1 h the program did not find any feasible solution).
To make a comparison between the two formalizations, we had to consider a problem instance with 3 vehicles and 1 socket. In this case, the values of the objective functions determined by solving the discrete time and the discrete event formalizations were different for some percent. Instead, the computational time for the discrete event case was 1 s, while the computational time for the discrete time case was over 5 min. More important, the number of binary variables for the discrete event formalization was 6, whereas in the discrete time formalization we had 363 binary variables! Additional scenarios obtained modifying Scenario 1 and considering 15 and 20 EVs have led to computational times of about 2.5 min and 6 min, respectively. Thus, although no extensive analysis has been carried out about this point, we can believe that the proposed approach is compatible with real-time application for problem instances whose size is greater with respect to the instances leading to the results represented in the previous pictures.
6 Vehicle-to-grid (V2G) extension In this section, we extend the above introduced model in order to allow vehicle-to-grid power flows. To this end, we must point out the differences with respect to the previously introduced model.
In this case, for each vehicle V j requiring service, besides to parameters dd j , dl j , rl j , α j the following information is available: & Initial state of the vehicle's battery, namely x init V; j ; & Desired final state, namely x fin V; j ; of course, the energy request is ER j ¼ x fin V; j −x init V; j .
Besides, even for the vehicle's battery, a couple of parameters υ disch, j and υ charge, j is assumed to be available. Such parameters have an analogous meaning with respect to the already introduced parameters η disch and η charge , referring to the main storage element. In this case, there is the necessity of considering the state equations for the energy contents of the various vehicles' batteries, that is Now the binary variables y i, j have the following meaning and constraints (5) must be replaced by in order to impose that, whenever there is a flow to/from vehicle V j , this vehicle must be connected to a socket. The requirement that the energy request must be totally satisfied may still be ensured by constraint (8), that could also be replaced by along with Note that Eq. (31) is written by assuming that, as regards V j , the V2G operation mode could be adopted only before the time instant C j . Observe that there is no constraint preventing the discharging of the battery of a vehicle even though it has already reached the desired energy value x fin V; j , provided that at the "final" time instant C j this value has been exactly reached.
Clearly, x V, MIN and x V, MAX are the lower and upper bounds of x V, i, j , respectively (the same for any vehicle). The value of x V, i, j is allowed to vary only in correspondence with time intervals (C i − 1 , C i ) for which C i − 1 ≥ rl i , according to (7).
The decision variables in the above problem formulation are: A case study has been considered for the V2G case. The values of the data related to each vehicle are reported in Table 10.
The values of the parameters are the same of Table 1 except for those reported in Table 11. Essentially the considered case study is the same as that in Scenario 2 in Section 5, but with the above Vehicle Dataset, and with the buying and selling prices corresponding to BP t ð Þ ¼ 0:15−0:0025 t SP t ð Þ ¼ 0:14−0:08 t where the prices are expressed in €/kWh and t is expressed in hours. Figure 14 represents the pattern (over time) of BP(t), SP(t) and f R (t). From these patterns one can infer that in the beginning of the time horizon (the hours immediately after 9.00 AM) it should be convenient to discharge the vehicles whose completion of service is not immediately requested. That is what is obtained by solving the above optimization problem for the considered instance. In fact, this is confirmed by Fig. 15 that shows the patterns of the power exchanged with the main grid, and the power flows from/to three vehicles (1, 9, 10). Table 12 reports the values of the completion times C i for the presented case study.   In this paper, a model to represent the charging of electric vehicles at a station with multiple sockets is presented, to define an optimization problem whose solution is compatible with real-time operations. To this end, a discrete event representation of the dynamics of the system has been adopted, to limit the number of variables to be determined. It has been assumed that the main decision variables of the problem, namely the power flows to the vehicles and the those from/to the main grid are kept constant within each time interval between two successive service completion time instants, referring to two different vehicles. This limitation seems to be not too restrictive and, in any case, it is necessary to allow the definition of a parameter optimization problem instead of a functional optimization one). The approach presented in this work refers to the optimization of the charging of a set of vehicles either already present at the charging station or whose arrival times are perfectly known, and thus it is intrinsically a finite horizon optimization problem.
Two different formalizations of the problem have been presented. In the first one, the power flow to vehicles is constrained to be monodirectional, whereas in the second one power flows from the vehicles are allowed (V2G). It is important to note that in both cases, for reasonable sizes of the problem instances, the computational times are compatible with a real-time application.
A limitation of the proposed model is the constraint relevant to the order of the sequence of the completion times, which is considered as fixed, owing to some priority order (given, for instance, by the order of the arrivals of the vehicles at the station). The removal of this constraint would allow considering even cases in which the arrival of a new vehicle, with some service urgency, may perturb the pre-existing service order.
This last issue is a matter of current research. Besides, a further research effort is needed if one wants to consider a periodic service demand, as, for instance, that required in public transportation. In this case, the scheduling problem should be solved by finding a schedule that can be iterated over time.
Another different formalization of the model could be that in which the arrivals of vehicles are represented as a stochastic process. In this case, the model would necessarily be of a stochastic type, and optimization over an infinite horizon should be sought.
However, remaining within the framework of deterministic models, like that considered in this paper, one could think of applying the decision model that has been developed by running again the model every time a new vehicle arrives. Of course, this would give rise to a sort of receding horizon (predictive) control scheme.
Funding Open access funding provided by Università degli Studi di Genova within the CRUI-CARE Agreement.

Appendix B
Additional nomenclature for the V2G model Parameters: x V, MAX = maximum energy level for the battery of a vehicle [kWh]; x V, MAX = minimum energy level for the battery of a vehicle [kWh]; x init V; j = initial energy level of the battery of vehicle V j [kWh]; x fin V; j = final energy level of the battery of vehicle V j [kWh]; υ charge, j , υ disch, j = loss coefficients affecting the behavior of the battery of vehicle V j [-].
Decision Variables: x V, i, j = energy level of the battery of vehicle V j at time instant C i [kWh]; f þ L;i; j =power flow to the vehicle V j in the time interval (C i − 1 , C i ) [kW]; f − L;i; j =power flow from the vehicle V j in the time interval (C i − 1 , C i ) [kW].
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.