Distributed Stochastic Model Predictive Control for Scheduling Deterministic Peer-to-Peer Energy Transactions Among Networked Microgrids With Hybrid Energy Storage Systems

The current tendency toward increases in energy prices makes it necessary to discover new ways in which to provide electricity to end consumers. Cooperation among the various self-consumption facilities that form energy communities based on networked microgrids could be a more efficient means of managing the renewable resources that are available. However, the complexity of the associated control problem is leading to unresolved challenges from the point of view of its formulation. The optimization of energy exchanges among microgrids in the day-ahead electricity market requires the generation of an optimal profile for the purchase of energy from and sale of energy to the main grid, in addition to enabling the community to be charged for any deviation from the schedule proposed in the regulation service market. Microgrids based on renewable generation are systems that are subject to inherited uncertainties in their energy forecast whose interconnection generates a distributed control problem of stochastic systems. Microgrids are systems of subsystems that can integrate various components, such as hybrid energy storage systems (ESS), generating multiple terms to be included in the associated cost function for their optimization. In this work, the problem of solving complex distributed stochastic systems in the Mixed Logic Dynamic (MLD) framework is addressed, as is the generate of a tractable formulation with which to generate deterministic values for both exchange and output variables in interconnected systems subject to uncertainties using hybrid, stochastic and distributed Model Predictive Control (MPC) techniques.


P
Electric power (W ).P Predicted electric power (W ).P(S)) Given probability for a certain scenario.

I. INTRODUCTION
The majority of developed countries are currently adopting new energy policies based on commitments to the Paris Agreement with the aim of reducing greenhouse gas emissions by transitioning from fossil fuels to other energy sources.In the face of the challenge of creating low/neutral carbon-based energy systems, microgrid technology may be a key solution by which to update traditional electric power systems to intelligent smart grids with a high degree of penetration by renewable energy systems.The lack of dispatchability of the new renewable generation schemes can be solved by structuring the power system components into smaller management units.In this challenging paradigm, microgrids are a key technology with which to solve system deficiencies.Microgrids pave the way toward the deployment of an electricity market that is completely based on renewable generation, providing the flexibility required in order to balance the stochastic behavior of generation sources and consumption loads for both market and system operators.Microgrids also could empower the role played by end users by allowing them to become active prosumers.As stated in [1] and [2], the combination of different energy storage technologies provides a high degree of flexibility and competitiveness to microgrids, since each Energy Storage System (ESS) has its own limitations or operational costs which can be improved if an appropriate control system is developed.The inclusion of these advanced controllers increases the number of constraints and variables to be optimized, along with the complexity of the control problem and the necessary computational cost.The networked operation of microgrids adds a degree of flexibility to their optimization, leading to better operation results in the electricity market, as shown in recent studies [3], [4], [5].Different prosumers can share their energy in local markets while participating in the day-ahead electricity market.This joint operation could achieve lower final costs for the electricity consumption required.But the networked operation of microgrids must confront the complexity of optimizing interconnected stochastic systems subject to penalties for deviation if the commitment made to the day-ahead market is not fulfilled.The incorrect and/or uncertain management of one microgrid could, therefore, seriously affect the whole energy community.The optimization algorithm for energy communities based on microgrids should be formulated by considering a distributed and stochastic control problem of the system (network) based on interconnected subsystems (microgrids).Aspects related to increases in the execution time that will allow the solver to discover the optimal solution must also be considered when several scenarios are included, in order to integrate uncertainty into the forecasting of the energy produced by the microgrid [6].
It is consequently recommended that the networked operation or the uncertainty management be included only at the tertiary control level, where sample periods of 1 hour are taken, while the secondary control level be applied solely to a single microgrid that follows the references obtained in the tertiary control [7].Energy exchange among renewableenergy-based microgrids will provide the possibility of dispatching their production through electricity pools, not only as single systems, but also acting as a network of microgrids that achieve better results in liberalized electricity markets.The main feature of these markets is that the different actors have to make their offers in advance, and will be charged for any difference between real-time production and energy bidding [2], [6].In this context, the sale and purchase of energy among the different microgrids and the main grid must be subject to a common deterministic energy exchange, despite the stochastic behavior of renewable generation and consumption loads.As interconnected systems, those microgrids that decide to exchange energy with each other will have to incur economic penalties if the neighboring microgrid does not achieve the scheduled energy in the dayahead market.It is difficult to solve a deviation of this nature at the secondary control level, at which execution times close to real time are required.It is, therefore, necessary to obtain deterministic profiles not only at the tertiary level for the energy exchange with the main grid, but also for the energy that has to be exported from/imported to the neighboring microgrids.In order to solve these issues, procedures with which to obtain both a deterministic exchange profile among microgrids and a deterministic optimization of the buying and selling of energy with the main grid in the day-ahead market, despite the uncertainty in energy forecasting, are required.

