In-Line Distributed Dispatch of Active and Reactive Power Based on ADMM and Consensus Considering Battery Degradation in Microgrids

This work presents a distributed in-line strategy to manage an isolated microgrid by optimizing active and reactive power dispatch. The proposed objective function leads to minimize the operation costs and addresses some technical requirements such as diminishing power losses and voltage deviation. Additionally, the strategy deals with temporal multi-scale goals, i.e., robustness to demand disturbances and variation of renewable resources (a short-term objective), and preservation of the health of battery-based storage systems (a long-term objective). The technique uses alternating directions method of multipliers (ADMM), accelerated consensus, and a novel battery degradation model (Quadratic AH-Throughput model). We test the proposed solution in a case study that includes renewable resources and lead-acid and lithium batteries. To obtain the results of the case study, we employ a co-simulation scheme that uses Matlab and DIgSILENT. Finally, the performance of the method is compared with a centralized optimization technique.


I. INTRODUCTION
Microgrids are widely used to integrate renewable energy resources and energy storage systems operating in a hierarchical scheme. The primary and secondary levels of the control hierarchy provide system stability through active and reactive power management [1]. For this purpose, the use of locally controlled power converters is common. On the other hand, the tertiary level establishes optimal operating points according to certain technical and economic conditions The associate editor coordinating the review of this manuscript and approving it for publication was Ahmed Mohamed .
(e.g., reduction of operating costs or provision of ancillary services) [2]. Tertiary controllers are in charge of highlevel decisions, which implies that they generally have to lead/execute several tasks [3]. Just to name a few, highlevel control is in charge of increasing the efficiency and robustness of the microgrid, facilitating the integration and management of storage systems, increasing the quality of service, and reducing the control effort of the lower levels of the hierarchy [4]. This large number of tasks could be performed efficiently by a distributed strategy. In fact, the design of centralized strategies implies a high computational effort and the need to implement complex communication VOLUME 11, 2023 This work is licensed under a Creative Commons Attribution 4.0 License. For more information, see https://creativecommons.org/licenses/by/4.0/ networks, increasing the deployment cost [5]. Additionally, from the network perspective, the robustness of centralized strategies is reduced because all the control effort is assumed by a single central node. Thus, if this node fails, the entire network fails [6], [7]. In contrast, distributed control strategies solve many of the aforementioned challenges. First, these strategies share the computational load among several controllers that operate with local information. Thus, they require communication networks with fewer links. Second, distributed strategies improve the resilience of the system to failures because these schemes do not depend on a single central authority [8]. Furthermore, they favor plug-and-play operation [6] and facilitate the integration of distributed energy resources such as renewable units. Distributed methods have been effective to solve the dispatch problem in microgrids using different approaches such as gradient descent [9], [10], consensus algorithms [11], [12], [13], and the alternating direction method of multipliers (ADMM) [14]. However, there are limitations that have not been fully addressed. Most of the methods reported in the literature do not consider relevant aspects of real scenarios such as the joint dispatch of active and reactive power, the optimal management of batteries, or the provision of ancillary services. For instance, [15] and [16] propose fast-converging distributed algorithms based on ADMM and the distributed gradient descent method to solve the economic dispatch problem, responding properly to demand disturbances [17]. Nevertheless, the algorithms do not take into account the management of energy storage devices, which are exposed to a high number of charging and discharging events. Consequently, these methods can significantly reduce the batteries' lifetime. In addition, the optimization does not consider the reactive power management of the microgrid. This fact reduces the capability of the strategy to mitigate voltage deviation and power losses.
Other distributed approaches address the problem of the imbalance between supply and demand caused by variations of demand profile and the inherent intermittency of renewable generators [18], [19]. Strategies based on a sliding horizon such as distributed model predictive control (DMPC) have shown to be a promising alternative to mitigate the imbalance. Some authors have complemented these strategies with machine learning tools to manage uncertainty. For example, [19] predicts irradiance using neural networks, with reduction of unsupplied energy for most of the analyzed cases. Although the proposed strategy has a distributed nature, it requires a high processing capacity for large prediction horizons, especially when it is necessary to consider small time intervals to cope disturbances of demand or irradiance. There are also some distributed strategies that consider the participation of storage systems to provide stability by facing variations in demand and generation. These strategies ensure that the state of charge of the batteries is within appropriate ranges at any time. For instance, the authors in [14] and [20] manage storage systems to meet technical and economic goals over a long-term horizon. The main drawback of long-term planning for battery management is that the ability to deal with short-term disturbances is seriously affected. Planning strategies with long horizons generally employ low time-resolution to avoid computational overload, but this fact reduces the strategy ability to cope with rapid changes in supply/demand. In addition to the described challenges related to storage systems, having an appropriate battery-degradation model is another problem to solve. This model is essential to design efficient policies that take care of the health status of batteries to increase their lifespan [4]. Although there are models to estimate the degradation of batteries of several technologies, many of the ones reported in the literature are not designed to be efficiently integrated into management algorithms [21]. On the one hand, there are models with a high degree of detail that, due to their complexity, are inadequate for making predictions in real time. On the other hand, the simplest models (e.g., control-oriented models) are not accurate enough to estimate the batteries lifespan [22], [23].
This work tackles the challenge of developing a comprehensive optimization problem and a solution method for a tertiary-level control of microgrids. Most of the optimization problems reported in the literature about tertiary control of microgrids are not extensive. Generally, they do not consider some relevant aspects such as joint dispatch of active and reactive power, provision of ancillary services (losses minimization, voltage deviation reduction), inclusion of a strategy for battery health care, consideration of uncertainty, and planning of a distributed operation. In this article, we formulate a tertiary-level optimization strategy considering all the aforementioned issues. Furthermore, we propose a distributed algorithm (based on ADMM and consensus) for solving the optimization problem. The algorithm allows us to perform an in-line operation due to its computational efficiency, which is guaranteed by dividing the scheduling horizon into two periods. This process speeds up the search for a solution by considering a long period horizon to schedule the batteries and a short horizon to respond to demand or electricity generation disturbances.
On the other hand, we have developed a novel battery degradation model (Quadratic AH-Throughput model) that can be included in the formulation of receding horizon strategies without losing the differentiability of the cost function. This characteristic allows us to use efficient algorithms ( [24], [25]) to solve the underlying optimization problem at each step of the receding horizon scheme. In addition, it is worth noting that the proposed battery degradation model can be adapted to lithium and lead-acid technologies and combines two influential variables (DOD and cycles) to achieve an accurate state of health estimation. Unfortunately, these desirable features are not included in many models reported in the literature. Summarizing, the main contributions of this paper are: 1) A comprehensive model for the tertiary control level of microgrids, which includes the implementation of a distributed strategy based on ADMM and consensus.
This strategy can operate in-line and includes multiple programming horizons allowing to deal with both battery management and system disturbances with a low computational burden. 2) A novel quadratic battery degradation model that can be easily integrated into optimization-based management strategies. This model can be applied to both lead-acid and lithium-ion batteries. The remainder of this paper is organized as follows: Section II describes the active power dispatch problem considering the long-term management of storage systems. Section III presents the complete power flow model considering reactive power, as well as the magnitude and angle of voltages, and the inclusion of ancillary services. The degradation model is presented in Section IV, where the tuning process of the model's parameters (which depends on the storage system technology) is also shown. In addition, Section IV describes the integration of the degradation model to the formulation of the active power dispatch problem. Section V presents the OPF algorithm based on ADMM and consensus, and Section VI shows the simulation scenario and the case studies, where a co-simulation scheme between Matlab and DIgSILENT is used to validate the performance of the algorithm and obtain numerical results. Finally, conclusions are drawn in Section VII.

