Optimal Control of Multiple Microgrids and Buildings by an Aggregator

The electrical grid has been changing in the last decade due to the presence of renewables, distributed generation, storage systems, microgrids, and electric vehicles. The introduction of new legislation and actors in the smart grid’s system opens new challenges for the activities of companies, and for the development of new energy management systems, models, and methods. A new optimization-based bi-level architecture is proposed for an aggregator of consumers in the balancing market, in which incentives for local users (i.e., microgrids, buildings) are considered, as well as flexibility and a fair assignment in reducing the overall load. At the lower level, consumers try to follow the aggregator’s reference values and perform demand response programs to contain their costs and satisfy demands. The approach is applied to a real case study.


Introduction and State of the Art
International policies for sustainable development have led to an increase in distributed power production based on renewable resources. The electrical grid has been changing in the last decade due to the presence of renewables, distributed generation, storage systems, microgrids, and electric vehicles. These technologies introduce a lot of challenges mainly due to uncertainties and intermittencies associated with their presence [1]. In particular, the massive presence of renewable resources can create some problems to the distribution grid; as a matter of fact, the unpredictability of these sources can cause some power quality issues in the power network (e.g., voltage unbalances and undesired peaks). Usually, traditional controllable generators are called to compensate these fluctuations, operating at different working points from the optimal ones. This function for the traditional generators cause efficiency losses (increasing in operational and maintenance costs) and a decrease of regulation margins for the distribution grid [2]. Moreover, due to the increase of generation from renewables, large fossil-fueled production plants are no longer installed or are reduced in rated power; this affects the capability of the grid to respond to emergency situations.
The characteristics of these new smart grids require an increase of the power reserve to face the sudden request of active/reactive injection/absorption from a distribution system operator (DSO) to compensate for example a sudden drop in the production from a photovoltaic plant. Microgrids and smart buildings can see these issues as an opportunity to provide regulation and reserve services in both directions since they can be considered as prosumers [3][4][5]. Interconnected buildings can be seen as microgrids or districts that can share thermal and electrical power to satisfy comfort, economic, and technical exigencies. In this framework, demand response (DR) (i.e., the possibility for a traditional load to decrease the active power absorption for a certain period) is an effective and reliable strategy for the successful integration of renewable energy sources, handling the demand pattern using load flexibility whenever the system requires it [6][7][8]. A significant portion of DR programs can be represented by local users and/or prosumers, which, by themselves, cannot participate in the energy market and offer a reduction of load at a certain price. In fact, the introduction of new legislation and actors in the smart grid's system opens new challenges for the activities of companies, and for the development of new energy management systems, models, and methods. For example, the figure of an aggregator that manages different local consumers and/or producers to reduce power demand or to increase production gives rise to different possible optimization problems [1].
A key point is to integrate the different actors (transmission system operator (TSO), DSO, aggregators, local users, etc.) that can act within collaborative, competitive, or hierarchical rules in a market structure in which the decisions should be taken into account according to successive stages. Each stage is characterized by different players with different objectives, thus representing a portion of a multilayered energy market. An aggregator must take decisions interacting, first of all, with the TSO offering an amount of power to be reduced at a certain price. Then, the aggregator has to collect in its portfolio a large number of customers in order to be paid from the TSO; besides, it must provide incentives to local users, and should avoid customers' dissatisfaction in terms of both economic costs and technical feasibility. At the lower level of the layered market structure, there are users that have two main decisions to be taken: a) How to provide constraints to the aggregator related to the flexibility that they can technically offer; b) how to manage their local systems following the requests of the aggregator once they are available.
Distribution network's optimization and control in presence of DR aggregators is particularly interesting and some papers in the recent literature propose new operational management strategies. In particular, it is necessary to define how to schedule load reduction or production increase among the different customers to achieve an overall load reduction and/or shifting. The main effort is devoted to the integration of different actors in a multi-layered market structure. A portion of the recent literature is focused on bi-level programming, in which one or several constraints represent the optimal solution of low-level problems. In other words, the upper-level problem has its own optimization problem to be solved through mathematical programming, in which the analytical solution of the lower level optimization model is inserted as a constraint. In [9], the authors propose a bi-level model for the distribution network and renewable energy expansion planning in a DR framework. The objective function of the upper-level problem minimizes investment, maintenance, energy purchased from substations, and unserved power. The lower level has instead the objective of minimizing the overall payment faced by the consumers. The Karush-Kuhn-Tucker (KKT) complementarity constraints are used to ensure the optimality of the lower-level solution. In [10] the authors present a bi-level architecture based on Model Predictive Control. An upper-level decision maker, by means of its objective function, minimizes its own power losses and costs; moreover, it provides power exchange references related to power-flow constraints. The main differences from our work are that we focus on operational management in which the storage dynamics are represented as well as temperature variation in each building. Moreover, in the present paper, at the upper level, it is considered an objective function that represents an aggregator that receives remuneration from TSO, must provide incentives, and has to manage buildings and microgrids equipped with their own energy management systems (EMSs).
In the same line, in [11] the authors propose a bi-level programming approach, within a game theory approach, for optimizing the electricity tariff offered by an electricity retailer to its customers. The model identifies customers as 'prosumers' (i.e., both producers and consumers) who try to maximize their utility and to minimize their cost of electricity.
The authors in [12] consider a framework in which an aggregator of distributed storage energy systems, electric vehicles, and temperature control loads is present and bids in day-ahead energy and reserve markets. Even in this case, a bi-level optimization model is proposed. In the present paper, a similar framework is considered. However, the main difference, with respect to the previously mentioned contributions, is that microgrids and buildings here are represented with their own EMS. Thus, the dynamic behavior of users is taken into account.
Bi-level programming is used in many other application areas of energy systems in which there are multiple systems and objectives to be considered (see, for example, [13][14][15]). However, bi-level programming is not the only approach that is used in energy systems for the integration of different systems, actors/agents and decision-makers.
Authors in [16] develop a hierarchical and distributed DR control strategy. They consider a center-free algorithm and information is not collected on all DR devices. A hierarchical EMS for optimal multi-microgrids operation based on multi-agent systems is proposed by the authors of [17]. In [18] the authors proposes a distributed energy allocation mechanism for the DSO market. This mechanism is based on a bi-level iterative auction. The DSO runs an upper-level auction with load aggregators as intermediate agents competing for energy (the locational marginal price is assumed to be known). Aggregators implement lower-level auctions in parallel until market equilibrium is established. In this way, it is possible to converge to a socially optimal solution while maintaining physical grid constraints.
In [19] the authors study the operation of a retailer that acts as an aggregator with priceresponsive loads and submits demand bids to the day-ahead and real-time markets. The work presented in [20] uses Benders' decomposition method to reduce the computational burden in a twostage stochastic model for aggregators in a large-scale case study. In [21], customer aggregators are introduced to supply downstream demand in the most economical way. A two-level optimization problem considers aggregators' flexible energy demand incorporated into the centralized energy dispatch model. The objective function aims to maximize social welfare minimizing the energy purchase cost. In [22] and [23], the authors jointly study energy storage systems (ESSs) and DR. They analyze their impact and possible use in a smart grid.
In [24], the authors focus attention on the integration of residential users because they are in huge numbers and require relatively small power loads. It is shown that residential users can receive financial benefits from reserve provision. A hierarchical structure of users is adopted together with a game-theoretic approach.
In [25], the authors focus attention on plug-in electric vehicles (PEV) in a district and on how they can help in demand-side management. In the experiments, the results show that the proposed system can reduce a significant amount of both electricity cost and peak power.
A crucial point is the estimation of the potential flexibility of different types of consumers for day-ahead and real-time ancillary services provision taking into account customers' reactions to the price signals [26]. Moreover, the use of incentive-based payments as price offer packages is recommended in order to implement DR [27].
In addition to the scheduling of an aggregator's customers, it is fundamental to design the optimal set of customers for an aggregator. In this framework, authors in [28] study the impact of consumer behavior on the portfolio design of a DR aggregator, developing an optimization model.
The present paper considers an aggregator (AGG) that has the knowledge of the power distribution grid because it is also a DSO or works in strict collaboration with the DSO.
The day-ahead balancing market is that session of the market where the TSO requests for some power flexibility in order to deal with the variation of the demand. In this session, the AGG bids the price of energy and the amount of power to be reduced/increased in each time interval during the day and thus it is necessary to coordinate the different customers, trying to satisfy power demand reduction/increase and giving incentives to local users in connection with these requests. For the sake of simplicity, in this paper, only the case of power reduction is considered.
The main contributions provided in this paper can be summarized as follows: • The development of an optimization-based bi-level architecture for a DSO/aggregator for participation in the balancing market in which the incentives for local users (LUs), together with active and reactive power exchanges, are decision variables. • The statement of an optimization problem for the optimal management of an aggregator/DSO that considers a simplified prosumers' model for flexibility assessment, providing set points for DR operations of the LUs, ensuring a certain level of fairness.
• The inclusion of detailed dynamical models for the two main classes of LUs (microgrids and smart buildings) including electrical and thermal elements. The structure of the paper is organized as follows: In Section 2 the proposed control architecture is presented. Section 3 describes the AGG's optimization problem while Section 4 states the LUs' optimization problem. Section 5 presents the obtained results in a case study. Finally, Section 6 reports some concluding remarks.