A. LITERATURE REVIEW
The distributed and stochastic formulation for control problems when applied to systems with a large number of optimization variables, such as microgrids with hybrid ESS, requires the development of customized algorithms that can exploit the special features of their associated control problem, such as the limitation in the dimension of the matrices that current solvers can handle.As detailed in [8] and [9], MPC techniques are a powerful framework with which to solve the complexity of optimizing microgrids [10].Their hybrid formulation makes it possible to integrate logic and continuous decision variables [11], and stochastic MPC (SMPC) has, therefore, recently emerged with the aim of incorporating the probabilistic descriptions of uncertainties into a constrained optimal control problem [12].In a similar direction, Distributed Model Predictive Control (DMPC) [13] is being established as an advanced technique by which to optimally solve distributed control problems.A complete review of both SMPC and DMPC can be found in the aforementioned references [12], [13].The stochasticity of systems is being satisfactorily resolved using SMPC in several studies applied to a wide variety of systems.Theoretical analyses related to distributed stochastic MPC (DSMPC) have recently been carried out in [14], in which the problem of large systems composed of many coupled subsystems interacting with each other is analyzed, showing that the propagation and perturbation of uncertainty make the control design of such systems a complex problem.A theoretical framework with which to solve this kind of control problem is proposed.Firstly, the study establishes a centralized MPC scheme that integrates the overall system dynamics and chance constraints as a whole.Rather than solving a non-convex and large-dimension optimization problem at each moment, a semidefinite programming problem is stated.The computational cost and the amount of communication derived from a centralized framework are reduced by developing a DSMPC based on a sequential update scheme.This signifies that only one subsystem updates its plan by solving the optimization problem at each instant in time.
With regard to microgrids, recent reviews concerning the application of MPC techniques to this kind of systems can be found in [8], [15], and [16], in which no solutions are provided for common distributed and the stochastic formulation of complex optimization problems.It is particularly notable that aspects concerning deterministic exchanges among agents in distributed solutions are not addressed.SMPC and DMPC are recent and timely techniques that are being satisfactorily applied by the scientific community in order to manage possible errors in the energy forecast of microgrids and to deal with the formulation of control problems associated with interconnected microgrids, as shown in [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], and [17].In [18], the authors carry out a review of networked microgrids from fundamental to advanced research topics, while in [19] a review of the proposed solutions for P2P energy exchanges among microgrids is carried out.Three common gaps in the research developed in [18] and [19] can be highlighted: i) the non-inclusion of uncertainties in the energy forecasts for microgrids, ii) the fact that the cost functions developed do not integrate a large number of terms, as occurs when hybrid ESS are included in the networked operation of microgrids, and iii) the fact that they do not establish deterministic outputs and exchanges among the different subsystems, despite their inherited stochastic nature.In [3] and [20] algorithms based on Distributed Model Predictive Control (DMPC) techniques are applied without considering uncertainty in the energy forecast.Solutions considering uncertainties in the Energy Management System (EMS) of networked microgrids can be found in [21] and [22].The authors of [21] propose a model in which peers negotiate together in order to trade energy and flexibility by considering renewable generation uncertainty.In [23], the authors propose a P2P local electricity market for the joint trading of energy and uncertainty using flexible loads.A new P2P model in which both energy and uncertainty can be traded is proposed in [24], while aspects related to cybersecurity in P2P-based energy management are studied in [25].A consensusbased approach for the day-ahead market in conjunction with a local energy-reserve market design considering the uncertainties of renewable energy systems is studied in [26].The authors of [27] developed a two-stage robust stochastic scheduling model for transactive energy-based renewable microgrids.In the first stage problem, all the microgrids attempted to maximize their profits by adopting the optimal bidding strategy in the day-ahead market, while minimizing the imbalance cost in the second stage.In [28], the uncertainty of the electricity market is managed using a robust data MPC framework for multi-microgrid energy dispatch.In [29], the operation management of cooperative microgrids was formulated in the Chance-Constraint MPC framework, while in [30] the degradation cost of batteries was also included in the EMS, highlighting the importance of this term.The authors of [31] developed an optimal stochastic day-ahead scheduling problem.The stochastic analysis of the problem includes the day-ahead energy price as an uncertain parameter, while aspects of the operational cost of the ESS are not included.In [32], the authors introduce distributed microgrids integrated with buildings by taking advantage of their peak load limiting.The proposed algorithm is formulated as a two-stage stochastic problem: in the first stage, the temperature setpoints of the buildings for the next time step in each microgrid are determined, while in the second, the power exchange decisions made in order to limit the peak load in the microgrid network are defined.The work carried out in [33] is focused on the stochasticity of the multi-microgrid environment, proposing a distributed power management algorithm with which to minimize a sum of generation cost objective function subject to generator constraints, including the following: supplydemand balance constraint, individual constraint, capacity constraint and the ramp-rate constraint.Finally, case studies based on IEEE 30-bus, IEEE 57-bus and IEEE 300-bus systems show the effectiveness of the proposed distributed primal-dual consensus strategy.In [34], a distributed demand side management (DSM) approach for smart grids that takes uncertainty in wind power forecasting into account is developed.A two-stage stochastic optimization with which to operate a renewable-based microgrid with batteries is developed in [22], but the problem of the interconnection of microgrids is not addressed.Stochastic methodologies with which to solve resilience problems in single microgrids are also proposed in [35], [36], and [37].
Distributed Stochastic approaches that are applied to systems other than microgrids are additionally found in the existing literature, as can be observed in [38] and [39].In [38], the authors investigate the distributed output-feedback tracking control for stochastic nonlinear multi-agent systems with time-varying delays, and propose a new distributed stochastic homogeneous domination method.The authors specifically design distributed output-feedback controllers for the corresponding nominal systems.The proposed methodology simultaneously considers time-varying delays, unmeasurable states, and Hessian terms.The authors of [40] focus their research on enabling multiple agents to cooperatively solve a global optimization problem without a central coordinator by using a decentralized stochastic optimization in which aspects of sensitive information are considered.A decentralized stochastic optimization algorithm that is able to guarantee provable convergence accuracy, even in the presence of aggressive quantization errors that are proportional to the amplitude of quantization inputs, is proposed.In [41], an innovative data-driven robust model predictive control for irrigation systems is proposed.The paper integrates both first-principle models in order to describe dynamics in soil moisture variations, and data-driven models with which to characterize the uncertainty in forecasting errors from historical data.The precipitation forecast errors are analyzed, along with the dependence of their distribution on forecast values.In [39], a DSMPC framework is proposed using a stochastic cooperative game-based assistant fault-tolerant control for distributed drive electric vehicles, considering the uncertainty in driver behavior.The control algorithm considers the interaction among the driver, automatic steering, and in-wheel motors.SMPC techniques are also applied to HVAC systems for energy-efficient buildings in [42].A common gap in the aforementioned references related to DSMPC concerns the formulation of DSMPC problems, with cost functions that integrate a large number of terms.A framework with which to obtain deterministic behavior of the exchange variables is not addressed either, despite being an important aspect in the common optimization of networked microgrids in the day-ahead electricity market, as explained previously.The gap regarding the development of optimization methods for complex interconnected stochastic subsystems is again found in [38] and [39].
New control schemes with which to confront the computational burden that the interconnection of stochastic complex subsystems produce (as occurs in microgrids with hybrid ESS) are therefore required, in which the decomposition steps are defined in the optimization problem in order to make them feasible for normal computing devices.

