1 Introduction

The growing development of more efficient renewable generation technologies and storage systems, has shifted the energy generation paradigm towards decentralization. Although a large portion of the energy is still being generated from centralized power plants (some of which are also using renewable technologies), distributed generation has become a reliable and efficient alternative of supply. In this framework, microgrids (MGs) have been recognized as an efficient solution to integrate different kinds of distributed energy resources (DERs) into a single controllable entity that is able to operate in interconnected or islanded mode. Because of those features, MGs are considered as the building block of the smart grid concept. The recent success of such architectures has increased their deployment around the globe. Subsequently, researchers are currently proposing the interconnection of multiple MGs at a cyber-physical level in order to create smart grids. This new scheme is known as networked MGs (NMGs) [1, 2].

Interconnecting multiple MGs leads to several benefits such as reliability and resiliency enhancement, independence of the utility grid, and reduction of global costs. In order to achieve these objectives, control strategies for the energy trading among MGs have been proposed through the past few years at different layers. From a high layer perspective, the problem of NMGs is understood as the combination of two problems: optimal management of energy resources among MGs and encouragement of trading in the network. The first problem is solved through strategies of resource allocation that seek to optimize local and global objectives e.g. operation costs, while the second is addressed through the design of incentive mechanisms. In the existing literature, several strategies have been proposed for solving these problems separately or to integrate them under different contexts. Most of the works deal with a network of MGs interconnected with the utility grid.

Regarding the energy management of NMGs, several authors have presented solutions from different points of view. Some authors propose optimization models under several architectures such as centralized, decentralized, distributed, and hierarchical, which seek to take advantage of interconnection benefits. In a centralized approach, the dispatch and power exchange are handled by the energy management system (EMS). Based on local information from each MG, the EMS solves a single global optimization problem that provides not only the power interaction among MGs, but also the dispatch of each generator for every MG. In [3], the problem of NMGs is solved through a nonlinear optimization problem that minimizes generation cost. The authors solve this problem by using particle swarm optimization (PSO). In [4], the authors propose a real-time MG economic dispatch scheme with network constraints by applying conic-programming and model predictive control (MPC). In [5], the NMG has been modeled as a linear optimization problem. The objective is to maximize the benefits through an MPC approach, which outputs the power exchange scheduling and the optimal behavior of energy storage systems (ESSs) in each MG. Few works have addressed the operation of NMGs in a distributed manner although the number of that kind of methods increases lately. In [6], a distributed MPC approach is used for the day-ahead dispatch problem in a smart grid context. Here, there is not an explicit mention of MGs. Instead, a smart grid composed of multiple centers of generation and consumption is partitioned into multiple subgrids called hubs. This work provides a model for each hub in terms of the ESSs where an economic dispatch algorithm is solved. In [7], the authors propose a hierarchical method that comprises distributed control for multiple MGs and a central controller for each MG. Economic dispatch can be solved while MGs are plugged-in or plugged-out through flexible communication. In [8], a distributed management system is proposed for a network of MGs with a dedicated DC power exchange network. In that work, the distribution system operator (DSO) is in charge of managing the distribution network where the MGs are interconnected. The MGs seek to minimize their own operational cost and take into account power flow constraints by incorporating a relaxed optimal power flow (OPF) method into the optimization problem. This approach results into a second-order cone programming problem. Both DSO and MGs cooperate with each other through the EMS to minimize the global operation costs. Most of these works assume that MGs in the network reach a cooperation agreement and participate in the trading if an improvement in the global optimization costs is attainable. However, there are scenarios where selfish MGs would trade energy only in the presence of additional incentives. Therefore, research efforts have focused on integrating the resource management with mechanisms of incentives in order to obtain a full trading mechanism for MGs.

