1 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 (Ferro et al. 2019), 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.

2 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 day-ahead 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. 2018a, 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 (Zhang et al. 2018), 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 (Ferro et al. 2019), 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 (Ferro et al. 2019), 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 (Ferro et al. 2019), consisting of the possibility of power flows from the vehicles, that is, the so-called V2G model.

3 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).

Fig. 1
figure 1

Schematic representation of the charging station

The (monodirectional) power flow to the vehicle Vj is denoted with fL, j(t), j = 1, …, M (obviously fL, j(t) = 0 if Vj is not connected at time instant t). The total power flow provided to the charging station is fL, 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 fS(t). This flow is bi-directional, and, by convention, it is assumed to be positive when the power is drawn from the storage.

Similarly, fG(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, fR(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 Vj requiring charging service is characterized by the following parameters:

  • Release date (rlj), 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 (ddj), that is, the time instant at which the service should be completed [h];

  • Deadline (dlj), that is the time instant at which the service must be completed [h];

  • Energy request (ERj), 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 ddj) regarding the completion of the service, for a unit of energy requested; αj is expressed in \( \left[\frac{\text{\EUR}}{kWh\cdot h}\right] \).

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).

Fig. 2
figure 2

Time axis discretization

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 (Ci − 1, Ci), i = 1, …, M (let C0 = 0 by definition), define

  • fL, i, j= the constant power flow delivered for charging of vehicle Vj, j = i, i + 1, …, M;

  • fG, i= the constant power flow from/to the grid;

  • \( {f}_{L, TOT,i}=\sum \limits_{j=i}^M{f}_{L,i,j} \)= the (constant) total power flow delivered to vehicles.

Of course, at any time instant, the following power balance equation holds

$$ {f}_{L, TOT}(t)={f}_G(t)+{f}_S(t)+{f}_R(t) $$
(1)

where fL, 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),

$$ {f}_{L, TOT,i}={f}_{G,i}+{\overline{f}}_{S,i}+{\overline{f}}_{R,i}\kern0.5em i=1,\dots, M $$
(2)

where \( {\overline{f}}_{S,i} \) is defined as the average value of fS(t)in time interval (Ci − 1, C1) and \( {\overline{f}}_{R,i} \)has a similar meaning, namely

$$ {\overline{f}}_{S,i}=\frac{1}{C_i-{C}_{i-1}}\underset{C_{i-1}}{\overset{C_i}{\int }}{f}_S(t)\; dt\kern1em i=1,\dots, M $$
(3)
$$ {\overline{f}}_{R,i}=\frac{1}{C_i-{C}_{i-1}}\underset{C_{i-1}}{\overset{C_i}{\int }}{f}_R(t)\; dt\kern0.5em i=1,\dots, M $$
(4)