B. MAIN CONTRIBUTIONS
As discussed in [6], the flexibility of the participation of microgrids in electricity markets can be enhanced by the use of hybrid ESS.The aforementioned authors confront the optimization problem of integrating different types of ESS subject to the inclusion of different economic criteria, such as degradation and lifetime issues for each ESS, start-up costs, etc., and also that of considering uncertainties in the energy forecast.However, the methodology developed is applied only to one microgrid, without considering the case of energy exchange among different microgrids subject to uncertainties in the energy forecast.
The distributed optimization of day-ahead market participation for interconnected microgrids should confront a distributed formulation of complex single problems, integrating the operation cost of each microgrid component subject to the inherited stochasticity of the energy forecast and thus confronting the problem of avoiding penalties for deviations from the regulation service market.According to the literature review, while the stochasticity of energy generation within microgrids, along with their common participation in the electricity markets, are topics that have been considered in previous work related to energy trading schemes, the coupled problem of not achieving the energy schedule of the day-ahead market in a common operation of two microgrids owing to the connection of two stochastic systems has not been studied.The same can be said of the networked operation of microgrids with hybrid ESS when considering stochastic energy forecast scenarios.
The work described herein expands on the methodology introduced in [3], in which the networked operation of microgrids was solved using DMPC techniques, but by considering a deterministic profile in the energy prediction.It also achieves an advance in the state of the art with respect to [6] by considering energy exchanges among microgrids, despite uncertainties.As indicated in [3], the high number of constraints to be introduced into the controller makes it unfeasible (using standard computing hardware) to solve the network optimization problem in a centralized manner when more than two microgrids are involved.A problem related to the computational burden is similarly found in [6], in which more than two scenarios are considered in the stochastic optimization problem of a microgrid with hybrid ESS.The aim of this work is to propose a tractable methodology with which to manage two scenarios and two microgrids in the same optimization problem.The principal innovative results obtained are that, despite the uncertainty in the energy forecast that is considered, a deterministic energy schedule is obtained for both the purchase/sale of energy with the main grid and the energy exchange with the neighboring microgrid.The algorithm is developed using stochastic and distributed MPC techniques and mixed-integer programming.
The following features of the proposed methodology are considered to be the main contributions of the present work: • The development of a framework with which to optimize energy trading processes among networked microgrids, considering the stochasticity of both energy generation and load consumption, thus achieving deterministic energy exchanges among microgrids and enhancing their operation when compared to acting as individual microgrids.
• The generation of deterministic outputs in interconnected stochastic subsystems.
Fig. 1 shows a schematic overview of the kind of energy community on which this work is focused.As can be seen, each microgrid can be composed of internal loads and different renewable generators.Both loads and generators are drawn inside a cloud so as to highlight the inherited uncertainty in the energy forecast of these components of the microgrid.Each microgrid also integrates batteries and hydrogen as ESS that are not subject to uncertainties in the forecast of their behavior.