II. ACTIVE POWER DISPATCH CONSIDERING STORAGE SYSTEMS
A. PRELIMINARIES 1) MICROGRIDS AS GRAPHS A microgrid has buses (i.e., physical connection points for generators, loads, and transformers) interconnected by distribution lines. Thus, a microgrid can be modelled by an undirected graph G = (N , L), where N = 1, . . . , N is the set of nodes (buses) and L ∈ N × N is the set of arcs (lines), such as, if buses i and j are linked by a distribution line, then (i, j) ∈ L.
The nodes have some associated variables. For instance, all nodes have a voltage magnitude V i (where i is the node index) and an angle θ i . Moreover, if a node has a generator, it has active and reactive power generation, denoted by P G i and Q G i , respectively. Finally, if an electrical load is connected to a node, it has active consumption P L i and reactive consumption Q L i .

2) POWER FLOW
The power flow (PF) is a feasible solution to the problem of satisfying the power demands of the electrical loads using generators through active and reactive power injections. The power flow in a polar form is defined as where P i (V , θ) and Q i (V , θ) are active and reactive injections [26]. If flow is positive the node is providing power, else it is consuming. These variables are expressed in terms of magnitude and angle of voltage as for all i ∈ N , and where G ij and B ij are elements of the admittance matrix related with conductance and susceptance of line (i, j). The variable θ ij represents the difference between angles θ i and θ j , and the notation N i represents the set of nodes connected to the i th node, including i. The approximations for the energy constraints in a grid presented in (1) and (2) are often combined with an objective cost function establishing the optimal power flow (OPF) in microgrids [27], [28]. Next, we propose two joint optimization problems to deal with technical and economic objectives, providing, in addition, some ancillary services and a strategy for storage management.