The Proposed Decision Architecture
In this work, we propose a two-level hierarchical architecture for the problem, as depicted in Error! Reference source not found..
The higher level represents the AGG, aiming at minimizing different terms of cost, that include: a) Incentives to be paid to LUs, b) fees/benefits (to/from the main grid) for not reaching the agreed reduction, c) a term aiming at a fair distribution of the power reduction among the LUs. The AGG has to define active and reactive power exchanges with the LUs, as well as the incentives (that are expressed as a function of active power reduction).
At the lower level, LUs try to track the power reference values given by the solution of the AGG problem. Unlike the AGG, each LU uses a detailed model of its components.
Before the process starts, the AGG has perfect knowledge about the balancing market results (power reductions requests, incentives, and fees), and receives the maximum flexibility affordable by LUs calculated in the day-ahead on the basis of technical and economic considerations. Then, the AGG solves its optimization problem by using a simplified (emulated) model for each LU and assuming to have access to an estimate of the storage element associated with each LU. Instead, each LU does not have any information about the electrical grid and the other users, thus avoiding competitive behaviors. In fact, no competition between different LUs is allowed. It is important to note that the above two-level optimization procedure is intended to operate within a receding horizon control scheme. In particular, as reported in Figure 2, an optimization horizon (T) is defined over which it is assumed that reliable forecasts about future uncertain inputs and parameters (in this case, power demand, generation from renewables, prices) are available. Such forecasts are provided by prediction models which are considered to be external to the proposed control scheme. Of course, the optimization horizon is the length over which the optimization problem is run. In a receding horizon scheme, in the first run, the optimal control actions for the entire length of the optimization horizon are found, but only the solution corresponding to the first time interval is actually applied. Then, at the beginning of the second time interval, new information from sensors in field (concerning the system state) and updated forecasts of the external inputs are acquired. On this basis, a new optimization run is carried out, and so on until the horizon over which the system is actually operated or simulated (simulation horizon) is completely covered (see Fig. 2).
The optimization problem considered in this paper refers to a single iteration of the receding horizon control procedure and is focused on the possibility of efficiently solving the problem via a two-level approach. Clearly, in a receding horizon scheme, at each new time interval, new information is acquired and the two-level optimization procedure is again carried out.