C. OUTLINE OF THE PAPER
The remainder of this paper is organized as follows: The controller, formulated as a Stochastic Distributed Model Predictive Control (SDMPC) in order to include the uncertainty of the energy forecast, is developed in Section II, which also describes and justifies the operation cost associated with each storage technology used in the microgrid.The results obtained are discussed in Section III and the main conclusions are summarized in Section IV.

II. P2P STOCHASTIC OPTIMIZATION OF DAY-AHEAD MARKET PARTICIPATION
The microgrid controllers are designed in order to optimize the day-ahead participation of the network of microgrids such as those shown in Fig. 1 in the electricity market through P2P energy exchanges according to the following criteria: 1) Economic Optimization: The microgrid controllers integrate the operational costs of the microgrid components into the model simultaneously with the electricity market prices.2) Uncertainties Management: The controller is formulated to include the stochasticity of renewable generators and consumers' behavior.3) Deterministic Energy Exchanges: It is assumed that, independently of the stochastic nature of the energy forecast for each microgrid, the engagement of energy exchange must follow a deterministic profile that is completely independent of uncertainties as regards energy exchange with either the main grid or the neighboring microgrid.The block diagram of the proposed controller is shown in Fig. 2. Each block is detailed in the following sections.

A. GENERIC FORMULATION OF THE DSMPC CONTROLLER
The optimization problem for a system of interconnected stochastic subsystems, considering deterministic output variables and exchange variables among the different subsystems, can be generically formulated as indicated in the expressions (1)- (13).The first expression (1) corresponds to the cost function of a distributed and stochastic system using a multi-scenario formulation [3], [8] as the methodology with which to consider the uncertainties in the energy forecast.As will be noted, it is expressed in such a way that all the sample instants of a scheduling horizon SH are added together.The subindex i is utilized in order to mention each microgrid inside the network N .The upper-index [S i ] is used to reference each of the scenarios considered.As can be seen in ( 1), the nomenclature global is used for the global optimization problem derived from the network of interconnected subsystems, while the nomenclature local is employed to refer to each local optimization problem for each of the subsystems.The logic control signals are expressed as δ [S i ] i (t), while the continuous signals are integrated with u [S i ] i (t).The state variables are denoted by x [S i ] i (t) and correspond to those model variables whose value at each sample instant depends on the previous one.The nomenclature z [S i ] i (t) is used for the mixed product [11] of logic and continuous variables.Finally, v i→j (t) represents the exchange variables between a generic subsystem i and a generic neighbor subsystem j.The expressions (2)-( 7) represent the corresponding constraints related to the upper and lower limits of the variables that integrate the model of the plant, while the expressions ( 11)-( 13) concern the plant model constraints among variables using its state-space representation by employing the MLD framework [11].As will be noted, the model of the plant also includes its output variables (see expression (12)), which are labeled as y i (t).Note that in order to achieve a deterministic value for both the output variables y [S i ] i (t) and the exchange variables v [S i ] i→j (t), the constraints ( 9) and ( 10) are introduced because these kinds of variables do not depend on the scenario S i considered.The matrices A i , B i , C i , D i and E i represent the relationships among the different variables that integrate the plant model.Finally, P(S i ) denotes the probability of each given forecast scenario.As introduced in [3], the first term of the cost function (1) penalizes the exchange variables values so as to consider the transport losses resulting from power flux among microgrids. min subject to: Asumption 1: As mentioned in section I, the execution time required by the solver to find the optimal solution increases with the number of decision variables.