B. ACTIVE-POWER DISPATCH PROBLEM CONSIDERING BATTERY ENERGY-STORAGE SYSTEMS
Microgrids integrate battery energy storage systems (BESS) to support intermittent generation units, coordinated jointly with conventional generators by operation schemes such as the economic dispatch (ED), active power dispatch, or other variants. BESSs are modeled by accumulation dynamics that require multi-temporal management, adding a significant computational cost depending on the programming horizon.
The active power dispatch with BESSs determines the generation of each unit, including storage systems, to minimize the operating cost. It is mandatory to satisfy the restriction of supplying the aggregate demand and the constraints related to the generation limits. Besides, BESSs require the management of charge/discharge actions to keep the state of charge (SOC) of batteries within operational limits.
Consider a microgrid with a set of buses N , containing a set of generators N G = {1, 2, . . . , N G }, and a set of BESSs For the generation unit i ∈ N G ∪ N B (battery or generator), the active power profile is given by the vector In this period, generators and BESSs seek to coordinate the active dispatch and charging/discharging actions to solve min VOLUME 11, 2023 for all k ∈ K, where F is a cost function that captures the generation and storage cost, P k L is the aggregate power demand at time k, P Gimin , P Gimax , S jmin , S jmax are the operational limits associated with the generators units and BESSs, and S k j represents the SOC of BESS j ∈ N B at time k, defining S 1 j and S K +1 j as the initial and final states of charge. We have not considered startup/shutdown and ramp rate constraints because our model assumes that both generators and batteries have fast responses [29], [30]. Nevertheless, we recommend considering startup/shutdown and ramp rate constraints for large-scale microgrids whose generators have slow dynamics [31], [32].
The cost function F considers generation cost and battery degradation cost by where F i (P G i ) is a quadratic cost function of i th generator or BESS defined by k∈K (a are capacity-loss functions due to the number of cycles C δ j and DODs D δ j that occurs in the programming horizon, more details are provided by (20) in Section IV. We assume that F is convex to guarantee a global minimum in the problem. Moreover, for each BESS j ∈ N B in (5), a positive value of P k G j indicates that the battery is charging with a power equal to P k G j , whereas a negative value indicates discharge.

III. OPF AND ANCILLARY SERVICES
Optimal power flow mixes PF equations with an objective function to set an optimization problem to improve the performance of the power system or different technical requirements [33]. We establish an optimization problem based on OPF to adjust the reactive powers and voltage profiles, so that the objectives of reducing losses in distribution lines and maintaining voltages close to 1 p.u. are met. These ancillary services enhance the level of stability and improve the efficiency of the microgrid.
Voltages and power losses are sensitive to active and reactive power injections. These relations are well-established by the PF in (1), (2) and the power losses are given Notice that voltages and power losses depend on the power flows through the lines and are calculated according to the parameters of the distribution lines (resistance, reactance, conductance, and susceptance). Additionally, voltage magnitude and angle are not absolutely decoupled. These variables are related by quadratic functions that make the classical PF nonlinear, complex, and low-efficient [34]. In order to formulate an optimization problem considering a complete PF model, we use a linear PF with decoupled variables, high accuracy, and computational efficiency.

A. LINEARIZED PF
We use a linearized and decoupled PF introduced in [35]. The approximation is based on the fact that the differences between the phase angle do not exceed 20 degrees and voltage magnitudes are 1 p.u. approximately, for most small-scale power systems. In addition, the lengths of the lines are smaller than the ones in large-scale systems (transmission systems), so shunt susceptance or line capacitance can be neglected.
According to the notation of the PF linearization process presented in the Appendix A, the active power flow in (1) can be expressed as where N i is the set of neighbors of the node i th . In a similar manner, the reactive power flow in (2) can be established as The PF model in (9) and (10) is completely linear and decoupled, with the advantage that it does not require an iterative process to find a solution. This relaxation allows the problem to integrate the PF in the constraints of the optimization, mantaining the desirable relationship between voltages and active and reactive power flows. In addition, this model can be used in radial, and meshed distribution systems conserving the accuracy and improving computation efficiency [34].

B. ANCILLARY SERVICES
Distributed generation can enable ancillary services (AS) such as voltage regulation, congestion relief, selfconsumption, and energy displacement. These ASs help to face several common issues of distribution systems to maintain the integrity, stability, and power quality [4]. For instance, voltage variations on distribution levels can cause stability issues. When demand in a microgrid is too high, voltage profiles may drop below desirable limits, while overproduction of renewable generators produces over-voltages. In the same way, higher consumption leads to higher power losses and peak power demands, increasing electricity energy costs.
Providing AS in a microgrid with distributed energy resources (DERs) is challenging due to uncertainties associated with intermittent distributed generators (DGs), bidirectional flow, and limited reserves. BESSs show great potential to engage AS, stabilizing intermittent generation and increasing flexibility in balancing supply and demand. In addition, power electronic interfaces (inverters and converters) are enhancing their P-Q capabilities to provide AS by reactive power injections [36]. Although power electronic interfaces do not have the robust capacity curves of the synchronous generators, they can generate active and reactive power operating points in a range within a smaller P-Q curve.
Voltage regulation can be performed with BESSs and generators using an appropriate reactive power interface. Analogously, power losses can be reduced by reactive power injections, which adjust voltage-node profiles and reduce the total power losses. These services can be provided by an optimization strategy, in which, distribution losses and voltage deviation can be considered into the objective function as subject to Linearized PF Equations (9) and (10), ∀i ∈ N , where the objective function H is composed of two terms; the first one refers to the distribution losses (8), and the second term is a summation of penalties for voltage deviations in the nodes. Each form is weighted by parameters w l and w v . The decision variables are the voltages (V i ) and reactive powers of the generators and batteries (Q G i ). The voltages define an optimum operation point to minimize the objective function that can be reached through reactive power variation in generators. The PF equations (9) and (10) define the relationship between reactive power and the magnitude and angle of the voltages at each node. In (9), the active power is not a decision variable since it can be considered a fixed value, which is the solution of the economic dispatch. The constraints (12) - (14) are related to the reactive power restrictions of the generators, BESSs, and the magnitudes and angles of the voltages. These limits can be set up according to each region's electrical standards and regulatory aspects. From a practical point of view, most of renewable generators and BESSs have no rotational inertia, but some power interfaces enable them to maintain the voltage and frequency stability in isolated microgrids [37]. For example, some inverters can establish active and reactive power flows through power factor. The constraints in the operation point are respresented by a capability curve, which is given by [38] = cos −1 (PF), where PF is the power factor of the power interface, is the power angle, and P(t) and Q(t) are the active and reactive powers at the instant t. Notice that the maximum and minimum reactive powers are conditioned to the active power flow and depend on the PF.

IV. BATTERY DEGRADATION MODEL
Batteries enable the integration of PV systems in microgrids, increasing safety, flexibility, reliability, and quality by performing ancillary services. Energy management models allow performing ancillary services with batteries, like voltage regulation, frequency regulation, peak shaving, and flexibility in balancing supply and demand [4]. However, most of these models consider only basic ancillary services and only a few consider a battery degradation model. Then, current models lead to an incomplete overview of ancillary services enabled with batteries. Most of the energy management systems of batteries are based on policies if-then, which do not provide an optimal result. Consequently, batteries are charged when generation is high and discharged when generation is low, generating an overuse of BESSs. On the other hand, recent studies consider aging models as part of the energy management model to obtain the scheduling of charge/discharge batteries. Results show that including the effects of degradation reduces the cost of operation (15% approx.). Furthermore, charge/discharge actions are significantly affected, reducing the number of cycles performed per day but maintaining the amount of energy exchanged [39].
A promising research field includes proposing strategies to mitigate the battery degradation while undertaking other issues such as time-consuming, in-line execution, providing ancillary services, and testing different optimization algorithms [22], [40]. However, little attention has been paid to the reliability and accuracy of the battery degradation model, which leads to batteries to work in non-optimal operating points. Moreover, many degradation models are not validated in practice or are only based on battery datasheet curves like the cycle-vs-DOD (depth of discharge) charts, which are obtained under controlled testing conditions instead of real scenarios. Although a few studies validate the battery degradation models, most of them are too complex to be integrated into some optimization problems [41] because they include discrete variables, discontinuities, or highly nonlinear terms.
We propose a new battery degradation model so-called Quadratic Ah-throughput, a quadratic model to estimate battery degradation for lead-acid and lithium-ion batteries. Besides, the model can be easily integrated into the optimization formulation to obtain fast solutions. Remarkably, the Quadratic Ah-throughput model is based on a structure validated in real scenarios with high accuracy on estimation. Furthermore, the proposed model allows the management system to assess the influence of battery aging in performing ancillary services, such as reducing voltage deviation, distribution power losses, and balancing supply and demand. In this case, the battery degradation model is incorporated in the tertiary control level, specifically in the cost function (7) as a penalizing term of aging.

A. QUADRATIC AH-THROUGHPUT MODEL
The proposed model is a quadratic version of the Schiffer model, described in [42], that maintains a high estimation accuracy. In numbers, the weighted Ah-throughput model of Schiffer had an error of 6% on assessment whereas other models (e.g. models based on cycles, DOD and energy exchanged) had the error above 60% [21] and [22]. Besides, VOLUME 11, 2023 given that Schiffer model is highly complex, we extract only the main features and variables to build a reliable scheme.
The quadratic Ah-throughput (QAh) is a differential model to calculate the total degradation (Q t (k)) or the remaining battery capacity up to instantk. The total degradation is calculated in terms of the past instant and the change of degradation (Q t (k − 1), Q(k)) at the instantk. The change of degradation is defined by two losses functions: f c (·) and f d (·), so-called cycle-loss function and DOD-loss function, respectively. The QAh model is described by The cycle-loss function is an exponential function in terms of the number of accumulated cycles C(k) up to instantk. Similarly, the DOD-loss function is quadratic on DOD D(k) at instant k. Due to the number of cycles and the DOD are slow-changing variables,k is a considerable large period to capture the variation of C(·) and D(·). In this sense,k can be a period of several hours or days (one day is a typical value).
The loss functions are defined by where both functions are fitted by coefficients (α 1 , β 1 ) and (α 2 , β 2 , γ 2 ). These coefficients are calculated by an optimization algorithm to maintain the estimation accuracy. The process requires a real value of battery degradation (Q r (t)), provided according to the Schiffer model ( [42]) for lead-acid batteries. For lithium-ion batteries, the real degradation value can be provided by experimental data. To observe the validity of the proposed model, the real value is compared to the estimated value of battery degradation calculated by the QAh model in (16) and (17). Both degradation models, Schiffer and (16), are mapped for a range of values of DOD (D m ) and number of cycles (C n ) conforming a 3D function, whereas the solution of the optimization problem calculates the coefficients (α, β, γ ). The optimization process is described by where the objective function corresponds to the quadratic error (ê) between real and estimated degradation values. The concavity of the problem eases the search of the optimal value, which can be found with any optimization tool. The QAh model extracts only the main features of battery degradation. Although some models are described by many variables such as temperature, battery voltage, discharge current, number of cycles, and SOC (state of charge), only a few variables considerably influence the degradation. This simplification can be observed in similar models which use only one or two variables, mainly SOC, DOD, and cycles [21]. In this case, the QAh model uses DOD that captures the minimum value of SOC and represents the corrosion and degradation effect. Whereas, the number of cycles directly represents the effect of degradation. Moreover, the product of both loss functions (17) allows us to represent the lost capacity for a specific DOD according to the number of accumulated cycles at an instantk. This approach is similar to the Throughput models of [21] but represented in a quadratic form (19).
Other models described by one o two variables are inexact because they are only based on battery datasheet curves. Hence, they are tuned according to test cycles performed by the manufacturer. So, these models do not consider other degradation boosting factors such as voltage levels and discharging currents. Despite of the QAh model is a two-variables model, it is tuned according to the Schiffer model for lead-acid batteries, regarding all degradation factors obtained under real operational scenarios.
The QAh model is integrated into the active power dispatch problem in the degradation cost functionF j (P G j ) in (7). The corresponding SOC for each battery profile P G j is calculated according to (5). Next, the battery SOC is used for calculating the number of cycles and the DODs occurring during a period K + 1 as shown the Figure 1. These variables are collected in a vector of cycles C j = [C 1 j , C 2 j , . . . , C j ], and its related vector of DODs where is the vector length. Using the results from (18) and (19),F j (·) is defined asF Then,F j (·) is the summation of the capacity losses reached during the programming period {1, . . . , K + 1} multiplied by the battery cost B c,j . It must be highlighted that the cycle is an accumulative variable that must be stored and updated in each optimization process, which is particularly important in a receding-horizon method.

V. DISTRIBUTED OPERATION BASED ON ADMM AND CONSENSUS DYNAMICS
A. PRELIMINARIES

1) ALTERNATING DIRECTIONS METHOD OF MULTIPLIERS
Alternating directions method of multipliers (ADMM) is an optimization technique that splits the global problem into subproblems that are individually solved. In addition, individual solutions interact in a coordinated way to find a solution to the global optimization problem [43]. From a technical perspective, this method can be understood as a mix that takes advantage of the benefits of dual decomposition and the augmented Lagrangian method to improve convergence.
To explain te general method, consider the following optimization problem with a separable objective function f (x) where x = [x 1 , x 2 , . . . , x N ], and x i ∈ R n are subvectors of x, A ∈ R m×n and c ∈ R m . Moreover, f i (·) are assumed to be convex, which is necessary to guarantee convergence. The augmented Lagrangian of (21) can be written as where y ∈ R m is the vector of dual variables and ρ > 0 is a penalty parameter. Besides, the last term in the summation is a regularization term that improves the robustness and the convergence rate of the algorithm. ADMM iteratively solves the N -agents problem in (21) with where the penalty term ρ is also the step size. Notice that the ADMM algorithm has one minimization step (22), and one updating step of the Lagrange multipliers (23). Then, the augmented Lagrangian is sequentially minimized in a process where (22) directs the solution towards the optimum in the x 1 -direction, then it repeats the process directing the solution in the x 2 -direction, and so on, until it reaches x N -direction. The procedure is repeated until convergence. This process leads the search for a global solution through alternating directions. The convergence of the method is guaranteed due to the convexity of the objective function (7) and the linearity of the constraints (3)- (6). Hence, we can obtain a Lagrangian function whose saddle point is the optimal point over the domain of the primal variables and the multipliers. This point satisfies the Karush-Kuhn-Tucker (KKT) necessary conditions, which are also sufficient since the objective function i∈N G F i (P G i ) + j∈N BF j (P G j ) is convex. It is worth noting that the global term in (23) requires a central aggregator to broadcast this information to the other N individual processors. The algorithm is not fully distributed because y is a global variable that is shared by all agents. The next section uses consensus protocols to distribute the global information.