Several works about trading in NMGs have focused their efforts on MGs that are interconnected through a dedicated AC distribution power network and are connected with the utility grid. Under this framework, MGs decide if they will buy or sell energy according to economic and technical characteristics. Thereby, MGs decide how to distribute resources from the sellers to the buyers, and what will be the energy price. Therefore, these approaches integrate the energy management and incentive problems. Approaches in this topic are usually iterative, where the response from one kind of agents depends on the response of the others and vice-versa. Stackelberg games, double auction, and Nash bargaining are the most common approaches. In [9], the authors have proposed a non-cooperative game based on the multileader-follower structure of Stackelberg games. This approach contemplates two interactive games. In the buyer level, a player decides the amount of energy to be imported. In the seller level, a player submits energy price based on its willing to sell. The two games interact with each other until convergence to the Nash equilibrium is achieved. The energy allocation is done through the proportional sharing principle. A two-layer approach for the energy trading in MGs is proposed in [10], where the lower layer comprises the trading among prosumers and the upper layer comprises the trading among MGs. On one hand, the upper layer is implemented through a multi-leader multi-follower Stackelberg game. On the other hand, the lower layer determines the energy capacity of each MG and its respective role in the game (buyer or seller). There are two levels in the Stackelberg game proposed by the authors: a buyer level where the players submit and update energy prices for importing electricity; a seller level where the players adjust the energy to be exported by controlling states of energy storage. In [11], a non-cooperative game theoretic approach for the trading in NMGs is proposed. Similarly to previous works, the authors propose two interactive games. The seller strategy is to adjust its energy consumption, which translates into a portion of the total energy excess. For the buyer layer, the authors define a priority index which measures the contributions of each MG to the trading. In this approach, there is an aggregator for buyers and sellers. The role of the buyers’ aggregator is to define a unique energy price that minimizes the costs for all buyers, while for sellers its role is to define the allocation energy excess in order to maximize social welfare. In [12], the authors have provided a distributed peer-to-peer solution for the trading among prosumers in a MG. The authors consider the interaction among buyers through an evolutionary game approach where they cooperatively select sellers and the proportion of energy to be acquired. The core of these works is to show that efficient trading in MGs consist of the two problems mentioned before, i.e, management and incentives. Additionally, the authors discuss about integration with the local operation of MGs. Hence, the concept of high-level hierarchical control in the network of MGs is highlighted.

Hierarchical approaches have been proposed for the trading in NMGs where the local EMS is integrated with the high-level trading approach. The authors in [13] propose a bi-level hierarchical structure where the lower level solves the EMS by using stochastic programming, and determines possible deviations between the day-ahead and real-time market biddings from each MG. Trading among MGs is developed at the higher level by using a secondary market based on a distributed double auction (DDA) scheme, where the MGs seek to alleviate deviations. The DDA is coordinated by a central agent who is able to optimally allocate resources in the network by considering social welfare. In [14], the authors propose a trading mechanism based on bargaining theory in order to minimize operation costs of the network. Locally, each MG solves its economic dispatch problem (EDP) and decides if it is possible to contribute with the global objective. Next, MGs choose a fee for the energy to be distributed with their peers based on the Nash bargaining problem. In [15], the authors propose a three-layer hierarchical market scheme for the operation of multiple MGs. The first and secondary levels (day-ahead, hour-ahead) of the market solve the energy management problem from a game-theoretic framework through a double auction scheme, where the resource dispatch is determined after market clearing. MGs interact in the third layer, where they compete in order to meet possible energy mismatches from the lower two layers. The competition among MGs is done through a reverse auction mechanism.

The current literature explores the operations of NMGs that are not only interconnected among them, but also with the utility grid. To the best of our knowledge, there is a lack of consideration of ramp constraint of conventional generation and very few works consider the underlying capacity constraints from the network. In this paper, we propose a hierarchical approach for the energy trading in NMGs that combines a hybrid high-level layer with a distributed low-level layer. The high-level layer looks for maximizing social welfare in terms of achieving nodal prices agreement. The low-level layer uses a distributed economic dispatch that manages resources in the MG by complying with technical constraints. The main contributions of this paper can be listed as follows:

  1. 1)

    Maximization of social welfare through the agreement of nodal prices.

  2. 2)

    Use of consensus and replicator dynamics for the agreement of nodal prices.

  3. 3)

    Integration of local MG dispatch with a high-level coordination of MGs. The low-level EMS satisfies technical constraints such as generator limits and ramp-rate constraints.

  4. 4)

    Integration of network limits and analysis of impacts in the nodal price.

The remainder of this paper is organized as follows. Section 2 describes the formulation of different approaches applied to the problem of NMGs and presents the background of consensus-based algorithm and replicator dynamics algorithm. Case studies and their results are presented in Section 3. Finally, conclusions are drawn in Section 4.

2 Model of NMGs

In the power systems that operate under a single competitive market, there is a unique price related to marginal costs of generators. Usually, the objective of the system operator is to deliver electricity by minimizing operation costs or maximizing social welfare while complying with security and technical constraints. From this perspective, the system operator decides the optimal output of generators such that loads are satisfied and network constraints are not violated. Power flow limits may increase the energy price since cheaper generators can be curtailed for achieving security. In such case, the cost of congestion is socialized to the demand. A more advanced pricing of power systems is the nodal approach, where every zone or node has a different price related to the locational value of energy. The locational value of electricity is the result of congestion in the network and power losses. In the absence of congestion and neglecting power losses, nodal prices will converge to a unique price. That is, social welfare is maximized [16].

From an ideal perspective, centralized operation with full information is the benchmark, as it achieves social welfare maximization (or costs minimization). In this paper, the ideal scenario would be to have all the resources from different MGs operating under the same competitive market, obtaining a unique price. However, this configuration requires a large communication infrastructure, especially if there are several power plants. Under a distributed approach, the communication infrastructure is less demanding as local microgrid operators (MGOs) can communicate with the networked microgrid operator (NMGO), who manages information sharing between MGs. In that case, the unique price is achieved with the algorithms proposed in this paper. For this reason, nodal prices must be the same in order to maximize social welfare when there are no congestion limits, i.e., the distributed approach emulates a centralized market that maximizes social welfare. If there are active power flow constraints, then nodal prices will be different, especially for the nodes that import energy.