VOLUME 12, 2024
Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.
Asumption 2: while the number of decision variables increases with the number of subsystems and scenarios considered.
Asumption 3: Both subsystems can act as single and non-interconnected subsystems which are, in this case: v [S i ] i→j = 0. Asumption 4: In the case of obtaining v [S i ] i→j ̸ = 0, the value of J global is lower than the value of J global if the problem is constrained with v [S i ] i→j = 0.In order to reduce the number of scenarios in [6], an uncertainty band is used to introduce the stochastic behavior of the system by applying a mean deviation to a deterministic mean scenario S i = 0, thus generating a positive and a negative scenario S i = +, −.A method with which to conform the best couple of subsystems at each iteration is similarly followed [3].In both methodologies, the problem is decomposed into the following steps: Step 0. Peer-to-Peer optimization for the selected subsystems a and b, considering all the combinations of the possible deterministic scenarios.
For a number of possible scenarios N S a for the subsystem a, and a number of scenarios N S b for the subsystem b, the problem defined by expressions (1)-( 13) is solved by considering all the possible combinations of scenarios S a = 1, . . ., N S a and S b = 1, . . ., N S b , as specified in (14).Note that this simplification makes it possible to follow the procedure explained in [3], since the scenario is known at each iteration, signifying that the problem can be solved as a deterministic DMPC problem. min In this step, all the constraints defined in expressions (2)-( 13) are considered, with the exception of those defined in ( 9) and (10).The next set of optimal variables would be obtained after executing this step: After solving all the combinations of scenarios, the average profile for the exchange variables is obtained as follows: Step 1. Solving the problem for all the scenarios considered, independently for each subsystem This step calculates the value of the expectation i,local , taking into account the value of the local cost function for all the considered scenarios and constraining v [S i ] i→j (t) = 0.
In this step, all the constraints defined in expressions (2)-( 13) are considered.Note that in this step, the constraint ( 9) is included in order to achieve a deterministic value of the output variables for all the possible scenarios.After solving the problem defined in this step, the value of i,local for the optimal operation point for each subsystem working as a single system C <1> i,local is obtained.The upper index < k > refers to the iteration step. Step

Calculation of the expectation of the cost function for every single subsystem, considering exchange possibilities
This step solves the problem defined in ( 20) In this step, all the constraints defined in expressions (2)-( 13) are also taken into account.Note that although both microgrids are optimized independently, the exchange variables v [S i ] i→j (t) are considered and deterministic behavior is imposed on them (10).After solving this step, as occurred at Step 1, C <2> i,local is again obtained (note that this term evaluates only the corresponding value of i,local of the expression (20)). Step

Calculation of the expectation of the cost function for every single subsystem, considering exchange possibilities and constraining the local cost
The problem defined in Step 2 is again solved subject to the following constraint: Step

k. Calculation of the expectation of the cost function for every single subsystem, considering exchange possibilities and constraining the local cost, taking into account the previous result for the neighboring subsystem
This step solves the problem defined in ( 22) VOLUME 12, 2024 subject to: This step is carried out iteratively until the condition ( 24) is satisfied.
Note that if condition ( 24) is satisfied, the constraint related to the deterministic behavior of the exchange variables introduced in (10) for the stated problem before being decomposed into the proposed steps is also satisfied.The same is true of the constraint (8), which is related to the complementary behavior of the exchange variables between the subsystems involved.
Remark 1: The method is introduced for P2P optimization between two interconnected systems.In the case of a greater number of them, the procedure introduced in [3] to form the best couple at each iteration can be followed.