Representation of the Network Constraints
The considered physical system is composed by buildings and microgrids, both including renewables and storage systems, and connected to the main grid.
In order to formally represent the system model, the following sets are considered: It is necessary to consider the power flow equations for active and reactive power, which affect the power exchanges among LUs connected to the grid. As in [29,30], in the linearized form and in discrete time, these equations can be expressed as follows where: •   T is the number of time intervals considered, that is, the optimization horizon. The quantities , , , u z t p and , , , are a-dimensional and are expressed with reference to a common voltage/power base value (i.e., as p. u. values). The balance equation for active power at each node p is given by is equal to 1 if the LU j is directly connected to u and 0 otherwise. , Note that (3) holds for 1 u ≠ . In fact, conventionally node 1 is defined as the connection node to the main grid, to which no LU is directly connected. For this node, instead of (3), the following equation holds: is the power flow [kW] between node 1 and the main grid (considered as positive when the power is entering the node). Similarly, the balance equation for reactive power is given by: where , j t Q is the reactive power exchange [kvar] between node u and the LUs and , , p q t Q represents reactive power flows from node u to node z. In this case too, node 1 has a different equation, namely: is the reactive power flow [kvar] between node 1 and the main grid.
In this model, the following constraints must be fulfilled: where the upper and lower bounds have a straightforward meaning. It is supposed that the AGG only requests for a variation (decrease) of active power. To this end, the AGG, in order to determine incentives and to divide among its customers the (active) load reduction, has to quantify the reductions' possibilities of each LU using limited information about the local systems' states. For this reason, an emulation is necessary (i.e., an approximate simulation) of the dynamic behavior of each LU, as described in the following sub-sections.