Consider the network of multiple MGs interconnected through an independent AC power network and that as a whole can be isolated from the utility grid, as shown in Fig. 1. Each MG might be able to supply its inner demand during the day by using its own DERs, which comprise conventional generation, renewable generation, and stand-alone ESSs. At a local level, these resources are delivered to the loads by using the local competitive market, i.e. the EMS of MG (red dotted line in Fig. 1). The local EMS collects information from both DERs and loads, and solves an EDP in order to guarantee a reliable energy supply to loads while keeping energy balance in the MG.

Once the EDP is solved by each MG in the network, nodal prices appear. Note that in this case nodal prices are not the result of congestion, but they arise because of clearing local competitive markets that have different resources and loads. Having different nodal prices is not optimal (when there is no congestion) as other MGs could import or export energy to other systems, thus decreasing global operation costs. Thereby, MGs should share information with one another through the NMGO in order to seek a global economic benefit related to their operation costs. This procedure will lead to a unique electricity price. For the first case, interaction among MGs will be coordinated through: ① a consensus-based algorithm where the objective is to reach same nodal prices; ② a replicator dynamics algorithm that minimizes operation cost in the network.

As mentioned before, MGs have a diverse kind of DERs in order to supply their local loads at any period of time. The EDP is solved through a distributed MPC based strategy [17], where each DER shares information with a set of neighbors given a communication topology. In addition, the local controller (LC) implements a consensus-based approach in order to reach an agreement in the dispatch with the MG central operator. This algorithm takes into account capacity limits of generators and ramp-rate limits. Thereby, the price information for the high-level controller implicitly considers active constraints of generators in the MG.

Fig. 1
figure 1

Model of NMG

2.1 Networked energy trading: a simple case

In the perspective of the MGO, the solution of the local EMS provides a distributed economic dispatch that preserves energy balance and respects ramp constraints from conventional generators. As a secondary result, the MGO collects the information and builds a marginal cost function. This information also includes the current generation status and operation constraints. As mentioned before, the MG is part of a network that shares resources in order to reach a common objective: minimization of the global cost. Since MGs are interconnected through an AC power network, the main concern in the energy trading is to keep energy balance in the system. This implies a resource allocation problem where resources from each MG marginal generator are reallocated through the network in order to minimize operation costs. In this paper, we have solved this problem by applying the replicator dynamics algorithm and the consensus-based approach. These algorithms are presented next.

2.1.1 Replicator dynamics algorithm

Evolutionary game theory, specifically population dynamics, has been applied in the past few years to a diverse range of applications in distributed optimization, especially those related to resource allocation problems [18]. In the context of MGs, applications in economic dispatch and demand side management have been thoroughly explored. In this paper, recent results from [19] are adapted into the high level energy trading in NMGs.

Replicator dynamics algorithm is a simple dynamical model that shows how a proportion of agents is allocated in a set of habitats with different conditions to reach a certain goal. The population in each habitat perceives a shared welfare that is measured by a fitness function. Fitness depends on agent characteristics and distribution of the population in the environment. The main objective is that the population reaches a social equilibrium through evolutionary processes, where all agents achieve the same fitness. Denote \({\mathcal {H}} = \{1, 2, \dots ,H\}\) as the set of pure strategies, \(x_{i} \ge 0\) as the proportion of individuals playing strategy i (\(i^{\mathrm{th}}\) population share), and \(\varvec{x} = {[}x_{1},x_{2},\dots ,x_{H}]\) as the population state, which is restricted to the following simplex formulation:

$$\begin{aligned} \varDelta = \left\{ \varvec{x} \in {\mathbb {R}}^{H}: \sum _{i\in {\mathcal {H}}} x_{i} = 1 \right\} \end{aligned}$$
(1)

Evolution of the population in the different habitats is modeled through the following replicator equation:

$$\begin{aligned} \frac{\mathrm {d}x_{i}}{\mathrm {d}t} = x_{i}(f_{i}(\varvec{x})-{\bar{f}}(\varvec{x})) \quad \forall i \in {\mathcal {H}} \end{aligned}$$
(2)

where \(f_{i}(\varvec{x})\) represents the fitness function perceived by the agent in the \(i^{\mathrm {th}}\) habitat; and \({\bar{f}}(\varvec{x}) = \sum \limits _{j\in {\mathcal {H}}}x_{j}f_{j}(x_{j})\) is the the average fitness. As a consequence of the calculation of the average fitness, the set \(\varDelta\) defined by (1) is invariant and every initial population state that starts inside this set will remain in \(\varDelta\) for \(t \ge 0\).