B. APPLICATION OF THE METHOD TO A CASE STUDY CONCERNING INTERCONNECTED MICROGRIDS WITH HYBRID ESS
The method explained above was applied to a network of microgrids with hybrid ESS composed of renewable generation, local loads, batteries, an electrolyzer, a fuel cell and a hydrogen tank.The block diagram of the case study for a network of just two microgrids is represented in Fig. 2.
The analog inputs of the plant u u u [S i ] are defined in (25). where i,dis are the setpoints provided by the microgrid Energy Management Systems (EMS) to the local controllers of the Battery Management System for the charging or discharging of the batteries.P [S i ]  i,elz and P [S i ] i,fc are similarly the control signals sent by the EMS to the internal controller of the electrolyzer and the fuel cell in order to set their power.The energy exchange with the main grid, purchasing or selling energy in the day-ahead market, are represented by P i,pur and P i,sale , which do not depend on the scenario S i considered owing to the deterministic behavior required for these variables.
The logic inputs of the plant δ [S i ] i are represented in (26).
where δ [S i ] i,ch and δ [S i ] i,dis are logic variables related to the charge and discharge states of the batteries.The electrolyzer and fuel cell have digital inputs related to their on/off-state (δ [S i ] i,elz and δ [S i ] i,fc ).As the start-up and shutdown processes lead to degradation issues in the elecrolyzer and the fuel cell, the auxiliary logic variables σ [S i ] i,elz and σ [S i ] i,fc are included in order to penalize these processes.The logic variables χ [S i ] i,elz and χ [S i ] i,fc are auxiliary variables that are employed in order to represent the instants at which the electrolyzer and the fuel cell are in the on-state, with the exception of those at which these devices are started-up or shut down.These logic variables are used to penalize fluctuant operations in the electrolyzer and the fuel cell, which also lead to degradation processes.
i,pur and δ [S i ] i,sale are logic variables associated with the purchasing and selling of energy with the main grid.The lower limit for all the logic variables is ''0'' and the upper limit is ''1''.The vector of mixed product variables in the plant is represented by (27). where i,α are the mixed products for the charging/discharging of the batteries, the electrolyzer, the fuel cell and the purchasing/selling of energy, respectively.The auxiliary mixed products ϑ [S i ] i,elz and ϑ [S i ] i,fc are obtained in order to represent power increments in the electrolyzer and the fuel cell at all their working instants, with the exception those at which they are started-up or shut down.
The dynamic state variables of the different microgrids are the energy level stored in the batteries, using their state of charge SOC [S i ]  i , and the level of hydrogen available in the hydrogen vessel LOH [S i ]  i , as shown in (28).
The exchange variables v i→j between the microgrid i and the microgrid j represent the exchange of energy P i→j at each sampling instant (29).
Finally, the output variables of the microgrids (y i ) are defined through the use of the energy transactions with the main grid P grid , as shown in (29).The cost function defined in (1) can be obtained using the expressions (30) and (31).Expression (31) corresponds to the case study of just one microgrid [6].In the aforementioned cost function, CC represents the capital cost of acquisition for each component of the microgrid.The term Cycles corresponds to the number of cycles of the batteries.As indicated in [2], high charge and discharge power ratios produce degradation processes which have to be penalized, as occurs in the terms associated with battery degradation, and these are quantified by Cost degr,α .The electrolyzer and the fuel cell lifetimes depend on the number of working hours Hours.Fuel cells and electrolyzers are also degraded by starting-up cycles and power fluctuations.These degradation mechanisms are penalized in the terms concerning the Hydrogen ESS Degradation.The last two terms in (31) are included in order to maintain the energy stored in each ESS at the end of the 44546 VOLUME 12, 2024 Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.
schedule horizon in a reference value.Note that only those values whose difference with the reference are negative are penalized. being, Grid Exchange Revenue&Cost(J grid ) The state-space representation of the plant (11) can be specifically defined for this case study by following the mathematical model introduced in [2], with (32) and (33), where C bat stands for the capacity of the battery, and η ch and η dis signify the performance factors for the charging and discharging processes of the batteries.η fc and η elz are similarly the performance factors in the conversion powerto-hydrogen carried out by the electrolyzer and the fuel cell.As can be seen in Fig. 3, the optimization of two interconnected microgrids is subject to different possible energy scenarios in each microgrid.The forecast module is based on the methodology described in [2].It employs the historical data of a meteorological station to obtain the array of forecast variables composed of the hourly prediction for the energy generated by the photovoltaic and wind turbine generators, along with the load consumption (d i = [ Pi,pv , Pi,wt , Pi,load ], where the subscript i is used to make reference to the microgrid i belonging to the network N ).As already stated in [6], the stochasticity of these variables is defined by including an uncertainty band in the predicted value of the variables.A positive and negative uncertainty band ( P un ) is, therefore, applied to an initial deterministic scenario (S i = 0) of the remaining energy prediction Prem in the microgrid, which is defined as ( Pi,rem = Pi,pv + Pi,wt − Pi,load + P un ) for the optimistic energy scenario considered (S i = [+]) and ( Pi,rem = Pi,pv + Pi,wt − Pi,load − P un ) for the pessimistic scenario considered (S i = [−]) for each microgrid.
As occurred in [6], the uncertainty band value P i,un is obtained using the expression (34), which is based on the average standard deviation between the value of the predicted remaining power for the microgrid and that which is measured, applied to each hour and each day for a complete year, although other methods could also be applied to the proposed algorithm [6].The terms day and h refer to the day and the hour that the standard deviation is calculated, with Pi,rem (day, h) being the predicted value for the remaining power in the microgrid, while P meas i,rem (day, h) is the measured value.The forecast algorithm also calculates the energy prices for the actions of purchasing and selling power in the day-ahead market ( (t) = [ pur (t), sale (t)]).
The expression for the plant model output variables (12) can be particularized to the case of the microgrids that are the object of this study by means of the difference between the purchased and the sold energy in the day-ahead market with the main grid.The energy exchange with the main grid is the result of the power balance obtained for each scenario at each sample instant (36) using the following values K [+]  = 1, K [−]  = −1, K [0] = 0, as done in [6].
P i,grid (t) = z i,pur (t) − z i,sale (t) P i,grid (t) Following the methodology introduced in [2], the expression ( 13) can be obtained by the linear constraints resulting from the logic relationships between the variables u, δ and z (expressions ( 37)-( 42)).
The symbols ∧ and ∼ stand for the logic operators AND and NOT, respectively.As introduced with the constraints ( 9) and (10), both the exchange variables and the output variables of each subsystem have to behave in a deterministic manner.These constraints can be particularized to our case study by inserting the following expressions: The problem for Step 0 can be particularized to our case study concerning the optimization problem (45), in which the scenarios for each microgrid adopt the values S i = +, − and S j = +, −, and therefore, After solving all the combinations of scenarios, the average profile for the exchange of power among microgrids is obtained as follows: In the case study described herein, Step 1 can be expressed by defining the expectation i,local , considering the value of the local cost function for all the scenarios constraining the value of P [+]  i→j (t) = P [+] i→j (t) = 0 considered.
After solving the problem defined in this step, the value of i,local for the optimal operation point for each subsystem working as single systems C <k> i,local is obtained, as described in Section II-A.After obtaining C <1> i,local , Step 2 can be defined for the case study regarding P2P energy scheduling among networked microgrids with the expectation defined in (48): subject to: This step is carried out iteratively until the condition (51) is satisfied.