2) ACCELERATED CONSENSUS PROTOCOL
Consensus protocols are iterative algorithms whose goal is reaching the same value in the nodes of the graph (generally, the average of the nodes' initial conditions), using only local information at each updating step. Given an undirected graph G = (V , E) consisting of a set of nodes V = 1, . . . , N and a set of edges E ⊂ V × V , with initial conditions λ 0 ∈ R N , the consensus protocol reaches the state (1/N )1 ⊤ λ 0 .
This section describes two consensus protocols: the widely used linear consensus protocol and an accelerated version of it [44]. The linear consensus protocol achieves average state following the updating rule for each node i ∈ V , where λ l i is the i th entry of the vector λ l and w ij = w ji is the weight associated with the edge (i, j) ∈ E. If we let W be the weighting adjacency matrix 1 of G, and defining W ∈ R N ×N as the matrix whose entries satisfies then the consensus protocol in (24) can be expressed in the compact form The accelerated consensus protocol (ACP) is a two-step algorithm where each node i ∈ V updates two variables λ l i , µ l i at each iteration l. The update rule is given by where µ l = [µ 1 , . . . , µ N ] ⊤ and µ 0 = Wλ 0 . The accelerated consensus protocol has a linear convergence rate, which is highly convenient to face multi-temporal problems as scheduling of batteries. More details of the accelerated consensus protocol can be found in [44].

B. ADMM AND ACP FOR SOLVING THE ACTIVE-POWER DISPATCH WITH BESSS
Our purpose is to use ADMM and ACP to obtain an optimal solution for the problem in (3)-(7) in a fully distributed way without a central connector node.
First, we define the augmented Lagrangian of (7) as where F i is the objective function of the i th generation unit (generator or BESS), Y is the Lagrange-multipliers vector, and E is a vector of power balance constraints (which need global information) given by Indeed, the elements of E correspond to the power balance in (3) for all K timeslots. The Lagrangian in (26) can be conveniently expressed to distribute its calculation as where Y and E can be calculated and distributed by a central agent. However, the exchange of information with neighboring agents allows the calculation of Y and E to be distributed by a consensus protocol, generating the correspondingly E i , Y i vectors for each agent. Algorithm 1 describes the fully distributed method based on ADMM and ACP. Iterations are denoted by superscript t and the stopping criteria is reached when the 2-norm of the vector E t i is less than the threshold error ϵ = 1 × 10 −3 .

Algorithm 1 ADMM for Active Power Dispatch With BESSs
where λ L i is the solution of the distributed algorithm (25) at time L, with initial conditions λ 0 i = P t+1 G 1 , . . . , P t+1 where L is the number of iterations at consensus is reached, which is tuned experimentally. Notice that the major issue in distributing the ADMM is the aggregated load profile P L in the vector E in (27), which is a global variable. Nonetheless, ACP generates an individual vector E i with local information, making it available for all agents of the microgrid.
The algorithm starts obtaining the optimal power profile for the i th generator or battery minimizing its corresponding augmented Lagrangian. In case of batteries, the power profile is an optimal charging/discharging actions profile. It is remarkable that in Line 1, each agent (a generator or a battery) proposes an optimal solution to minimize its corresponding local function sequentially and individually.
Line 2 shows how to share global information in a distributed way. First, the consensus protocol's initial conditions are loaded in λ 0 i for each agent and one of the agents must load the aggregated load profile P L . For instance, the last agent can load its initial condition as λ 0 N ← − P t+1 G N − P L . In any case, the aggregated load profile P L is only known by one agent. Conveniently, the proposed selection of the initial conditions leads the consensus to converge to the average of their initial states, which is precisely the vector E i divided by the number of agents N .
Note that the accelerated consensus in (25) returns an average state λ i , which corresponds to the average power balance for all time slots. Therefore, in Line 3, each average state is multiplied by N to obtain an estimated value E i . Finally, Line 4 shows the updating equation of the Lagrange multipliers for each agent. The optimal values P * G i := P t+1 G i ∀i ∈ N G ∪N B are reached according to the stopping criteria, where the Lagrange multipliers tend to be constant.

C. ADMM FOR SOLVING THE REACTIVE-POWER DISPATCH ENABLING ANCILLARY SERVICES
Similar to the previous section, the augmented Lagrangian is defined according to the objective function and the corresponding constraints, and finally, the solving algorithm is presented.
First, the H function in (11) is written conveniently to express as a sum of single functions So, the augmented Lagrangian of (11) is defined as where H i , Z i , U i are the objective function, dual variables and constraint vectors of the i th agent, respectively. The vector U i is given by The first term of U i is the constraint of active power flow in (9), which includes optimum in the first instant of the active-power dispatch (P 1 G i ) * found by the Algorithm 1. The second term is the constraint of reactive power flow in (10). Each constraint in the vector U i requires only local information since all constraints of U i are calculated over the set of neighbors N i . Algorithm 2 describes the proposed method to obtain the reactive power dispatch based on the ADMM. It works similarly to Algorithm 1, but it calculates the optimal profile of reactive power for generators and batteries by minimizing the augmented Lagrangian L q in (29). It is worth remarking that Algorithm 2 is completely distributed and does not need consensus.
Algorithm 2 ADMM for Reactive Power Dispatch 1: for t = 1 to T max do 2: Algorithm 2 starts finding the reactive power profiles for generators and batteries. Then, the Lagrange multipliers are calculated according to constraints U i with a q as step size. The optimal reactive power profiles Q * G i = Q T max G i , ∀i ∈ N G ∪ N B are reached at the maximum iteration T max when the Lagrange multipliers tend to be constant.

D. IN-LINE OPERATION APPROACH
The energy managing strategies of a microgrid must have the ability to respond to disturbances. The robustness feature is motivated due to some inputs to the algorithms are constantly changing, such as the load profile, solar irradiance, and wind speed, among others variables that have an aleatory nature. Although the low-level control hierarchy of a microgrid allows the system to respond to disturbances, it is crucial to deal with disturbances from upper levels to minimize the control effort at lowers levels.
The proposed approach to manage disturbances is based on feedback by measuring disturbances and updating control signals. The in-line operation relies on the ability of the algorithm to process all operations in a maximum time equal to the updating time. Figure 2 shows a scheme of the local monitoring system that allows each agent to measure local variables (power limits, voltages, active and reactive power, and disturbances) to perform the distributed processing. Then, the control signals are updated (active and reactive power setpoints) and the cycle is repeated continuously. To avoid the computational complexity, we use a control scheme that splits the programming period into two segments: short-term and long-term periods (see Figure 3). Based on the multi-horizon model predictive control (MPC) scheme in [45], we define a short-term period with k s time intervals of width k s . A long-term period with K time intervals is also used with an interval width K . Specifically, we propose that the measurements must be updated in the first interval of the short-term period. This multi-horizon scheme allows the management system to set a short sampling time k s to deal with disturbances. At the same time, it maintains a large horizon of programming, to preserve a reasonable computational cost. Notice that this combination enables a short sampling time with a low computational complexity because the long-term period uses fewer decision variables. It should be mentioned that this strategy reduces the computational complexity in return for an increase in the number of estimations. Although the horizon is divided by reducing the number of variables, the estimations must also be increased to the same extent. Then, the number of signal estimators must forecast the measured signals every short sampling time to obtain the estimated signals to run the algorithm along the programming horizons. Figure 3 illustrates the combination of short and large periods. Specifically, we use a long-term period of 24 hours with time intervals of 1 hour, typically used in dispatch problems. Besides, we use a short-term period of 1 hour of 5-minutes time intervals.
The concept of a two-period programming horizon is implemented to use the advantages of the short-term and long-term periods in the formulation of a new active dispatch problem as The objective function in (30) gathers the generation costs for the long-term period (F i ) and short-term period (F i ).
The active power profile for the short-term period is given . . ,P K s G i ], during a short-time interval K s = {1, 2, . . . , K s } with time intervals equal to k s . Similarly to (7), the cost function (F) is a cost function that captures the generation and storage cost during the short-time period. VOLUME 11, 2023 In adittion to long-term constraints (3)-(6), the constraints related to the short-term period are ∀k s ∈ K s . Similarly to constraints for the long-term period, equations in (31)-(34) represent the power balance, power limits, the SOC dynamics, and SOC limits, for the short-term.