It is apparent that \( {\overline{f}}_{R,i} \) turns out to be a function of Ci − 1, Ci. 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 \( {\overline{f}}_{S,i} \), i = 1, …, M will be determined (and not, of course, the function fS(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 fS(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 \( {\overline{f}}_{S,i} \) are to be chosen in order to easily allow the fulfilment of the physical constraint on fS(t)for any time instant.

Besides, note that we have imposed that functions fG(t), fL, j(t) (the latter is the power flow to vehicle Vj), as well asfL, 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

$$ {y}_{i,j}=\left\{\begin{array}{l}1\kern0.5em \mathrm{if}\ \mathrm{vehicle}\ {V}_j\ \mathrm{is}\ \mathrm{under}\ \mathrm{charging}\ \mathrm{in}\ \mathrm{time}\ \mathrm{in}\mathrm{terval}\ \left({C}_{i-1},{C}_i\right)\\ {}\begin{array}{cc}& \end{array}\\ {}\begin{array}{ccc}0& \mathrm{otherwise}& \begin{array}{cccc}& & & \begin{array}{c}\\ {}\mathrm{for}\ i=1,\dots, M,j=1,\dots, M\end{array}\end{array}\end{array}\end{array}\right. $$

Then, the following constraints must be introduced

$$ {y}_{i,j}\cdot K-{f}_{L,i,j}\ge 0\kern0.5em i=1,\dots, M,j=1,\dots, M $$
(5)

in order to impose that when the power flow fL, i, j is greater than zero, the binary variable yi, 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 yi, j is 1 even when fL, i, j is equal to 0, and thus (5) does not seem to be equivalent to the definition of yi, 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 yi, j = 1 and fL, 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

$$ {\displaystyle \begin{array}{cc}\begin{array}{cc}{y}_{i+1,j}=0& \mathrm{if}\end{array}& {rl}_j>{C}_i\end{array}}\kern0.5em i=0,\dots, M-1,j=1,\dots, M $$
(6)

The above condition can be also stated as

$$ \left(1-{y}_{i+1,j}\right)\kern0.24em K-\left({rl}_j-{C}_i\right)\ge 0\kern0.5em i=0,\dots, M-1,j=1,\dots, M $$
(7)

In this way, when Ci < rlj, that is, when vehicle Vj is not yet ready for service at the end of time interval (Ci − 1, Ci), (1 − yi + 1, j) must be equal to 1, hence yi + 1, j must be equal to 0, and thus vehicle Vj cannot be under charging in time interval (Ci, Ci + 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 Ci but later than that time instant Ci − 1, cannot be put under charging, according to (7) before Ci, and thus has to wait for service even in the case that some socket is free before Ci. 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 ERj is satisfied for any vehicle Vj is accomplished by introducing the constraints

$$ \sum \limits_{i=1}^j{f}_{L,i,j}\left({C}_i-{C}_{i-1}\right)={ER}_j\kern0.5em j=1,\dots, M $$
(8)

The dynamics of the state variable xS(t) [kWh] representing the energy contents of the storage element can be traced by the discrete event equation

$$ {x}_S\left({C}_i\right)={x}_S\left({C}_{i-1}\right)-{\eta}_{disch}{\overline{f}}_{S,i}^{+}\left({C}_i-{C}_{i-1}\right)+{\eta}_{charge}{\overline{f}}_{S,i}^{-}\left({C}_i-{C}_{i-1}\right)\kern0.5em j=1,\dots, M $$

or even, more simply,

$$ {x}_{S,i}={x}_{S,i-1}-{\eta}_{disch}{\overline{f}}_{S,i}^{+}\left({C}_i-{C}_{i-1}\right)+{\eta}_{charge}{\overline{f}}_{S,i}^{-}\left({C}_i-{C}_{i-1}\right)\kern0.5em j=1,\dots, M $$
(9)

where the initial state xS(C0) = xS(0) = xS, 0 is known. In (9) \( {\overline{f}}_{S,i}^{+} \) and \( {\overline{f}}_{S,i}^{-} \) are the “positive” and “negative” components of \( {\overline{f}}_{S,i} \), namely

$$ {\overline{f}}_{S,i}={\overline{f}}_{S,i}^{+}-{\overline{f}}_{S,i}^{-}\kern0.5em i=1,\dots, M $$
(10)
$$ {\overline{f}}_{S,i}^{+},{\overline{f}}_{S,i}^{-}\ge 0\kern0.5em i=1,\dots, M $$
(11)

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 \( {\overline{f}}_{S,i}>0 \), then fS(t) ≥ 0 for Ci − 1 ≤ t ≤ Ci (and when \( {\overline{f}}_{S,i}<0 \), then fS(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 \( \left|{\overline{f}}_{S,i}\right| \) 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 Ci 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 \( {\overline{f}}_{S,i}^{+}\cdotp {\overline{f}}_{S,i}^{-}=0 \), since, owing to (9), a pair \( \left({\overline{f}}_{S,i}^{+},{\overline{f}}_{S,i}^{-}\right) \) with both variables greater than zero may be replaced by a pair with at least one variable equal to zero, that allows the same behavior for the system but reduces the energy losses.

Summing up, the assumptions that characterize the present model are:

  • the arrival times (release dates) of all vehicles are perfectly known and no stochastic behavior is modeled;

  • the power flows fG (t) and fL, j (t) are kept constant during any time interval (Ci − 1, Ci);

  • the sign of the average power flow \( {\overline{f}}_{S,i} \) is taken as representative of the direction of the power flow fS(t) during the whole time interval (Ci − 1, Ci).

4 The optimization problem

Having defined in the previous section the model of the system, we can now define the optimal scheduling problem concerning the vehicle charging.

4.1 Problem – Optimal scheduling of vehicle charging

$$ \min \sum \limits_{i=1}^M\left\{{FGCOST}_i+{\alpha}_i\cdot {tard}_i\cdot \right.\left.{ER}_i+\sum \limits_{j=1}^M\beta \cdot {y}_{i,j}\cdot \left({C}_i-{C}_{i-1}\right)\right\} $$
(12)

subject to (2), (4), (5), (7), (8), (9), (10) and

$$ {FGCOST}_i=\left\{\left[\underset{C_{i-1}}{\overset{C_i}{\int }} BP(t) dt\right]{f}_{G,i}^{+}-\left[\underset{C_{i-1}}{\overset{C_i}{\int }} SP(t) dt\right]{f}_{G,i}^{-}\right\}\kern0.5em i=1,\dots, M $$
(13)
$$ {f}_{G,i}={f}_{G,i}^{+}-{f}_{G,i}^{-}\kern0.5em i=1,\dots, M $$
(14)
$$ -{F}_{G,\mathit{\operatorname{MAX}}}\le {f}_{G,i}\le {F}_{G,\mathit{\operatorname{MAX}}}\kern0.5em i=1,\dots, M $$
(15)
$$ {F}_{L,i,j,\mathit{\operatorname{MIN}}}\le {f}_{L,i,j}\le {F}_{L,\mathit{\operatorname{MAX}}}\kern0.5em i=1,\dots, M,j=i,\dots, M $$
(16)
$$ 0\le {f}_{L, TOT,i}\le {F}_{L, TOT,\mathit{\operatorname{MAX}}}\kern0.5em i=1,\dots, M $$
(17)
$$ -{F}_{S,\mathit{\operatorname{MAX}}}\le {\overline{f}}_{S,i}\le {F}_{S,\mathit{\operatorname{MAX}}}\kern0.5em i=1,\dots, M $$
(18)
$$ {x}_{S,\mathit{\operatorname{MIN}}}\le {x}_{S,i}\le {x}_{S,\mathit{\operatorname{MAX}}}\kern0.5em i=1,\dots, M-1 $$
(19)
$$ {x}_{S, MINFIN}\le {x}_{S,M}\le {x}_{S,\mathit{\operatorname{MAX}}} $$
(20)
$$ {C}_i\ge {C}_{i-1}+\varepsilon \kern0.5em i=1,\dots, M $$
(21)
$$ \sum \limits_{j=1}^M{y}_{i,j}\le N\kern0.5em i=1,\dots, M $$
(22)
$$ {tard}_j\ge {C}_j-{dd}_j\kern0.5em j=1,\dots, M $$
(23)
$$ {C}_j\le {dl}_j\kern0.5em j=1,\dots, M $$
(24)
$$ {f}_{L, TOT,i}=\sum \limits_{j=i}^M{f}_{L,i,j}\kern0.5em i=1,\dots, M $$
(25)

where all the variables, apart from fG, i, \( {\overline{f}}_{S,i} \), FGCOSTi, i = 1, …, M, are constrained to be nonnegative.

The decision variables in the above problem formulation are: Ci, fG, i, fL, TOT, i, \( {\overline{f}}_{S,i} \), \( {\overline{f}}_{R,i} \), FGCOSTi, \( {f}_{G,i}^{+} \), \( {f}_{G,i}^{-} \), xS, i, tardi, i = 1, …, M, and fL, i, j, yi, 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 yi, j is 1 when fL, 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. Namely, \( \kern0.5em {f}_{G,i}^{+}=\max \left\{{f}_{G,i},0\right\} \) and \( \kern0.5em {f}_{G,i}^{-}=\max \left\{-{f}_{G,i},0\right\} \). 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 non-zero (say, for instance, \( {f}_{G,i}^{+}>{f}_{G,i}^{-} \)) would provide a higher value of FGCOSTi, 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 FGCOSTi results (through the evaluation of the two definite integrals appearing in (13)) to be a function of decision variable Ci and Ci − 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 FL, i, j, MIN = 0 if i ≠ j and FL, i, j, MIN = FL, low if i = j. In this way, we ensure that the vehicle Vi completing its charging at Ci receives at least a power flow FL, low during time interval (Ci − 1, Ci). 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 tardj appearing in (12). Actually, tardj is the tardiness of the charging service provided to vehicle Vj and is defined as

$$ {tard}_j=\max \left\{{C}_j-{dd}_j,0\right\} $$

Indeed, constraints (23) are equivalent to this definition, since tardj 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.

5 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.

Table 1 System Parameters

A forecast of the renewable power production fR(t) is available over a whole day with a time discretization step equal to 15 min. To be able to express \( {\overline{f}}_{R,i} \) as a function of Ci − 1 andCi, we have chosen to interpolate the available forecasts via a seventh order polynomial function

$$ {f}_R(t)={a}_7^l{t}^7+{a}_6^l{t}^6+{a}_5^l{t}^5+{a}_4^l{t}^4+{a}_3^l{t}^3+{a}_2^l{t}^2+{a}_1^lt+{a}_0^l $$

Using the MATLAB tool, the following values for the parameters of the above function are found (see Table 2).

Table 2 Polynomial Approximation Parameters of Power Production from RES

In Fig. 3 the original pattern of the renewable power production fR(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.

Fig. 3
figure 3

PV power production function and its polynomial approximation

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 Ci − 1, Ci by determining the definite integrals of the fourth order interpolating function shown in Fig. 4 and given by

$$ fp(t)={a}_4^p{t}^4+{a}_3^p{t}^3+{a}_2^p{t}^2+{a}_1^pt+{a}_0^p $$
Fig. 4
figure 4

The time-varying buying price and its polynomial approximation

The coefficients of the interpolating function are reported in Table 3.

Table 3 Parameters of the time-varying energy buying price polynomial approximation

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.

Table 4 The Parameters of the Base Vehicle Dataset

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.

5.1 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 (SOCi) of the storage represents the variable xS, i of Eq. (9) normalized using the capacity of the storage (equal to 120 [kWh]).

Table 5 The results corresponding to the optimal schedule for Scenario 1
Fig. 5
figure 5

The Gantt diagram representing the optimal schedule Scenario1. The charging intervals of the 10 vehicles are clearly represented by various colors

Fig. 6
figure 6

The pattern representing the power bought/sold from/to the external grid in the optimal solution for Scenario 1

Fig. 7
figure 7

The pattern representing the state of charge of the storage 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).

5.2 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.

Table 6 The results corresponding to the optimal schedule for Scenario 2

As in the previous case the following Figs. 8, 9 and 10 represent the obtained solution.

Fig. 8
figure 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
figure 9

The pattern representing the power bought/sold from/to from the external grid in the optimal solution for Scenario 2

Fig. 10
figure 10

The pattern representing the state of charge of the storage in the optimal solution for Scenario 2

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.

5.3 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 7 Values of due dates and energy requests in Scenario 3

Table 8 and Figs. 11, 12 and 13 represent the results obtained providing the optimal schedule.

Table 8 The results corresponding to the optimal schedule for Scenario 3
Fig. 11
figure 11

The Gantt diagram representing the optimal schedule Scenario 3

Fig. 12
figure 12

The pattern representing the power bought/sold from/to the external grid in the optimal solution for Scenario 3

Fig. 13
figure 13

The pattern representing the state of charge of the storage in the optimal solution for Scenario 3

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.

Table 9 Run time and objective function results of the three scenarios

Overall, these results show that the model is compatible with real-time applications.

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 \( \sum \limits_{i=1}^Mi \), since in any time interval (Ci − 1, Ci) at most M − i + 1 vehicles can be under charging. This reduction in the number of binary variables (with respect to the expected value M2) is achieved by introducing in the problem formalization an additional (“technical”) constraints, namely

$$ {y}_{i,j}=0\kern0.5em i=1,\dots, M,j<i $$

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:

  • 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 Vj requiring service, besides to parameters ddj, dlj, rlj, αj the following information is available:

  • Initial state of the vehicle’s battery, namely \( {x}_{V,j}^{init} \);

  • Desired final state, namely \( {x}_{V,j}^{fin} \); of course, the energy request is \( {ER}_j={x}_{V,j}^{fin}-{x}_{V,j}^{init} \).

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

$$ {x}_{V,i,j}={x}_{V,i-1,j}+{\upsilon}_{charge,j}\;{f}_{L,i,j}^{+}\left({C}_i-{C}_{i-1}\right)-{\upsilon}_{disch,j}\;{f}_{L,i,j}^{-}\left({C}_i-{C}_{i-1}\right)\kern0.5em j=1,\dots, M,i=1,\dots, j $$
(26)

where

  • \( {x}_{V,0,j}={x}_{V,j}^{init}; \)

  • xV, i, j= state of the battery of vehicle Vj at time instant Ci;

  • \( {f}_{L,i,j}^{+} \) and \( {f}_{L,i,j}^{-} \) are positive and negative components of fL, i, j, namely

$$ {f}_{L,i,j}={f}_{L,i,j}^{+}-{f}_{L,i,j}^{-}\kern0.5em j=1,\dots, M,i=1,\dots, j $$
(27)
$$ {f}_{L,i,j}^{+},{f}_{L,i,j}^{-}\ge 0\kern0.5em j=1,\dots, M,i=1,\dots, j $$
(28)

Now the binary variables yi, j have the following meaning

$$ {y}_{i,j}={\left\{{}_0^1\right.}_{\mathrm{otherwise}}^{\mathrm{if}\ \mathrm{vehicle}\ {V}_j\ \mathrm{is}\ \mathrm{either}\ \mathrm{under}\ \mathrm{charging}\ \mathrm{or}\ \mathrm{discharging}\ \mathrm{in}\ \mathrm{time}\ \mathrm{in}\mathrm{terval}\ \left({C}_{i-1},{C}_i\right)} $$
$$ j=1,\dots, M,i=1,\dots, j $$

and constraints (5) must be replaced by

$$ {y}_{i,j}\;K-{f}_{L,i,j}^{+}\ge 0\kern0.5em j=1,\dots, M,i=1,\dots, j $$
(29)
$$ {y}_{i,j}\;K-{f}_{L,i,j}^{-}\ge 0\kern0.5em j=1,\dots, M,i=1,\dots, j $$
(30)

in order to impose that, whenever there is a flow to/from vehicle Vj, 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

$$ {x}_{V,j}^{init}+\sum \limits_{i=1}^j{f}_{L,i,j}\left({C}_i-{C}_{i-1}\right)={x}_{V,j}^{fin}\kern0.5em j=1,\dots, M $$
(31)

along with

$$ {x}_{V,\mathit{\operatorname{MIN}}}\le {x}_{V,i,j}\le {x}_{V,\mathit{\operatorname{MAX}}}\kern0.62em i=1,\dots, M,j=1,\dots, M $$
(32)

Note that Eq. (31) is written by assuming that, as regards Vj, the V2G operation mode could be adopted only before the time instant Cj. 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}_{V,j}^{fin} \), provided that at the “final” time instant Cj this value has been exactly reached. Clearly, xV, MIN and xV, MAX are the lower and upper bounds of xV, i, j, respectively (the same for any vehicle).

The value of xV, i, j is allowed to vary only in correspondence with time intervals (Ci − 1, Ci) for which Ci − 1 ≥ rli, according to (7).

Besides, constraints (16) and (17) must be substituted by

$$ -{F}_{L,j,\mathit{\operatorname{MAX}}}\le {f}_{L,i,j}\le {F}_{L,j,\mathit{\operatorname{MAX}}}\kern0.5em i=1,\dots, M\kern0.5em j=i,\dots, M $$
(33)
$$ -{F}_{L, TOT,\mathit{\operatorname{MAX}}}\le {f}_{L, TOT,i}\le {F}_{L, TOT,\mathit{\operatorname{MAX}}}\kern0.5em i=1,\dots, M $$
(34)

since now the power flow to the vehicles may be positive or negative.

Then, the optimization problem to be considered in the case in which V2G operation mode is allowed consists still in the minimization in (12) subject to (2), (4), (7), (9)÷(11), (13)÷(15), (18)÷(34). All variables, apart from fG, i, \( {\overline{f}}_{S,i} \), FGCOSTi,fL, TOT, i i = 1, …, M and fL, i, j, i = 1, …, M, j = 1, …, M are constrained to be non-negative.

The decision variables in the above problem formulation are: Ci, fG, i, fL, TOT, i, \( {\overline{f}}_{S,i} \), \( {\overline{f}}_{R,i} \), FGCOSTi, \( {f}_{G,i}^{+} \), \( {f}_{G,i}^{-} \), xS, i, tardi, i = 1, …, M, and fL, i, j, yi, j, xV, i, j, \( {f}_{L,i,j}^{+} \), \( {f}_{L,i,j}^{-} \), i = 1, …, M, j = 1, …, M.

A case study has been considered for the V2G case. The values of the data related to each vehicle are reported in Table 10.

Table 10 V2G Extension: Data relevant to the EVs

The values of the parameters are the same of Table 1 except for those reported in Table 11.

Table 11 V2G Extension: Values of the additional parameters

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

$$ {\displaystyle \begin{array}{c} BP\;(t)=0.15-0.0025\;t\\ {} SP\;(t)=0.14-0.08\;t\end{array}} $$

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 fR(t).

Fig. 14
figure 14

V2G extension: Pattern of BP(t), SP(t) and fR(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).

Fig. 15
figure 15

V2G extension: Power exchange with the main grid and power exchange for vehicles 1, 9, and 10

Table 12 reports the values of the completion times Ci for the presented case study.

Table 12 V2G extension: Completion time results

7 Conclusions and future developments

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.