III. RESULTS
The algorithm was programmed in a MATLAB environment using the TOMLAB® toolbox as optimization software.
The execution time required for all the steps of the controller was 43.93 s, using a PC with an Intel® Core™ i7-9750H @ 2.60 GHz and 16 GB of RAM installed.The different values integrated into the controller are shown in Table 2.The sample period selected was T s = 1 hour and the schedule horizon was 24 hours, as usually occurs for the day-ahead market operation.Fig. 4 shows the results of the price prediction carried out by the controller following the methodology described in [2].It is considered that pur (t) = 3 sale (t).The different energy forecast scenarios when considering an uncertainty band of ±5000 W for each microgrid is shown in the left-hand graph in Fig. 5.The procedure explained in Step 0 of Section II was followed, and the results obtained for the energy exchanges P 1→2 when considering the deterministic profiles P1,rem and P2,rem based on the different combinations of considered scenarios is displayed in the right-hand graph of Fig. 5.In order to simplify, the assigned value is similar for each of the scenarios considered P(S i = +) = P(S i = −) = 0.5.
The simulations for the SMPC controller applied to the microgrids working as single systems (Step 1 of the    find an energy exchange consensus for the day-ahead, which has deterministic behavior, independently of the scenario considered for each microgrid.The algorithm also obtains a deterministic energy exchange with the main grid.The final results of the algorithm can be observed in the graphs in Fig. 7. One goal of the algorithm is to achieve, in a networked operation, a lower value of the sum of local operational costs defined in expression (47) than that which acts as single systems.The optimization results of Step 1, in which the microgrids act as single systems, can be found in Fig. 6, while the optimization results of the networked operation are displayed in Fig. 7.The legends of both figures include the term P req , which indicates the exchange power required in order to satisfy the given constraint in expression (51), in which P req = 0 for the case of single microgrids, as occurs in Fig. 6.As can be seen in Fig. 7, despite the uncertainties, a common profile for the exchanged power for both microgrids and scenarios is found after several iterations.A common profile for the energy exchange with the main grid is also obtained for each microgrid, independently of the scenario considered.These can be considered as the main achievements of this work.Note that if the most advantageous energy forecasts S 1 = + and S 2 = + are scheduled, after which the worst possible scenario combination S 1 = − and S 2 = − later arises in the real-time operation  of both microgrids, the schedule of energy exchange with the main grid carried out could not be achieved, since the corresponding penalty for deviations in the regulation service market are applied.This provides an additional feature to the P2P optimization of microgrids presented in [3].
The values obtained for the local cost functions of the microgrids are shown in Table 3 for both cases: 1) Single or independent operation of each microgrid without energy exchange, and 2) Cooperative P2P operation, while Table 4 shows the sum of costs for both microgrids when considering the possible scenario combinations.As can be seen, despite the stochastic nature of the energy forecast, a deterministic energy exchange profile that achieves a better interaction with the main grid and reduces the operation cost of the ESS can be obtained between both microgrids.These cost reductions make the sum of the local cost functions evaluated as a network with a P2P energy exchange lower in comparison to the case of working as single systems (see Table 4).