VI. SIMULATIONS AND RESULTS
To show the implementation of the proposed method, first we present the presented the fitting of QAh-Throughput model for lead-acid and lithium batteries to be incorporated in the optimization model. Secondly, the case study to test the optimization strategy is described with all technical details about the microgrid. Next, the results of the active dispatch are presented, and a comparison of the distributed methods with a centralized one is performed in terms of the algorithm velocity and the optimal value. Furthermore, an analysis of the influence of the degradation model is presented considering three scenarios: i) without a degradation model; ii) considering only battery costs; and iii) with degradation model. The interaction of the lead-acid and lithium technologies and the lifetime extension achieved with the degradation model for both technologies is remarkable. Next, the ancillary services by the injection of reactive power are included with a quantitative comparison of the power losses and voltage deviation. Finally, disturbances management by the in-line operation is presented, whose benefits are quantified in terms of the reduction of computational effort and the error between demand and generation.

A. TUNNING OF DEGRADATION MODELS FOR BESS
To incorporate the degradation models in the planning of charge/discharge actions for BESSs, we have tailored the proposed model according to experimental data in [46] and the empirical weighted Ah-Throughput model in [21]. Specifically, the Ah-Throughput model can be fitted for lead-acid and lithium-ion batteries from curves of capacity vs. cycles with other DODs, aging experiments, or manufacturer information. Besides, the proposed solution method can get a fast solution because it is convex on DOD.

