Optimal Management of Energy Communities Hosting a Fleet of Electric Vehicles

: In this paper, we study the problem of managing an energy community hosting a ﬂeet of electric vehicles for rent. On the day ahead, service requests for electric vehicles are submitted to the community. Then, the optimal request-to-vehicle assignment has to be found, as well as the optimal charging schedule of vehicle batteries. A suitable model is presented and included in an existing energy community architecture. The overall community management problem is formulated as a bi-level model, featuring two nested optimization problems. The optimal request-to-vehicle assignment requires the solution of a mixed-integer linear program. To reduce the computational complexity, a heuristic solution to the assignment problem is presented. Numerical results show that participation in the community grants a remarkable reduction in the electric vehicle charging cost. The adoption of the heuristic assignment solution provides a dramatic reduction in the computation time required to solve the bi-level model. At the same time, the level of suboptimality introduced appears to be negligible, being less than 1% in most of the considered cases.


Introduction
Energy communities are social aggregations of entities, that exchange energy among themselves through the public grid they are connected to. The single entities may engage in generation (especially from renewable energy sources), consumption, and energy storage, as well as provide energy services to other community members or the public grid. Participation of entities in an energy community is voluntary and open. To solicit this participation, the primary purpose of energy communities is to provide environmental, economic, or social benefits to its members or shareholders [1]. This process can also be favored by existing social relationships [2]. Several pilot studies carried out worldwide have shown that aggregation is actually capable of generating benefits of different types (see, e.g., [3,4]).
The constitution of, as well as incentives granted to, energy communities are regulated by national or local laws [5], whereas each energy community may typically decide the internal mechanisms governing its operation. Indeed, an energy community is based on a physical layer, whose components (loads, distributed energy resources, energy storage systems, electric vehicles) should be suitably coordinated, managed, and controlled to fully exploit all the benefits of aggregation.
In the literature, energy volumes to be exchanged within a community are often obtained together with energy prices by clearing a suitably designed local energy market. Local energy markets can be organized either in a centralized or peer-to-peer fashion (see [6] for a comprehensive review). The centralized solution is typically based on a community operator, who manages trading activities inside the community, as well as plays the role of intermediator between the community and the rest of the system [7][8][9]. In peer-to-peer market design, entities directly negotiate with each other, achieving consensus on an energy transaction for a certain amount of energy and a price without centralized supervision [10][11][12]. The mechanism governing the operation of a community may also include a strategy to redistribute community benefits among the members [7].
Besides energy exchange among its members, energy communities may also engage in providing flexibility and services to the grid, e.g., through enrollment in demand response programs and the provision of reserves. Another option, as explicitly highlighted in [1], is to provide charging services for electric vehicles (EVs). Given the increasing penetration of EVs in the transportation sector [13], this option is expected to become more and more concrete, and bring benefits at different levels. Indeed, mass adoption of EVs is known to have a number of impacts on distribution grid operation and management [14,15]. One of these is the high peak power consumption determined by the simultaneous charging of a large number of EVs [16]. In this respect, EV charging within energy communities could help reduce peak power thanks to the overall optimization performed at the community level. Moreover, including EVs in energy communities could provide additional flexibility to enable the integration of renewable energy into existing power grids. At the user level, social and economic benefits are expected because the energy for EV charging can be bought at cheaper prices resulting from the internal market of the community [7]. To achieve the expected benefits, EV charging has to be suitably scheduled and optimized. The management of EV charging stations connected to distribution grids has been addressed in numerous contributions, see, e.g, [17][18][19][20][21][22]. However, to the best of the authors' knowledge, the optimal integration of a fleet of EVs into energy communities has received little attention so far. The energy management system for a public EV charging station integrated within a community microgrid is proposed in [23]. The aim is to minimize the cost of energy for EV charging and to meet the community demand while maximizing the revenue from selling the surplus energy of a photovoltaic (PV) system and the energy discharged from EVs. The scheduling of a community-integrated energy system with an EV charging station is considered in [24]. Here, an integrated demand response program is designed to promote a balance between energy supply and demand. In both contributions, the resulting problems are formulated in the framework of mixed integer programming.
In this paper, we extend the energy community architecture proposed in [7], by introducing a new entity that manages a fleet of EVs for rent. A local market based on the marginal pricing scheme is organized at a centralized level. The market aims at maximizing the social welfare of the community. This is performed by defining energy prices and volumes to achieve a more efficient allocation of resources, a reduction in the peak, and an increased amount of reserve at the community level. Since we focus on a setup where EV rental requests are submitted to the community one day ahead, two additional problems must be addressed. First, each rental request must be assigned to a vehicle. Then, the optimal EV charging scheduling must be found. A community operator is assumed to manage the market and to redistribute the community benefits among the entities, in such a way that the solution achieved by each entity within the community is not worse than that obtained by acting individually. Different from [7], where the clearing of the local market is formulated as a linear program, in this work the request-to-vehicle assignment requires the introduction of binary variables, which makes the local market optimization problem a mixed-integer linear program (MILP). To avoid the high worst-case computational complexity of solving the MILP (as could be faced in practice, when the numbers of EVs and requests increase), a heuristic procedure is proposed to solve the assignment problem, based only on the set of the received requests. Once the assignment of requests to vehicles has been fixed, the local market optimization problem becomes again a linear program, that can be efficiently solved. Numerical results presented in the paper show that the proposed heuristics has a very cheap cost in terms of computation time, and performs very well in instances for which the MILP can be solved at the optimum, thus making it possible to compare the solution of the heuristics with the optimal one.
The paper is organized as follows. Section 2 reviews the problems formulated in [7] for the clearing of the local market, and the redistribution of community benefits. The two problems are presented in a unified fashion in the form of a bi-level program. Section 3 shows how to include a fleet of EVs for rent in the framework previously introduced. The proposed heuristic solution to the request-to-vehicle assignment is described in Section 4.
Numerical results are reported in Section 5 and discussed in Section 6. Finally, Section 7 draws the conclusions.
Notation: The subscript t is used to denote a discrete time instant within the considered time horizon T = {1, . . . , T}. The time between two consecutive time instants is denoted by ∆. The subscript u is used to denote an entity in the entity set U . The subscript d denotes an EV in the vehicle set D. Finally, the subscript h is used to denote an EV service request in the request set H.