Consider a set of MGs \({\mathcal {M}} = \{1,2,\dots ,M\}\) that is interconnected through an AC power network and is able to share information through the NMGO that supervises the trading in the network. For this case, it is assumed that there will be only one marginal generator in each MG characterized by the following information: current state of the generator \(P_{MGi}\), the generation limits after ramp constraints \([P_{i}^{\min }, P_{i}^{\max }]\) and the linear marginal cost function \(2a_iP_{MGi}+b_i\), where \(a_i\) and \(b_i\) are quadratic and linear weights that depend on generator technology, respectively. Consider the aggregated power to be redistributed in the NMGs as the aggregation of the states of the marginal generators \(P_{NMG} = \sum \limits _{i\in {\mathcal {M}}}P_{MGi}\), which defines the energy balance that must be respected in the trading. Under these considerations, the application of the replicator dynamics for the energy trading in a NMGs follows a similar structure to an optimal dispatch problem. The following proposal is adapted from [19].

Let \(p_{MGi} = P_{NMG}x_{i}\) be the dispatch of the marginal generator from \(i^{\mathrm {th}}\) MG disposed for the energy trading. Therefore, MGs represent habitats while the proportion of demanded power represents a group of individuals. The replicator equation applied to the trading resource allocation problem is:

$$\begin{aligned} \frac{\mathrm {d}}{\mathrm {d}t}p_{MGi}= p_{MGi}\left( f_{i}(p_{MGi}) - {\bar{f}}\right) \end{aligned}$$
(3)

where \(f_{i}(p_{MGi})\) is the fitness function that describes the payoff of \(i^{\mathrm {th}}\) MG; and \({\bar{f}} =\frac{1}{P_{NMG}}\sum \limits _{i \in {\mathcal {M}}}p_{MGi}f_{i}(p_{MGi})\) is the average fitness function. The solutions for the energy trading among MGs are invariant under the following simplex formulation:

$$\begin{aligned} \varDelta _{MG} = \left\{ (p_{MGi}) \in {\mathbb {R}}^{H}: \sum _{i\in {\mathcal {H}}} p_{MGi} = P_{NMG} \right\} \end{aligned}$$
(4)

In other words, if the initial resource distribution \(p_{MGi}(0) \in \varDelta _{MG}\), then the trajectories of the NMGs trading stay within \(\varDelta _{MG}\). Therefore, the balance in the NMGs can be guaranteed. The equilibrium point of (3), denoted as \(\varvec{p_{MG}^{*}} = [p_{MG1}^{*}, p_{MG2}^{*},\dots , p_{MGM}^{*}]^{\mathrm {T}} \in \varDelta _{MG}\) satisfies the following condition:

$$\begin{aligned} f_{i}(\varvec{p_{MG}^{*}}) = {\bar{f}}(\varvec{p_{MG}^{*}})={\bar{f}}^{*} \quad \forall i \in {\mathcal {M}} \end{aligned}$$
(5)

It means that all MGs obtain a fitness equals to the average fitness \({\bar{f}}^{*}\) in the equilibrium. This condition can be used to design a pricing mechanism for the NMGs. A desirable property of the trading is that its energy price is equal for every MG. Considering that the lower level provides a linear marginal cost function of each MG, then the fitness function is related to that function. One advantage of linking the fitness with the marginal cost function is that equilibrium of the replicator dynamics corresponds to the minimization of the cost function of all the generators. This property is the result of to the gradient property in replicator dynamics, which states that if the fitness is defined accordingly to:

$$\begin{aligned} {f}_{i}(p_{MGi}) = -\frac{\partial C(\varvec{p}_{MG})}{\partial p_{MGi}} -(a_{i}p_{MGi}+b_{i}) \end{aligned}$$
(6)

Then, the equilibrium guarantees the minimization of costs \(C(\varvec{p}_{MG})\). The fitness function is complemented by incorporating capacity limits through barrier functions as follows:

$$\begin{aligned} \begin{aligned}&f_{i}(p_{MGi}) \\&\;={\left\{ \begin{array}{ll} - C_{i}^{\max } - m(p_{MGi}-P_{i}^{\max }) &{} p_{MGi} < P_{i}^{\min } \\ {\bar{f}}_{i}(p_{MGi}) &{}{P_{i}^{\min }\le p_{MGi} \le P_{i}^{\max }} \\ - C_{i}^{\min } - m(p_{MGi}-P_{i}^{\min }) &{} p_{MGi} > P_{i}^{\max } \end{array}\right. } \end{aligned} \end{aligned}$$
(7)

where \(C_{i}^{\min }\) and \(C_{i}^{\max }\) are the minimum and maximum values of the marginal cost function for each MG; and m is the slope of the barrier function. The barrier functions are modified from [19] in order to guarantee continuity of the fitness function in the constraint limits.

Stability and convergence of the replicator equation depends mainly on the fitness function characteristics. Considering that it does not depend on the strategies of other players, the equilibrium point is asymptotically stable if it is positive and differentiable \(\forall i \in {\mathcal {M}}\) and \(\forall x \in \varDelta\), and if its derivative with respect to the strategy decreases. Hence, a positive constant B is added to each fitness function in order to guarantee their positivity without affecting obtained solutions. Even though the fitness function is non-differentiable, the assumption can be relaxed to a locally Lipschitz condition as shown in [20], demonstrating asymptotic stability of the equilibrium point \(p_{MGi}^{*}\). Therefore, the replicator equation converges to a minimum generation cost and to a unique nodal price.

Although the replicator method works fine for specific conditions of the fitness function, this is not a real case since marginal cost functions are not necessarily continuous and linear. Indeed, these functions are usually piece-wise linear due to multiple marginal energy resources with possible discontinuities. Moreover, the existence of ramp-rate limits makes more complex the task of obtaining a continuous linear fitness function.

2.1.2 Consensus-based agreement algorithm

Consensus algorithms [21,22,23] have gained importance because of their capabilities to share information in connected graphs where there is no central controller, and their capabilities to reach agreements among different participants. Case in point, equitable allocation of resources. In this research, the main goal of the high-level controller is that nodal prices are equal for all nodes when possible, i.e., when there are no active flow constraints.

Consider a connected and undirected communication graph denoted by \({\mathcal {G}} = ({\mathcal {N}},{\mathcal {E}})\), where \({\mathcal {N}} =\{1,2,\dots ,N\}\) is the set of nodes, \({\mathcal {E}}\) is the set of edges connecting nodes, each node is designated a decision variable denoted by \(\pi _\ell\). To reach an agreement or consensus between participants, consider the following process described in [22]. Let \(\varvec{\xi } \in {\mathbb {R}}^N\) be a vector of auxiliary variables, i.e., \(\xi _v \in {\mathbb {R}}\) corresponding to a node \(v \in {\mathcal {N}}\). The variables are initialized at time 0 with the current values of variables at time \({\check{k}}\), i.e., \(\xi _{v,0} = \pi _{v,{\check{k}} }\), for all \(v \in {\mathcal {N}}\). Therefore, a continuous-time standard average consensus algorithm is computed, i.e.,

$$\begin{aligned} \xi _{v,{\check{k}}+1} = \xi _{v,{\check{k}}}+\sum _{i \in {\mathcal {N}}_v }w_{vi}\left( \xi _{i,{\check{k}}} - \xi _{v,{\check{k}}}\right) \quad \forall v \in {\mathcal {N}} \end{aligned}$$
(8)

where \(w_{vi}\) is the weight of the link between nodes v and i; and \({\mathcal {N}}_v\) is the set of neighbors of node \(v \in {\mathcal {N}}\). Since the graph is undirected, \(w_{vi}=w_{iv}\). Here, \({\check{k}}\) is the discrete time for a sampling time very close to zero. If the communication graph \({\mathcal {G}}\) is connected and the weight of links are symmetrical, then the dynamics in (8) converge to \(\varvec{\xi }^{*} \in {\mathbb {R}}^m\), where \(\xi _v^{*} = \sum \limits _{v\in {\mathcal {N}}}{\xi _{v,0}}/|{\mathcal {N}}|\), for all \(v \in {\mathcal {N}}\) [23]. According to [21] and [24], if the out-degree of every node in the graph is equal to its in-degree and if the graph is connected, the system is average-preserving. For choosing adequate weights, it can be used the definitions of [25] and the max-degree characterization that achieves average convergence.

Since we do not want to achieve average consensus, but a different consensus where nodal prices are equal and ensure energy balance, we propose a different consensus algorithm. From the previous description of the consensus, it can be seen that the update of the auxiliary consensus variable depends on the current state and deviations with respect to neighbors’ states (8). However, the agreement in that consensus is the average of initial conditions, i.e., the mean value of marginal prices of MGs when they operate in isolated mode. Such result might not be appropriate for the global optimization objective though we are looking for same nodal prices. From the economic principles and different analysis described in [16], the maximum benefit of interconnected systems arises when nodal prices are equal. Nevertheless, the agreement obtained through average consensus can violate the energy balance constraint.

In this section we provide a general consensus-based algorithm that reaches a nodal price agreement while complying with the energy balance constraint. The basic functioning of the algorithm relies on the comparison of nodal prices and the average of them. Thus, MGs with a nodal price lower than the average will have an incentive for increasing their power, whereas MGs with a nodal price higher than the average will have an incentive for decreasing their output. The proposed procedure is described in Algorithm 1, where \(\alpha\) is a convergence parameter; \(\mu _\pi\) is the average of nodal prices; \(\pi _i\) is the nodal price of \(i^{\mathrm {th}}\) MG; \(t_{ol}\) is a termination condition; \({\mathcal {I}}\) is the set of nodes with a price below \(\mu _\pi\); \({\mathcal {D}}\) is the set of nodes with a price above \(\mu _\pi\); \(\left| {\mathcal {I}}\right|\) is the cardinality of the set \({\mathcal {I}}\); \(d_j\) is a distribution factor according to the distance of \(\pi _j\) and \(\mu _\pi\); and \(\Delta P_{{\mathcal {I}}}\) is the total power increased by nodes in the set \({\mathcal {I}}\).

figure a

2.2 Networked energy trading: general case

In the previous section, we show the operation problem of NMGs for a simple case. In that case, we have an explicit linear function of the marginal cost of MGs, or equivalently the nodal price function, and capacity limits. However, it is not straightforward to define a marginal cost function of the MG, and in the possible case, this function might be discontinuous and piece-wise linear. Moreover, this function is dynamic and changes in terms of generator characteristics within the MG. Finally, the methods proposed in Sections 2.1.1 and 2.1.2 do not include ramp-rate limits of generators. This constraint is essential as it describes the maximum output change from one period to the next, and it may modify nodal prices.

In [17], we have proposed a distributed MPC to solve the EDP of a single MG. In that case, generators implicitly preserves energy balance at the same time that capacity limits and ramp-rate restrictions are considered. In order to account for ramp-rate limits in the problem of NMGs, we use the distributed model predictive control (DMPC) proposed in [17] along with a high-level controller for the nodal price agreement. Instead of using an explicit function of nodal prices, the DMPC provides the nodal price as a result of the local economic dispatch. Algorithm 2 describes the proposed procedure to include ramp-rate constraints without requiring the marginal cost function of MGs. Here, \(\varvec{a}_i, \varvec{b}_i, \varvec{P}_{i}^{\min }, \varvec{P}_{i}^{\max }, \Delta \varvec{P}_{i}^{\min }, \Delta \varvec{P}_{i}^{\max }\) are vectors in \({\mathbb {R}}^g\), where g is the number of generators in \(i^{\mathrm {th}}\) MG, \(DMPC(\cdot )\) is the method proposed in [17], and \(D_i\) is the demand of \(i^{\mathrm {th}}\) MG.

figure b

2.3 Networked energy trading: power flow limits

In the problem of NMGs, and in general for power systems operation, it is necessary to consider grid constraints, which are related to the capacity of distribution lines. Generally, this is a complex problem since economic trading do not follow power flow behavior as this latter obeys Kirchhoff laws. In the presence of active network constraints, global agreement of nodal prices can not be reached [16]. Therefore, resources must be re-dispatched in order to achieve a feasible and efficient solution that complies with network constraints.

Without loss of generality, the case considered with three interconnected MGs is shown in Fig. 2, where DG denotes distributed generator. Let MG1 and MG2 to be sellers and MG3 to be a buyer when network constraints are neglected. Next, consider a line capacity between nodes 2 and 3, i.e. line 2-3. Applying the superposition theorem, we can find the flow on line 2-3 when injecting \(\varDelta _{MW}^{1,3}\) in node 1 and extracting it in node 3 (\(F_{1,3}\)), and when injecting \(\varDelta _{MW}^{2,3}\) in node 2 and extracting it in node 3 (\(F_{2,3}\)) as follows:

$$\begin{aligned} F_{1,3}= & {} \dfrac{Z_{1,3}}{Z_{1,2}+Z_{2,3}+Z_{1,3} } \varDelta _{MW}^{1,3} \end{aligned}$$
(9)
$$\begin{aligned} F_{2,3}= & {} \dfrac{Z_{1,3}+Z_{1,2}}{Z_{1,2}+Z_{2,3}+Z_{1,3}} \varDelta _{MW}^{2,3} \end{aligned}$$
(10)

where \(Z_{i,j}\) is the line impedance between nodes i and j.

Fig. 2
figure 2

Testbed for trading in an isolated AC network of MGs

Equations (9) and (10) are known as distribution factors, and represent the incremental change of power flow in distribution lines according to injection and extraction of power in specific nodes. Now, if there is an excess (\(E_x\)) of power in line 2-3, the flow from sellers to buyers must be reduced. Thereby, by using (9) and (10) the following condition must be fulfilled.

$$\begin{aligned} \dfrac{Z_{1,3}}{Z_{1,2}+Z_{2,3}+Z_{1,3}}P_{MG1}^-+\dfrac{Z_{1,3}+Z_{1,2}}{Z_{1,2}+Z_{2,3}+Z_{1,3}}P_{MG2}^-=E_x \end{aligned}$$
(11)

where \(P_{MGi}^-\) is the power reduction of \(i^{\mathrm {th}}\) MG. Additionally, energy balance and efficiency must be achieved as well. These are defined respectively as:

$$\begin{aligned} \pi _1(P_{MG1}-P_{MG1}^-)\, = \,\pi _2(P_{MG2}-P_{MG2}^-) \end{aligned}$$
(12)
$$\begin{aligned} P_{MG1}^-+P_{MG2}^- \, =\, P_{MG3}^+ \end{aligned}$$
(13)

This is a first approach and entire combinations must be analyzed to define and provide a better algorithm. For instance, the flow when 1 MW is injected in node 1 and extracting it in node 2, the flow decreases the power flow in line 2-3 (\(L_{2,3}\)). Algorithm 3 shows the proposed procedure for including network constraints in the consensus-based agreement of nodal prices, where \(Z_T= Z_{1,3} + Z_{1,2} + Z_{2,3}\). This pseudo-code solves a simple case when there is one flow constraint in line 2-3 and MG3 is a buyer. Nevertheless, this reasoning can be generalized and extended to more network constraints and different operation scenarios. In order to take network constraints into account, the following conditions based on generalized distribution factors can be modeled:

$$\begin{aligned} \left[ \begin{array}{cccc} \delta ^1_{1,2} &{} \delta ^1_{1,3} &{} \dots &{} \delta ^1_{n,n-1}\\ \delta ^2_{1,2} &{} \delta ^2_{1,3} &{} \dots &{} \delta ^2_{n,n-1}\\ \vdots &{} \vdots &{} &{} \vdots \\ \delta ^C_{1,2} &{} \delta ^C_{1,3} &{} \dots &{} \delta ^C_{n,n-1} \end{array} \right] \left[ \begin{array}{c} P_{1,2}\\ P_{1,3}\\ \vdots \\ P_{n,n-1} \end{array} \right] \le \left[ \begin{array}{c} L_{1,2}^{\max } \\ L_{1,3}^{\max }\\ \vdots \\ L_{C,C-1}^{\max } \end{array} \right] \end{aligned}$$
(14)

where \(\delta _{i,j}^\ell\) is the distribution factor on line \(\ell\) of injecting power in node i and extracting it at node j; \(P_{i,j}\) is the power injected at node i and extracted in node j; and \(L_{i,j}^{\max }\) is the power limit of line connecting i and j. For the specific case of this paper, with a power flow constraint in line 2-3, (14) can be written as:

$$\begin{aligned} \delta _{1,3} P_{1,3}+\delta _{2,3} P_{2,3} \le L_{2,3}^{\max } \end{aligned}$$
(15)

The previous reasoning and the power distribution factors are used in Algorithm 3 for taking into account network constraints.

figure c

3 Case studies and results

3.1 Simple case: linear marginal cost function

In order to validate the consensus and replicator proposed for the simple case where the marginal cost functions are linear and unique, a case study comprising three MGs is proposed in Table 1. The low-level control provides to each MGO the explicit parameters of the marginal cost function, as well as the current dispatch state and operation limits of the marginal generator. In Fig. 3, it can be seen that both algorithms converge to the same energy price for the trading and the same dispatch for each MG. As a result, due to the gradient property of the replicator dynamics for potential games, it may be concluded that the proposed consensus-based algorithm is able to converge to a unique price and to a power dispatch that achieves costs minimization. Although the case study presented has full-information, both of the proposed algorithms can be easily extended to a fully distributed scheme without full information. The main difference between replicator dynamics and consensus-based algorithms is the convergence speed, where the latter requires fewer iterations. The replicator is implemented discretely by using the Euler approximation for solving differential equations. This approximation has a parameter that dictates convergence speed, so its tuning may improve performance. Furthermore, the implementation of both algorithms is not very complex and their execution is done in the same timeframe. However, the main drawback for the proposed replicator dynamics algorithm is the election of the fitness function. In this case, we have used a linear marginal cost function for its fitness, which is an assumption that does not hold for a more general MG scenario. In terms of theoretical convergence, in the replicator case, a connected graph is necessary [19]. On the other hand, the convergence of the proposed consensus-based algorithm is more complex to be demonstrated. This proof along with an extension to the generalized case of the replicator will be covered in future work.

Table 1 Parameters of simple case
Fig. 3
figure 3

Evolution of energy prices and power dispatch in NMGs

The assumption on the linearity of the marginal cost function of each MG does not hold in a generalized context, where the low level DMPC economic dispatch may result in more than one marginal generator with their respective ramp constraints. This translates into a piece-wise marginal cost function for each MG that dynamically changes the trading conditions. For future work, the complimentary analysis will be required to study the nature of the general marginal cost function and to make assumptions about the resulting fitness in order to guarantee the asymptotic stability.

Table 2 Parameters of generators in MG1
Table 3 Parameters of generators in MG2
Table 4 Parameters of generators in MG3
Fig. 4
figure 4

Comparison of trading behavior when ramp constraints are applied

3.2 General marginal cost function

This section shows the results of consensus-based algorithm (Algorithm 2) applied to the problem of NMGs. In this case, the DMPC proposed in [17] is used as the low-level controller. Integration of DMPC with the consensus-based algorithm is very important because ramp-rate constraints can be considered. In addition, MGs do not provide an explicit marginal cost function but they can deliver nodal price information as the output of local economic dispatch. This case study is composed by 3 MGs (Fig. 2), and their specific details are shown in Tables 2, 3 and 4. Figure 4 depicts the behavior of power of MGs in terms of ramp-rate constraints. For this case, the ramp constraint of DG2 in MG1 is 0.5 MW. In the ideal case, nodal prices converge to $24.17, thus maximizing the social welfare as described in [16]. Nevertheless, in the presence of ramp limits, the nodal price increases. This behavior arises as a consequence of the limitation in second generator of MG1. From nodal prices in Fig. 4, it can be seen in the first iteration that nodal price of MG1 is the lowest. Thereby, if a generator in this MG is constrained, the remaining MGs (MG2 and MG3) should deliver the lack of energy in the network. This analysis can be observed in the power patterns shown in Fig. 4. In this real and probable scenario, nodal prices stabilize at $32.84. Hence, the cost of the constraint to the nodal price agreement is $8.67.

3.3 Network contraints

Fig. 5
figure 5

Comparison of trading behavior before (until iteration 11) and after (after iteration 11) network constraints are considered

Considering the same case study as in Section 3.2, we include an additional constraint to the problem, i.e., 2 MW power flow limit in line 2-3. If the power flow in line 2-3 surpasses its capacity limit, MGs must be re-dispatched. This process is described in Algorithm 3, and its results are shown in Fig. 5. Algorithm 3 shows that at first Algorithm 2 must be executed in order to find ideal outputs of MGs, then MGs are re-dispatched if capacity limits are violated. The first stage (Algorithm 2) is shown in Fig. 5 from iterations 1 to 11. After this, capacity limit of line 2-3 is surpassed by 0.4 MW and MGs must be re-dispatched, which is the second stage of Algorithm 3 (from iterations 12 to 16).

From the results, it can be seen that nodal prices of sellers (MG1 and MG2) reach an agreement, but the nodal price of buyers (MG3) differs and is larger. Here, there is an implicit incentive to make an investment in line 2-3 because of the constraint cost to users in MG3. A different approach considered in DC MGs is to manage the power flow between MGs. Such an approach can be seen in [26].

4 Conclusion

The trading in a network of interconnected MGs by an AC power network was studied through a hierarchical approach that integrates local energy management of each MG, and the trading in the network. The lower layer solves the economic dispatch through a DMPC approach that preserves inner balance and respects ramp constraints. The MGO aggregates the results and finds the nodal marginal cost, and distributes this information to a NMG operator who is in charge of distributing data to other MGs. The MGs update prices based on this information. For the simple case where the marginal cost function from each MG is linear, a consensus-based algorithm and a replicator dynamics algorithm have been proposed. It has shown that both algorithms converge to the same nodal price, which is a minimum cost solution for the energy trading.

Since an explicit function of nodal prices or marginal costs of a MG is not always available, we have proposed two algorithms based on consensus, which use DMPC as a low-level controller. The DMPC controller considers ramp-rate constraints and delivers its nodal price as a result of a local economic dispatch. This information is used by the consensus-based agreement algorithms to provide power change signals to the participant MGs.

We have analyzed the impact of two kinds of constraints in the power system, i.e., ramp-rate limits and network limits. The impacts of these constraints are the increase of the nodal price agreement, and the difference of nodal prices between buyer MGs and seller MGs. Costs of the constraints in the nodal price imply incentives for investing in the MGs or in the network. Thereby, there would be only a single nodal price agreement without active constraints, thus maximizing social welfare.

In summary, the main advantages of the proposed algorithms are as follows: ① the proposed algorithms emulate the centralized benchmark in the absence of congestion limits by achieving agreement of nodal prices; ② the algorithms are distributed, so the communication infrastructure is less demanding; ③ there is no need of sharing private information of generators within the MGs; ④ these algorithms stabilize very fast; ⑤ they rely on a local market based on distributed MPC. Additionally, network constraints can be included.

For the future work, we propose to generalize network constraints in both the consensus-based algorithm and the replicator dynamics algorithm. For the latter, we propose as well to analyze the impacts of having a piecewise linear marginal cost function and its implications in the fitness to guarantee asymptotic stability. Additionally, we will explore how the main grid acts in these algorithms as a passive player (only provides energy prices and does not respond to the MGs decision) or an active player (energy prices evolve according to the NMGs decision).