1) LEAD-ACID BESS
We tune the model according to the weighted model [21], which is accurate in estimating the capacity loss of lead-acid batteries. However, it is not suitable for real-time optimization due to its complexity. In order to obtain the coefficients of the QAh-Throughput model in (16) and (17), a fitting process is carried out regarding the data from the experimental Ah-Throughput model (See Figure 4). The obtained coefficients are α 1 = 0.4585, β 1 = 3.321, α 2 = 3.529, β 2 = −0.5762, γ 2 = 0.0283. The top of the Figure 4 shows the typical DOD vs cycle curve, where the error to predict the cycles for a specific value of DOD is about 7%. The bottom of the Figure 4 shows the remaining capacity for different values of DOD. The absolute error of the QAh-Throughput model is ±0.04, which corresponds to a percentage error of 1.1%.

2) LITHIUM-ION BESS
The fitting process of the QAh-Throughput model for lithium-ion batteries is carried out with real data from [46]. The model fitting is divided into zone a from 0 to 600 cycles and zone b from 601 cycles to 10000. Zones a and b show different behaviors that a unique QAh-Throughput model cannot represent. Zone a shows a nonlinear and significant decrease in capacity for the first cycles. In contrast, zone b describes a linear reduction of capacity with a low rate (see actual data in Figure 5).  Table 1 shows the fitting coefficients of the QAh-Throughtput model according to the experimental data of lithium-ion batteries for zone a and b. The comparison of the fitting and experimental data is shown in Figure 5. The model represents the capacity behavior for both a and b zones with an absolute error of ±0.0087, representing an 1.6%.

B. CASE STUDY
The microgrid simulated is based on the test feeder IEEE 13 bus system with voltage level of 4.16 kV (see Figure 6). Comparison of actual data from [46] and QAh-Throughput model for a lithium-ion battery.
In order to analyze the interaction between renewable energy and storage resources in an isolated mode, we include a diesel generator (G 1 ), a photovoltaic generator (G 2 ), a wind turbine (G 3 ), a lead-acid battery system (B 1 ), and a lithium-ion battery system (B 2 ). The diesel unit is the slack generator that provides the voltage and frequency references. It is worth mentioning that the location and size of generation units are established according [47], to minimize generation costs, power losses, and voltage deviations. The electrical lines between nodes are solid, while the communications channels between agents are dashed lines. Table 2 details the capacities and costs for generators and storage systems. The maximum limits of reactive power are calculated according to the generation unit's power factor in (15), according to the active power available at a specific instant. Figure 7 shows the aggregated load profiles of the active and reactive power, which correspond to actual data of one-week power consumption of a university campus in the Southwest Colombia. The individual load profiles for each node are obtained by dividing the aggregated profiles according to the nominal capacity of each load in Table 3. The solar irradiance and wind speed profiles are shown in Figure 8, which are 7-days real measurements obtained in    June of 2021 with a meteorological station located in Pasto -Colombia. Figure 9 shows the active power dispatch obtained with ADMM-ACP (ADMM with accelerated consensus protocol). Clearly, the cheap solar and wind generators (G 1 and G 3 ) are dispatched to their maximum capacity, while the batteries are charged and preserved to provide cheap energy in the rush hours. The expensive diesel generator (G 1 ) completes the rest of the power to supply the aggregate demand in the system. Besides, all active power profiles are within the limits and the power balance is accomplished properly. The performance of the ADMM-ACP is compared with a centralized method (sequential quadratic programming -SQP), the ADMM with aggregator, and the ADMM with consensus (ADMM-C),  without substantial differences between power profiles as it is shown in Table 4. This fact is particularly important since the centralized algorithm relies on complete information to reach the result, while the distributed algorithms uses only local information to achieve the same optimal value. Figure 6 depicts in dotted lines the links of communication between neighbors to perform the distributed techniques.