IV. CONCLUSION
This work presents a distributed stochastic MPC approach for interconnected systems that include a large number of terms in their cost function and require a deterministic schedule for both exchange and output variables.
The developments are applied to an energy community based on networked microgrids with hybrid ESS.The results obtained show that the energy community achieves a lower cost for its optimization in the day-ahead market as a network of microgrids than in the case of participating as separate microgrids, despite considering uncertainties in the energy forecast of both microgrids.
Two of the main challenges related to the large-scale deployment of energy communities are confronted and resolved.The first is that of large-scale energy storage, which is achieved by introducing an advanced formulation specifically developed for the management of microgrids with hybrid ESS composed of hydrogen and batteries in spite of the large number of terms required in the cost function of the associated optimization problem.The use of both technologies achieves high rates of power and energy density in the renewable power plant.The second challenge concerns the integration of uncertainties into the energy forecasting of interconnected microgrids.This aspect is achieved by using an advanced formulation for the energy optimization problem based on distributed stochastic MPC techniques.
As can be seen from the results, despite considering a band of uncertainty in the energy forecast of both microgrids, they can acquire a deterministic commitment to exchanging energy with the main power grid and with the neighboring microgrid.The proposed methodology paves the way toward a massive deployment of energy communities with large energy storage facilities based on hybrid ESSs.
Peer-to-peer energy transactions involve many entities, each with its own generation and consumption profiles.As the number of market participants increases, the computational burden grows.The objective of this algorithm is to solve the schedule of interconnected microgrids, and it is, therefore, an off-line optimization method to be used before the day-ahead market closes.The computational burden can be solved with simply a correct anticipation of the day-ahead market session closure, depending on the number of market participants involved.
Moreover, although the paper is focused on networked microgrids, the proposed methodology can be applied in order to solve the problem of coupled uncertainties in interconnected systems.Future developments will address the problem of including different scenarios with different probabilities so as to create a more generalized distributed stochastic framework.

FIGURE 1 .
FIGURE 1.An example of four-bus networked microgrids with hybrid ESS, considering uncertainties in the energy forecast.

FIGURE 2 .
FIGURE 2. Block diagram of the proposed stochastic P2P optimization of microgrids.

FIGURE 3 .
FIGURE 3. Possible energy scenarios in a P2P optimization of microgrids.

FIGURE 5 .
FIGURE 5. (a) Different energy forecast scenarios considered for both microgrids.(b) Power exchange profiles using deterministic P2P optimization of microgrids.

FIGURE 6 .
FIGURE 6. Optimization results for each microgrid working as a single system.

FIGURE 7 .
FIGURE 7. Optimization results for the stochatic P2P optimization of the interconnected microgrids.

TABLE 4 .
Comparison of results for the single and cooperative P2P optimization.
z Mixed product for Electric power (W ).δ On/Off state.ε Minimum tolerance provided to the controller.η Efficiency (p.u).χ Logical degradation state.ϑ MLD power variation in degradation state (W ).σ Start-up state logical variable.Cost of energy (e).Expectation of the cost function.

TABLE 1 .
Literature related to the optimization of networked microgrids considering forecasting uncertainties.

TABLE 2 .
Values of the controller.

TABLE 3 .
Controller results for each microgrid.