Energy Community Model
An energy community is a collection of entities located in the same geographical area that pool their resources using the public distribution network. Entities can be very heterogeneous, ranging from residential customers to small and medium-sized enterprises. In general, an entity is characterized by a number of different components that may include one or more loads (sheddable or non-sheddable), generators (steerable or non-steerable), electrical storage systems and EV charging stations. The members of a community exchange electricity between them, share energy storage systems and provide services to the external grid. An energy community may bring several benefits, such as energy cost savings, peak cost reduction and provision of reserve on an aggregate basis.
While it is assumed that the entities are connected to the same local bus, the energy community provides a virtual layer over which entities may exchange energy flows (see Figure 1). Denote by e gri u,t ≥ 0 and i gri u,t ≥ 0 the energy exported to and imported from the grid by entity u at time t. Moreover, let e com u,t ≥ 0 and i com u,t ≥ 0 be the energy exported to and imported from the community by entity u at time t. Then, the net energy flowing from entity u to the local bus amounts to (e gri u,t + e com u,t ) − (i gri u,t + i com u,t ). Since the energy balance at the community level implies ∑ u∈U (i com u,t − e com u,t ) = 0, the net energy flowing from the grid to the local bus is ∑ u∈U (i  It is assumed that the energy flows with the external grid are subject to the same pricing mechanism as if the entities were not part of a community. Conversely, the peak power penalty is applied to the aggregate net power flow, and the provision of the reserve to the grid is remunerated at the community level, depending on the aggregate amount of power reserve provided. A community operator coordinates the behavior of the entities in order to maximize the benefits for the community. On the day ahead, the operator collects the load and generation profiles of each entity, as well as their flexibility, and schedules the operation of the devices based on the prices of the electricity imported from or exported to the grid. For the remuneration of this activity, the entities pay a fee to the operator, which is assumed to be proportional to the aggregate amount of energy exchanged within the community, i.e., it is equal to γ com ∑ ∀u∈U ∑ ∀t∈T (e com u,t + i com u,t ), where γ com [e/kWh] is a given unitary price. In [7], an optimization model was proposed to solve the problems that the community operator has to face. In the following, such a model is briefly reviewed. For the sake of exposition, the mathematical details are skipped and the interested reader is referred to [7] for an exhaustive description. In Section 3, it will be shown how to extend this model so as to include the management of a fleet of EVs for rent.
The community operator has to determine the energy flows among the entities and the corresponding prices (i.e., the operator has to clear the market), and then it has to share the profits among the community members. These tasks can be simultaneously formulated as a bi-level model, which is a mathematical program composed of two nested optimization problems, termed upper and lower level [25]. In general, a bi-level model can be written as where F and f are the objective functions of the upper and lower level problems (1) and (2), respectively. In the framework considered in [7], the lower-level problem models the market clearing task, while the upper-level problem takes care of profit redistribution. In the following, we outline the main features of both problems.

Lower Level Problem
The objective function f (y; x) of problem (2) represents the social welfare of the community over a given time horizon T . It is composed of three terms: The term f E (y) accounts for costs and revenues related to the energy flows. Among others, they include the costs of energy purchased from the grid or from the community, the costs of shed demand and steered generation, the costs of storage usage and the fees paid to the community operator. The revenues come from selling energy to the grid or to other community members. The term f R (y) represents the revenues collected by the community for providing symmetric reserve to the grid. It is assumed that the revenue is proportional to the aggregate reserve r sym provided by the community, i.e., it is equal to π res r sym , where π res [e/kW] is a given reserve price. The term f P (y) corresponds to the loss incurred by the community for the peak power p consumed by the community from the grid over the time horizon T , and it is equal to −π peak p, where π peak [e/kW] is the peak price. The vector of the optimization variables y ∈ Y includes the energy volumes exchanged by each entity and the charging/discharging profiles of the storage devices. The feasible set Y is used to enforce technical constraints on the optimization variables (e.g., maximum steerable generation, maximum capacity of a storage system, etc.), as well as to model the storage dynamics and to guarantee the energy balance for each entity at all times. In [7], it is shown that the lower level problem (2) can be cast as a linear program and thus efficiently solved. Moreover, according to the marginal pricing framework [26], the dual variables of the energy balance constraints represent the optimal purchase/selling prices of the energy traded within the community.

Upper Level Problem
The purpose of problem (1) is to share the community profit among the entities according to a given redistribution policy. A possible choice is to maximize the smallest (absolute or relative) profit increase that the entities experience when participating in the community. The objective function F(x, y * ) naturally reflects the chosen policy. The optimization variables x include the fraction of revenues from reserve provision and peak costs that are ascribed to each entity, as well as slack variables instrumental to encoding the redistribution policy in the objective function. The feasible set X ensures that no entity is penalized compared to acting individually. In particular, this means that when participating in the community, the profit of each entity cannot be less than the profit the entity would achieve by acting individually. (1) and (2), the optimizer y * and the feasible set Y of the lower level depend, in general, on the optimization variables x of the upper level. In turn, the feasible set X of the upper level may depend on y * . However, in the considered application, the lower level problem (2) is a linear program that does not depend on x, i.e. f (y; x) = f (y), see (3). Moreover, for a given solution y * of the lower level problem, the upper level is also a linear program. As a consequence, problem (1) and (2) can be efficiently solved as the cascade of two linear programs, one corresponding to the lower level, and the other corresponding to the upper level. A discussion about possible solution strategies can be found in [7].

EV Charging Management
In this section, we show how to include an entity hosting a fleet of EVs in the energy community model previously introduced. To this aim, we first present a model of such an entity and then describe how to modify the upper and lower level problems (1) and (2) accordingly.

EV Rental Service Model
For the sake of exposition, we assume that one entity of the community is hosting |D| vehicles, i.e., this entity does not have any other kind of load, generation or storage systems other than the vehicles. The considered scenario is that of an entity that runs a fleet of EVs for rent. On the day ahead, a customer submits a request h to the entity, by specifying the departure time t l h , the return time t r h and the expected amount of energy E h consumed for the vehicle usage. The first problem the entity has to face is to decide which vehicle to assign to each request (vehicle assignment problem). For the sake of exposition, we assume that EV requests are such that there always exists a feasible assignment. An optimal charging schedule for the vehicles should be found. In order to come up with a solution that is optimal at the community level, we assume that the vehicle requests are forwarded to the community operator that returns the optimal vehicle assignment and charging schedule as a result of the social welfare maximization problem (2). Let us define the following request parameters In (4), σ h,t and ω h,t are equal to one only when the time index t coincides with the return and departure times of request h, respectively. On the other hand, δ h,t in (5) is equal to one if request h is active at time t. Concerning the assignment problem, it can be formulated by introducing the following set of constraints where the variable z h,d is such that z h,d = 1 if and only if request h is assigned to vehicle d.
Clearly, each request must be fulfilled by exactly one vehicle and a vehicle cannot serve more than one request at the same time instant. These two conditions are imposed by constraints (7) and (8), respectively. In order to model the dynamics of the EV batteries, let s d,t denote the battery energy level of vehicle d at time t, and by a d,t the fraction of the power rating P d that the battery of vehicle d consumes at time t. Then, for each d ∈ D, the battery level satisfies In (9), the parameter η d represents the battery charging efficiency of vehicle d. Moreover, if vehicle d is fulfilling request h, its battery level is reduced by E h when the vehicle returns to the entity (at time t r h ). In (10) the battery level of each EV at the initial and final time is set. For the sake of simplicity, we are imposing that the EV batteries are filled up to the maximum level S d at the beginning and at the end of the considered time horizon, but different choices can be made. Clearly, both the battery level and the charging rate must be within the limits enforced by (11). Finally, it must be noted that a vehicle cannot be charged while fulfilling a request (so that a d,t must be zero during the request period). Moreover, if a vehicle is assigned to a request h, then its battery level at departure time t l h must be not less than the energy E h required by the request. These constraints can be written as The fleet of EVs contributes to the power reserve that the community provides to the grid. If we assume no vehicle-to-grid power injection, each EV can provide only a downward reserve when charging (i.e., it can increase the power consumed from the grid if needed). The maximum power increase is dictated by the residual battery capacity, as well as by the current and the maximum charging rate. Clearly, when a vehicle is fulfilling a service request, it cannot provide any reserve. Hence, the downward reserve r d,t ≥ 0 provided by vehicle d at time t must satisfy the following constraints

Lower Level Problem
We can now summarize the modifications to problem (2) that are required to include the entity hosting the fleet of EVs. In the following, let v ∈ U be the index of such an entity in the entity set U .
Concerning the objective function f (y; x) in (3), the quantity f E (y) includes an additional term −π igr t i gri v,t − γ com i com v,t representing the energy cost and the contribution of the EV fleet to the community operator fee, where π igr t is the price of the energy imported from the grid at time t. The revenue f R (y) coming from reserve provision and the cost f P (y) related to peak power is modeled by means of the slack variables r sym and p, respectively. Hence, the contribution to reserve and peak power boils down to modifying existing constraints that define the set Y in (2) with the following ones where r − u,t in (17) is the amount of downward reserve that entity u can provide at time t, whereas the sum in (18) would be the community peak power at time t without the fleet of EVs.
There are two kinds of additional optimization variables that need to be included in the vector y in (2). First, the entity hosting the fleet of EVs requires a set of variables common to all other entities, namely the energy flows imported from the grid or the community (i gri v,t , i com v,t ) and the downward reserve r d,t provided by each EV. Conversely, the new variables which are specific to the rental requests and the EVs are the binary assignment variables z h,d , the EV battery levels s d,t and the EV charging rates a d,t .
Concerning the new constraints defining the feasible set Y in (2), besides (6)-(16), the energy balance at entity v must be added, as follows

Upper Level Problem
The purpose of the upper-level problem (2) is to redistribute the community profit among the entities. In this paper, the adopted redistribution policy aims at maximizing the smallest relative profit increase in the entities. This choice is slightly different from what was performed in [7], where the smallest absolute profit increase was considered. Let J * = f (y * ) be the optimal profit of problem (2). Denote by J u the profit of entity u ∈ U when participating in the community. Clearly, The underlying idea is to decompose J u as The term J E u in (21) represents the profit coming from the energy generation and consumption of entity u when operating in the community. Notice that J E u can be easily obtained from the solution of (2) by extracting the community energy prices from the dual variables of the energy balance constraints (see [7] for the details). Moreover, (21) is left free as an optimization variable of the upper-level problem.
In order to express the relative profit increase in an entity, denote by J SU u the optimal profit of entity u when acting as a single user, i.e., outside the community. Notice that the value J SU u is computed by solving for each entity an optimization problem similar to problem (2), but without any interaction among the entities. Then, introduce the slack variable α ≥ 0 and consider the constraints Maximizing α corresponds to maximizing the minimum relative profit increase for the entities such that |J SU u | > 0. Notice that, since α ≥ 0, constraints (22) imply that J u ≥ J SU u , ∀u ∈ U , ensuring that no entity is penalized compared to acting individually, thus promoting the participation in the community.
Summarizing, the objective function of problem (1) is simply F(x, y * ) = α. The vector x of the optimization variables includes J u ,J u and α. The feasible set X is defined by constraints (20)- (22), besides the condition α ≥ 0. (1) and (2) resulting after the introduction of the fleet of EVs retains its original structure. Specifically, it enjoys the same decoupling property between the upper and lower levels. As such, it can still be tackled by solving sequentially the lower level and the upper level problem. The upper-level problem is still a linear program. The major difference is that now the lower-level problem involves binary optimization variables (the assignment variables z h,d ) so it becomes a MILP. A flow chart of the overall procedure is shown in Figure 2a. Large-sized instances of the lower-level problem, featuring many requests and a large number of EVs, require an excessive computational burden to be solved at the optimum. A possible way to deal with this issue is to solve the assignment problem beforehand, prior to the market clearing. This approach leads in general to suboptimal solutions but makes the lower-level problem a linear program. To this purpose, in the next section, we propose a heuristic procedure that can be used to solve the assignment problem, based only on the requests received on the day ahead.

Heuristic Assignment
In this section, we present a heuristic solution to the problem of assigning an EV to each request. The requests are sorted by their departure time and they are processed sequentially in that order. The proposed heuristic builds the final assignment incrementally, starting from z   (10) is verified. Again, this can be checked from s d i ,0 , z (i−1) h,d and P d . In general, at iteration i there exist multiple EVs that can be assigned to request h i without violating any of the above conditions (candidate vehicles). In this case, the heuristic attempts to assign to h i the most promising candidate vehicle, by maximizing the time that a vehicle has at its disposal to recharge its battery before request h i begins. For each candidate vehicle c i , the availability time is computed as the maximum of the return times of the requests associated with vehicle c i in z h,d . Then, request h i is assigned to the candidate vehicle having the earliest availability time. Intuitively, the heuristic tries to maximize the time between two consecutive requests that must be served by the same vehicle. This choice aims at introducing more flexibility in the charging schedule problem to be solved afterwards, thus obtaining less suboptimal results.

Remark 3.
When the assignment problem is addressed by means of the proposed heuristic procedure, problem (2) boils down to a linear program, since the binary variables z h,d are assigned. Hence, the overall bi-level model (1) and (2) can be efficiently tackled by solving two linear programs sequentially. The resulting flow chart is shown in Figure 2b. The proposed procedure leads to a dramatic reduction in the computational burden, although it is not guaranteed to return the optimal solution. However, numerical simulations have shown that the heuristic solution attains a cost close to the optimal one. These aspects will be extensively discussed in the next sections.

Numerical Results
To validate the proposed approach, three examples are provided. The first two are toy examples reported to illustrate how the proposed procedure works, while a third example aims at evaluating the procedure's performance and computational feasibility in a more realistic scenario. In each example, a comparison between the proposed heuristic for vehicle assignment and the optimal solution of the MILP is carried out. In all simulations, the optimization horizon is assumed to be 24 h. In the following examples, the peak price is set to π peak = 0.5 e/kW, while the reserve price is π res = 0.3 e/kW. Finally, the fee received by the community operator is γ com = 0.01 e/kWh. Simulations have been performed on Matlab, the optimization problem is formulated in Yalmip [27] and solved by Gurobi [28] on an Intel i7-11700 @ 3.60 GHz, 32 GB of RAM. Example 1. Let us consider a community composed of three entities, and let us perform a simulation of one day. The sampling time is set to ∆ = 1 h. The first entity is assumed to be a non-flexible load, whose demand of 5 kW is kept constant throughout the day. The second entity may provide steerable generation up to 7.5 kW, while the third entity is equipped with two identical EVs. EV battery capacities are set to S d = 50 kWh with a maximum charging power P d = 7.4 kW. Battery efficiencies are set to η d = 0.9. Three EV requests are considered, as detailed in Table 1. Electricity prices for import from and export to the grid are assumed to be constant during the day and equal to π igr t = 0.15 e/kWh and π egr t = 0.035 e/kWh, respectively. Moreover, the unit cost of steerable generation is assumed constant and amounts to 0.04 e/kWh.
In Table 2, the request assignment is reported. Specifically, an entry is labeled if a vehicle and a request are matched by one of the procedures (H stands for heuristic, while O stands for the optimal MILP solution). In this setup, the optimal solutions obtained from solving the MILP and applying the proposed heuristic coincide. In fact, to mitigate the peak power consumption, the optimal allocation is the one that maximizes the time between consecutive requests of each vehicle, since it provides more flexibility for the recharge. In Figure 3, it can be noticed that EV batteries are charged at a power rate lower than its maximum, in order to limit the peak consumption. Notice that the power imported from the grid never exceeds 2.5 kW and the steerable generation facility (entity 2) sells all the generated energy to the community in order to achieve the minimum aggregated cost. From the community market point of view, the prices change three times a day. At the beginning of the day, only entity 1 is demanding energy, which is satisfied by the steerable generation. From 9 to 13, the EV charging process begins, but the power imported from the grid remains below the daily peak, which occurs in the last part of the day when the community is asking the grid for a constant power of 2.5 kW. The community incurs an overall cost of 15.08 e with respect to a total cost of 32.33 e if each entity would act alone exchanging energy only with the grid.

Day time [h] Battery level [kWh]
The energy flows at the community level and the community prices are reported in Figure 4.

Example 2.
To provide an example where the heuristic is suboptimal, a setup similar to that reported in the previous example is considered. The same data of Example 1 have been used, except for the price of energy imported from the grid, and the maximum amount of steerable generation. The import energy price is set to π igr Entity 1  It is apparent that it is not convenient to charge vehicles in the interval [9,17] since the energy price is doubled and steerable generation is not available. However, the solution returned by the heuristic coincides with that of Example 1, because it does not depend on prices and on other entity features. On the other hand, the optimal MILP solution assigns the first two requests to one EV and the last one to the other vehicle, as reported in Table 3. In this case, the optimal cost incurred by the community is 30.73 e, while that provided by the heuristic assignment amounts to 32.55 e.

Example 3.
Let us consider a more realistic framework composed of 5 entities as described in Table 4. Each table entry denotes the number of non-flexible loads (nfl), sheddable loads (she), non-steerable generators (nst), steerable generators (ste), storage systems (sto) and EVs. Notice that, entity 5 is equipped with 10 identical vehicles. A simulation of 100 days is carried out, solving problem (1) and (2) for each day. The sampling time is ∆ = 10 min.  The non-flexible energy demand profiles for entities 2 and 4 in a given day are depicted in Figure 5. Such profiles are a slightly perturbed version of those reported in [29]. Sheddable loads of entities 1 and 3 can reduce their consumption up to 25% of the nominal value. Non-steerable generation is assumed to be provided by PV plants (see Figure 6), whereas the steerable generators are capable of producing up to 5, 7.5, 8 kW of electrical power for entities 1, 2 and 3, respectively.  Figure 6. Example 3. Non-steerable generation profiles in day 10.
The storage system of entity 3 has a capacity of 40 kWh with maximum charging/discharging power equal to 10 kW, while the charging and discharging efficiencies are both set to 0.9.
Regarding the vehicles associated with entity 5, a set of 10 EVs with identical specifications are considered. Their battery capacity is S d = 50 kWh, while their maximum charging power and battery efficiency are set to P d = 22 kW and η d = 0.9, respectively. For each day, up to 30 EV service requests are considered. These requests are chosen to ensure the feasibility of the heuristic procedure. Departure times are drawn from a discrete uniform distribution from 1 to 108 time steps, corresponding to the range 12 a.m.-6 p.m. On the other hand, for a given EV request h, its duration is set according to a discrete uniform distribution from 1 to 4 h. The energy required by each request follows a uniform distribution in the interval [10,40] kWh. Finally, the prices of energy imported from the grid are taken from the Italian electricity market [30] (see Figure 7), while the export energy prices are set to 25% of the import energy prices. Concerning the simulation results, the procedure based on the heuristic assignment provides an average community daily cost of 114.16 e, whereas the total cost of all the entities acting individually would be 129.48 e. Energy flows and community prices for a given day are reported in Figure 8.  Focusing on the entity hosting EVs, it would incur an average daily cost of 71.21 e by acting alone, while joining the community grants a cost reduction of 11.83%. To evaluate the optimality level of the heuristic, the solution obtained by the proposed procedure is compared to that returned by the MILP. In the considered setup, the two approaches show similar results. In fact, the maximum daily gap between the two solutions is less than 1%.
Regarding the computation time, the average time to find a solution to problem (1) and (2) for one day using the heuristic procedure or solving the MILP is 0.79 and 144.29 s, respectively. Hence, in this case, the proposed heuristic is around 200 times faster than the optimal procedure.

Discussion
While Examples 1 and 2 reported in the previous section are toy examples aimed at illustrating how the proposed procedure works, Example 3 is more realistic and allows one to obtain insight into the potential performance of the proposed approach.
The main outcome is that the cost of EV charging is significantly reduced when the rental service operates within the energy community (more than 10% in the considered setup). Notice that this comes at no expense to the other community members. Overall, the community enjoys an average daily cost saving of about 15 e, which is then shared among all the entities. The adopted redistribution policy ensures that, when participating in the community, all the entities benefit from a cost reduction, compared to operating alone (i.e., outside the community).
In order to evaluate the level of conservatism introduced by the heuristic assignment procedure presented in Section 4, the heuristic solution (i.e., the one computed as in Figure 2b) was compared with the optimal solution (i.e., the one computed as in Figure 2a). Notice that the latter requires the solution of a MILP, whose complexity scales badly with the number of binary variables. This was the reason of the size of Example 3, in which the number of entities and EVs was chosen such that the MILP could be solved in reasonable time. Quite remarkably, the cost returned by the heuristic solution is very close to the optimal one, with a performance degradation that is always less than 1%. As a matter of fact, on many days, the heuristic assignment coincides with the optimal one.
A third aspect that was analyzed is the computational complexity of the proposed approach. In the considered example, the processing time required to compute the heuristic solution is about 200 times less than that needed to find the optimal solution. Such a dramatic time reduction is expected to be even more evident in larger and more realistic scenarios. Indeed, when the number of EVs increases, the solution of the MILP quickly becomes intractable. On the other hand, the complexity of the proposed approach scales nicely with respect to the problem size, since it does not require the solution of any combinatorial problem. We stress that the possibility of skipping the solution of a MILP is what mainly distinguishes our contribution with respect to [23,24].
We stress that the obtained results are in agreement with European energy policy directives [1], stating that the primary purpose of energy communities is to provide environmental, economic or social community benefits to its members or shareholders. Indeed, the more advantageous energy prices originated within the community bring clear economic benefits to the members, but also induce social benefits, by helping fight energy poverty through lower supply tariffs. Environmental benefits are achieved not only by fostering the penetration of renewable energy sources, but also enabling the decarbonization of the transportation sector by making EV management more affordable. Optimization performed at the community level promotes more virtuous consumption behaviors at the household level, by fostering concepts of common responsibility. Finally, optimal community management brings benefits also at the system level, by enabling the reduction in the peak power resulting from uncoordinated simultaneous charging of a large number of EVs.

Conclusions
In this paper, the optimal management of an energy community hosting a fleet of EVs for rent has been considered. The contribution is threefold. First, a new optimization model for EV rental service has been proposed, which includes the request-to-vehicle assignment problem, as well as the optimal charging schedule of the vehicle batteries. Second, it has been shown how to embed such a model into an existing optimal management architecture of energy communities. The resulting optimization problem is a bi-level model, whose exact solution requires tackling a MILP. Third, a heuristic solution to the assignment problem has been devised. This results in a dramatic reduction in the overall computational complexity, at the price of minor performance degradation.
Several research directions are currently under investigation. A more extensive experimental validation of the proposed heuristic is needed in order to evaluate its ability to return feasible assignment solutions in case of a high request-to-vehicle ratio. The proposed management model solves a planning problem on the day ahead. A further step is to derive online operation policies that adjust the day-ahead schedule on the basis of the actual load and generation profiles, as well as of the deviation of vehicle usage from the times and energy declared in the submitted requests. In this respect, it will also be useful to incorporate more accurate techniques for the prediction of EV charging duration time [31,32] in our model.