C. ACTIVE DISPATCH WITH BESS
To guarantee the same effort in the optimization process, we define as stopping criteria the error of the power balance lower or equal to 1 × 10 −3 for the distributed methods. Table 4 also shows that the optimal cost values are the same for all methods with a slight difference for ADMM-C. However, the centralized process is less time-consuming than the distributed ones since ADMM updates variables one by one, whereas the centralized method updates all variables simultaneously.
On the other hand, there are essential differences between the convergence time of distributed methods. The ADMM-C and the ADMM-ACP are faster than the classic ADMM with the aggregator. Besides, notice that the ADMM-ACP and the ADMM-C need the same iterations to converge, but the first one uses less time. This difference occurs because ADMM-ACP only needs 20k iterations to reach the consensus, while ADMM-C needs three times more iterations (60k). This reduction of the consensus iterations could be particularly significant in an actual implementation, where the communication delays play an essential role.

D. EFFECTS OF THE DEGRADATION MODEL IN THE SCHEDULING OF BATTERIES
Three test scenarios are defined to compare the degradationmodel effect on the optimization process. Scenario 1 is the base case and it considers the batteries as free-of-charge units, i.e., the costs of energy discharged by the batteries are not considered in the optimization function. Then, both units are treated as equals in the optimization process. Scenario 2 regards a price by energy discharged of the batteries with the costs presented in Table 2. In economic terms, the batteries are treated as generators, and their energy costs are considered in the optimization function. Finally, Scenario 3 regards only degradation as a penalization term in the optimization function. The batteries' energy costs are not considered.  Figure 10 shows the evolution of batteries' capacity for the three scenarios. From the overall view, the differences between loss-of-capacity curves of lithium-ion and leadacid battery technologies are evident. As expected, the loss of capacity of the lithium-ion battery decreases slowly in comparison with lead-acid technology. In contrast, lead-acid battery capacity decays rapidly and must be replaced several times for Scenario 1 during the time horizon. Table 5 shows the weeks to end-of-life (EOL) for the three scenarios for each technology. Furthermore, taking as reference the end-of-life of the lithium-ion battery, the table shows the number of replacements of lead-acid batteries per scenario. Clearly, the optimization results in Scenario 3 show that the degradation model significantly expands the batteries' lifespan. According to Table 5, the EOL of the lithium-ion battery increases a 38% and a 72% concerning scenarios 1 and 2, respectively. Likewise, the EOL of the lead-acid battery increases a 158% and a 72% in comparison to scenarios 1 and 2. Moreover, the number of replacements of the lead-acid battery required in Scenario 3 are reduced to the half compared with the base case (Scenario 1). This important increase in the lifespan of the batteries can be explained by the charging/discharging pattern of the batteries.  Figure 11 shows, in Scenario 1, that both batteries are discharged to similar DOD levels without considering a difference in technologies. This discharging levesl lead to rapid degradation of the lead-acid battery compared to the lithium-ion technology as it is presented in Figure 10. In contrast, Scenario 2 reduces the DOD of lead-acid technology as a result of the economic power dispatch, which expands the lifespan of both battery technologies in comparison with the base case. However, a significant increment in the batteries' life is obtained regarding the model degradation in Scenario 3. To reach this increase, the degradation model reduces the DODs of both batteries and increases the number of cycles, as it is shown in bar graph of Scenario 3 in Figure 11. Furthermore, at the same time, the load's energy requirements are fulfilled. Besides, it is worth highlighting that the degradation model adjusts the DOD according to the state of degradation of the battery along the time, as it is shown in Figure 12. At the start of the battery life (in the first week) lead-acid battery has a deeper degradation rate than lithium-ion technology. As a result, the lead-acid has a higher DOD than the lithium-ion battery in the first weeks. On the contrary, at the EOL of batteries (at weeks 750 and 240) the DOD is higher for lithium-ion batteries than lead-acid ones. This effect occurs because the lead-acid battery has a higher rate of degradation than lithium-ion technology at EOL.

E. REACTIVE DISPATCH AND ANCILLARY SERVICES
Algorithms 1 and 2 perform jointly the optimal power flow of the IEEE 13-nodes microgrid in a distributed fashion, guaranteeing that the main variables are within the proper ranges. Figure 13 shows the reactive power of each generation unit with their respective power limits in dashed lines. Notice that reactive power limits of each generator are calculated according the active power available by (15). Specifically, the power factor of each power interface defines the ability to absorb or generate reactive power. This feature is known as the capability curve. Moreover, the last graph of Figure 13 shows the comparison of total reactive generation and the aggregated reactive demand, whose balance is fulfilled.  In this case, the reactive dispatch enables the ancillary services of reducing power losses and voltage deviation, by using the optimization function (11). Figure 14 shows the influence of reactive dispatch in reducing the voltage deviation (VD). The continuous line shows the VD using only the slack generator (G 1 ) to fulfill the reactive power demand. Whereas the dashed line shows the VD when the other generation units are enabled to adjust the reactive point operation. Notice that the improving of VD is remarkable. For example, the VD in nodes 611, 652, 671 and 680 are 47.9%, 47.1%, 43.1%, 43.1%, respectively, and a 26% in average for all nodes.
On the other hand, Figure 15 shows that power losses are also reduced by reactive power dispatch. In numbers, the power losses are reduced 22.9% by the reactive injections of renewable generators and batteries, which are limited by their capability curve.