Emulation of the LUs Corresponding to Buildings
This subsection reports the model used for the emulation of a building, embedded in the statement of the higher-level problem. This model includes a storage system, renewables, and heat pumps. The state of charge (SOC) dynamics of storage systems (one for each building) can be represented by the following equations The electrical balance equation includes the sum of power feeding the building (i.e., power from storage, renewables, power from the main grid) that is equal to the power demand , It is supposed that the AGG has no detailed information about the temperature in the various rooms in each building. Thus, a single variable , j t T [K] is used to represent the temperature of the overall building j. The dynamics of such temperatures is represented as in [31], namely: where σ is a given constant specifying whether the heat pump operates in heating mode ( 1 The following upper and lower bound constraints must be taken into account: , , ≤ , , ≤ , , ∈ , = 0, … , − 1 , , ≤ , , ≤ , , ∈ , = 0, … , − 1 , ≤ , , ≤ , ∈ , = 0, … , − 1 where all bounds for control and state variables are known parameters, being is a given quantity (known at least as a forecast), , , RES j t Q may be considered as a decision variable since its value may be adjusted, for any time interval, by means of an electronic system based on the use of inverters.
Finally, the following constraints must be satisfied: where the upper bounds

Emulation of the LUs Corresponding to Microgrids
This subsection presents the model used to emulate microgrids within the statement of the higher-level problem. Microgrids can be modeled in a similar way as for buildings. However, the system model is in this case a bit more complicated because the thermal balance must be considered, given the presence of cogeneration plants in microgrids.
Specifically, the electrical balance is given by: where , , EL j t P is the power produced from fossil fuel plants.
The thermal balance in the heating operation mode is given by: where , , , where , , , TH CHI j t P is the thermal power needed to feed chillers. Moreover, in the cooling mode, also the following constraints need to be satisfied:

The Higher-Level Optimization Problem
In this subsection, the statement of the higher-level optimization problem solved by the AGG will be provided. This problem will embed, as constraints, all equations and inequalities that have been introduced in the previous subsections in order to emulate the LUs' behavior.
The cost function of the higher-level decision problem consists of several terms.
A) The first of them is inc C [€], that is the cost relevant to incentives that must be provided to the LUs in order to diminish their own load. Let is a unit cost coefficient [€/kWh]. Namely, this coefficient represents the cost associated to a unit of unsatisfied energy demand. The following constraints hold as regards t DR , namely: On this basis, DR B can be written simply as: C) Finally, there is a term called "Assignment Fairness" ( AF C [kW 2 ]) that is introduced to avoid too unbalanced power reductions among the population of LUs. This term can be written as: (37) At this point it is possible to formalize the overall AGG decision problem as follows.
The higher-level (AGG) decision problem: s.t. constraints (1)÷(37) and In the expression of the cost (38), ω [€/kW 2 ] is a tradeoff coefficient whose value should be tuned on the basis of the real case study considered. Constraint (39) must be inserted in order to avoid excessive discrepancies between the benefit provided by the market to the AGG (with reference to a specific LU j) and the overall incentive provided by the AGG to that LU. In (39) min α and max α are fixed parameters (<1) and represent minimum and maximum fractions of the benefit to the LUs.
Having so represented the optimization problem to be solved by the AGG, we are now in a position to introduce problems that have to be solved by each LU.

The LUs' Optimization Problem
The LUs track the references coming from the solution of the AGG problem, but have detailed local information and may decide how to manage production plants and storage systems in order to accomplish the AGG's requests. has the same physical meaning as , , HP j t q but now it corresponds to the power provided to the heat pumps in building j that is actually determined solving the problem for the detailed model of that building.