F. IN-LINE OPERATION
The proposed in-line scheme is based on a receding horizon strategy capable to update the active and reactive power dispatch to response to disturbances. The programming horizon is split in two programming periods: the long-term is 24 hours with hourly slots, and the short-term is 5 minutes with one slot. Users could tune these features according to the available computational capacity and the size of the microgrid. The in-line scheme is suitable to solve the active dispatch with batteries because the long-term period allows the system to anticipate the battery scheduling. Similarly, a long-term period enables batteries to displace energy from valley hours to rush hours and eases the measurement of the batteries' degradation. At the same time, the short-term period allows the management to response to disturbances by changes in the load and resource profiles.
To test the in-line scheme, we define a load disturbance adding noise to the load profile ( Figure 16). The noise is obtained from a normal distribution with variance equal to 10% of the maximum value of the load profile. Similarly, the disturbances of wind speed and irradiance are obtained following the same criterium. Notice that Figure 16 shows two estimated profiles: hourly and 5-minutes curves, which are estimations of the actual power demand curve. The system can use sophisticated forecasting tools to obtain more exact predictions [48]; but in any case, both curves are used to build the two-level programming horizon as it is shown in the bottom of the Figure 3.
In-line operation requires additional steps to solve the OPF problem over a receding horizon. Firstly, power demand, wind speed, and irradiation profiles are loaded to make the corresponding estimations according to the programming horizon. Second, the first instants of the profiles are updated by real-time measured data in the short-term and long-term periods. Next, Algorithm 1 solves the active power dispatch problem in (3)-(7) obtaining the generation units' power profiles for the programming horizon. Then, Algorithm 2 solves the reactive power dispatch problem in (11)- (14). At this point, the OPF is solved, and the first setpoints of the active and reactive power profiles are sent to secondary and primary controllers to be used as references. Finally, the programming horizon is displaced to the next instant, the SOCs of batteries are updated, and the process starts again in the first step. In summary, Algorithms 1 and 2 run every short-term period, the active and reactive profiles are updated according the programming horizon, batteries' SOCs are updated, the programming horizon is displaced, and the cycle is repeated.  Figure 17 shows the results with in-line scheme. Notice that all generation units modify their dispatches to satisfy the new power demand. The dotted lines represent the variation of the dispatch profiles during the running of the in-line scheme. Variations are proportional to the noise added to the power demand curve, wind speed profile, and irradiation profile. Similarly, this variation causes G 2 not to be dispatched to the maximum power because of the estimation error. Figure 18 shows the power balance error between generation and power demand. The graph in the top shows the error for the day-ahead dispatch, and the one in the bottom shows the error obtained with the in-line scheme. The error is reduced because the in-line method corrects the generation units' dispatch, although it does not disappear entirely because the in-line scheme takes a while to get the results. Specifically, graph in the bottom shows the error while the in-line algorithm is processing; during this short time, the power balance error still exists. In numbers, the average errors without and with the in-line scheme are ±83.05 kW and ±0.346 kW , respectively. In any case, these errors are zeroed by the secondary and primary controllers of the microgrid hierarchy, but the control effort is significantly minor with the in-line scheme.
Another worth-mentioning benefit is the computational complexity reduction. In this case, a conventional receding horizon strategy (as MPC) uses a whole programming horizon of 24 hours with time slots of five minutes, i.e., 288 variables per generation unit. Under the same conditions, the in-line scheme requires 24 variables for the long-term period and one additional variable for the short-term period per generation unit. Running both strategies in a computer with a processor Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz, we obtain that the MPC takes 52.53 seconds per iteration, whereas the in-line scheme takes 4.72 seconds.

VII. CONCLUSION
A distributed algorithm based on ADMM and consensus is presented to obtain an OPF of microgrids with distributed resources. The algorithm provides ancillary services with batteries and renewable sources. The reduction of voltage deviation and power losses by reactive dispatch are tested by simulation. Finally, the algorithm incorporates degradation models for two battery technologies to extend their lifetime and an in-line scheme to deal with inputs disturbances.
The ADMM-ACP is a strategy to solve the OPF of a microgrid with a performance comparable to conventional ADMM but without an aggregator to share global information. ADMM-ACP is a fully distributed optimization scheme that relies on local information converging to a global optimum. These optimization schemes are suitable in scenarios with multiple agents where it is valuable to limit the sharing of information, manage the bandwidth communication network of a microgrid, reduce the centralized processing, and perform plug-and-play features, among others.
On the other hand, we present a degradation model that, using experimental data or datasheets, can be adapted to both lead-acid and lithium-ion technologies with a short estimation error. Battery capacity loss is a feature sensitive to DOD and charge/discharge actions and knowing this condition could be significant to preserve the battery life by proper scheduling.
Finally, the in-line operation reduces the computation complexity of batteries' active-power-dispatch problem. At the same time, this time division allows the algorithm to deal with disturbances in a short-time horizon and to schedule batteries for the long term by a multi-horizon strategy.

APPENDIX A PF LINEARIZATION
Considering some approximations such as V i , V j ≈ 1, sin(θ) ≈ θ, cos(θ) ≈ 1. The Equation (1) can be rewritten as Assuming the angle differences between neighboring buses are small, the approximations in Equation (35) are Now, we define an admittance matrix Y ij = G ij + jB ij with the following structure Y ij = −y ij j ̸ = i y ii + j∈N i y ij j = i, (37) where y ij = g ij + jb ij is the admittance of line (i, j), and y ii = g ii + jb ii is the shunt admittance at bus i th .
Then, using Equation (37) and expressing V as 1.0 + V , the first term of Equation (36) becomes Note that V i is smaller than V i , so V 2 i and V i V j can be neglected in the approximation process. Using the admittance matrix, Equation (38) is compacted as

VOLUME 11, 2023
Following a similar process, we can approximate the second term of Equation (36) as To accomplish a successfully variable decoupling and linearization of power flow, we prioresse the influence of angles over voltages in Equation (40). So, using the approximations in (39) and (40) the active power flow in (35) is expressed in a linear fashion as In a similar way, the reactive power flow in Equation (2) can be established as