The Model Used for the Optimization Problem of a Building
Even for the detailed model of the single building the presence of a single storage element is considered, whose dynamics can still be represented via (10)- (11).
The power balance equation is given by: which has the same meaning as (12) but where: • , , is the power flow form the storage element corresponding to the solution of the local problem; • , , is the actual power flow from the main grid to the LU j, determined by the solution of the local problem; • , is the building load, expressed in a more detailed way with respect to (12), that is: Including: -fixed consumption , , ; -power necessary to feed electrical vehicles ℎ, , ; -power necessary to feed washing machines ℎ, , . However, there is a fundamental difference between (42)-(43) with respect to (12)- (13). In fact, whereas , , , , , and , , are considered as fixed in (12) where , , , is the total electrical energy demand for electrical vehicles [kWh]. , , is the power demand for the washing machines that is split in two terms: one fixed , , (not adjustable) and one deferrable , , .
, ℎ, is the total deferrable energy demand [kWh] for washing machines.

The Optimization Problem for a Building
Each LU j receives form the AGG, as a part of the solution of its problem, the load reductions , , = 0, . . . , − 1 attributed to the specific LU, and the (reference) values , = 0, . . . , − 1, corresponding to the power flow between the grid and that LU. Then, the LU problem can be formalized as the minimization of the quadratic deviation between the sequence , , of the actual power flow from the main grid and the LU, and the reference sequence , .

The Model Used for the Optimization Problem of a Microgrid
We consider a model with the following entities: Microturbines (representing the cogeneration plants), photovoltaics, electric vehicles charging stations, heat pumps and chillers. Even for the detailed model of the single microgrid, the presence of a single storage element is considered, whose dynamics can still be represented via (10)- (11).
In this model, the electric power balance is given by: where: • ,ℎ, , is the active power coming from the controllable microturbine h in microgrid j; • , , , is the active power that is injected from local renewable energy sources of kind l; • , , is the active power (unrestricted in sign) drawn from the storage; • , , is the power coming from the grid; • , , is the power requested by heat pumps; • , , is the fixed electrical demand; • ℎ, , is the power consumed by electric vehicles.
Powers ℎ, , is considered as a deferrable load and is subject to constraints similar to those in Equation (44). Furthermore, , , , and , , , are the corresponding reactive power flows. Note that it is assumed that it is possible to regulate the reactive power from the controllable microturbines, imposing them as equal to zero. Thus, there is no decision variable corresponding to these powers. Instead, it is assumed that the reactive power coming from the renewable energy sources, as well as the reactive power coming from the storage, can be regulated. Thus, such powers are considered as decision variables. Besides, , , is a fixed amount of reactive power corresponding to the heat pumps and the electric load (the reactive power for electric vehicles is assumed to be zero).
Besides, the following constraints must be taken into account: where ℎ, is a given parameter characteristic of the considered microturbine. More complex relationships could be used instead of (56) but, for the sake of simplicity, in this paper a purely linear model is adopted.

The Optimization Problem for a Microgrid
Even in this case, the optimization problem can be stated as the minimization of the quadratic deviation of the actual behavior with respect to the reference value given by the upper problem, as regards both active ( , = 0, . . . , − 1) and reactive ( , = 0, . . . , − 1) powers.

Application to a Case Study
The developed bi-level architecture has been applied to a case study in the Liguria Region, Italy. In particular, the considered case study is related to Savona Municipality data, which is located in the north western part of Italy. In particular, on the territory, it is already present a microgrid at the campus level [29], which includes heat pumps, buildings and renewables, a laboratory microgrid, and a sustainable building that, with renewables and storage systems, can be operated in islanded mode and considered as a microgrid. Moreover, the municipality is planning to replicate the microgrid in different areas and to constitute an energy community in the context of a so-called "smart city project". For these areas data have been estimated on the basis of territorial characteristics and the Savona Campus Microgrid.
Specifically, six different local users have been considered. Three of them are building type LUs, while others are microgrid type LUs. Figure 3 shows a scheme of the considered case study. The network is composed by a slack node (i.e., the connection to the main grid, green), plus other 5 (blue) nodes: two with building type LUs connected, and three with microgrid type LUs. The model has been implemented with the optimization modeling software LINGO and the results are presented in the following sub-sections. Due to the high-computational burden, each problem runs in about 4 to 6 min.

The Available Data and Demands
The upper level represents the AGG and emulates the LUs' behavior in order to determine and distribute the demand reduction. The considered power production from renewables for the different local users (only from PV plants) is reported in Figure 4, while electrical ( , ) and thermal ( , , ) demands (the latter is considered only for microgrids) of two LUs (one building and one microgrid) are reported in Figures 5 and 6. Electrical and thermal demands for the other LUs have profiles similar to those reported in Figures 5 and 6, respectively. Note that a 24 h optimization horizon has been considered, whereas the time discretization interval is 1 h.

Results for the AGG Optimization Problem
The optimal results for the AGG's optimization problem are presented in Figures 7-9. The optimal solution has a power reduction as presented in Figure 7. It highlights that the power reduction requested at the grid node ( ) is almost satisfied along the entire optimization interval, with a slight difference during the first and the last hours due to the absence of renewable power.
Besides, Figure 8 reports the values for the power exchanged between the main grid and each LU ( , ), while Figure 9 shows the optimal results related to the power reduction , , . It can be noted that the overall power reduction is split in rates which are maintained almost equal along the whole day. This is mainly due to the presence of the "Assignment Fairness" term in the cost function minimized in the higher level problem.  Once the upper-level optimization problem is solved, its solution is used as a reference pattern for the lower-level decision problems.

Lower-Level Results: Building-Type LUs
The results of the lower-level optimization problems are presented in Figures 10 and 11. It can be noted that the power reference pattern set by the AGG is tracked almost exactly in the solution of the lower-level problems ( Figure 10).
where , , , the first term in the r.h.s. represents the power drawn from the storage and injected into the building, whereas , , , represents the power absorbed by the storage. Figure 11. Electrical balance in the LUs (buildings).

Lower-Level Results: Microgrid Type LU
The second type of LUs are microgrids. They have higher flexibility due to the presence of a larger pool of energy production technologies. This leads to a solution ( Figure 12) which perfectly fits the reference data. In Figures 13 and 14 both the electrical (53) and thermal balances (57) are reported, highlighting the variety of the energy production pool. Specifically, the presence of two microturbines for each of the three microgrids, one with electrical nominal power of 35 and 65 kW (C30 and C65, respectively). The fraction of the load satisfied through the energy bought from the grid is definitely lower than in the case of buildings because the microturbines are co-generative plants, which are able to satisfy also thermal demands.  As expected, the higher flexibility of the microgrids provides a better solution in regards to the objective function, since the electrical profile totally fits the reference one (see Figure 12).

Conclusions
Demand response is a subject of utmost importance and it can provide a noteworthy improvement to the performance of the grid. Of course, this requires the development and the application of viable and effective approaches for energy management. In this framework, an approach was proposed in this paper based on a bi-level architecture in which an AGG of consumers plays the role of a higher-level decision-maker. The problem solved at the AGG level is relevant to the balancing market, and incentives for LUs (i.e., buildings and microgrids) are considered as well as their flexibility. The higher-level, representing the AGG, determines the reference values, to be considered by the LUs, minimizing the overall cost function considered. At the lower level, the local users try to follow the reference values and, through demand response programs, try to contain their costs and to satisfy their demands. The microgrids are characterized by higher flexibility with respect to the other LUs (buildings), owing to the presence of several production plants. The proposed architecture has been developed within the following assumptions in regards to the (bidirectional) interaction between the two levels. First of all, the higher level provides the reference patterns for the lower-level problems. Besides, there is information flow from the lower level to the upper level in regards to the storage initial state and the maximum affordable reduction for each LU. The application of the presented decision scheme could be viewed within a receding-horizon framework, in which, at each time step, only the solution referring to the next time discretization interval is applied. Then, at the next time step, a new solution to the same problem, concerning an optimization interval of the same length as above, is determined after having received the information about the current system state. Further developments will be the implementation of more detailed models for single plants and the use of different renewable energy sources. Another possible extension could the application of the model to grids with different architectures to determine if the load flexibility can be improved. Funding: This research received no external funding. The outputs of the optimization results have been used as input data for the development of an Energy Management System for sustainable districts that will be developed within the PICK-UP innovation project funded by Liguria Region within the Innovation Pole on Energy Technologies and Sustainable Development (EASS).