In this section, the whole decentralized gradient algorithm will be designed. First, models for renewable sources and battery systems will be presented, and then the possible shapes of the used price functions will be described.
  4.4. Algorithm Development
The proposed algorithm is based on the algorithm presented in [
8] utilizing the Lagrangian dual problem for EDP and further improves it. The designed algorithm derives a distributed EDP solution using local 
 estimation using only local communication for each generator [
8,
49].
Initially, it is also necessary to state some assumptions that will be considered for the entire algorithm operation.
Assumption 2.  All considered price functions  are convex and continuously differentiable.
 This assumption is not violated even in the case of the considered shapes of the price functions for renewable resources given in Equations (
13), (
16), (
17), and (
19). That is because they are linear or constant functions. Linear functions and constant functions are both concave and convex.
Assumption 2, along with the condition described in Equation (
11), which is affine, meets the Slater condition. The Slater condition is essential for ensuring strong duality in a convex optimization problem and requires the feasible region to contain an interior point. In this context, an affine function comprises a linear function plus a constant, and its graph forms a straight line. This implies a zero duality gap, allowing the original problem outlined in 
Section 3 to be transformed into a Lagrange dual problem. Similarly, it can be argued that the condition (
3) for the extended problem is also affine, and therefore, along with 
Assumption 2, it satisfies the Slater condition in this case as well.
 As mentioned in the previous chapters, the communication topology of the network between N agents is represented using an unbalanced directed graph .
Remark 2.  The proper functioning of the algorithm relies on the graph  being strongly connected, primarily due to the need for information exchange among agents. The distributed solution would not operate appropriately if any network part were informationally isolated from the rest.
 Before the algorithm itself, it is necessary to define the set of all renewable resources as 
 to shorten the notation. Term 
 and 
 represent a set of conventional units and BESS. In each agent in the network, the following three equations are calculated, which thus define the entire iterative algorithm: 
For the first two equations, three distinct calculations can occur, depending on whether the agent represents a conventional power plant (index c), renewable resources (index ), or a BESS (index b) with price functions , , or . Variable  represents the i-th generator estimation of the optimal incremental cost. The calculations for all three options are nearly identical, differing only in the price function used and, consequently, the form of the gradient calculation . Term  expresses the corresponding power generation and has three calculation options.
The first option calculates for all conventional controllable power plants belonging to the set . The second option represents renewable sources like solar and wind, which are not controllable and which belong to the set . It can be only decide whether to provide the energy to the grid or store it in the BESS. The third option indicates the calculation of the BESS, which belongs to the set . Variables  and  represent primal and dual variables, while  denotes the consensus variable. The parameter  signifies the consensus weight, and parameters , , and  represent the variable fuel price for conventional power plants, renewables, and BESS, respectively, in percentage (). Function  denotes the charging or discharging decision function of the BESS, and  designates the step size, sometimes called learning gain.
Remark 3.  An agent representing only the local load in the considered network topology  and would not provide any produced power information to the network.
 Definition 1.  For all  and  the uncoordinated learning gain has a form [8]:where the term  from Equation (25) satisfies: Term  can be chosen in the following form:where terms  and  are adjustable parameters of . If  has the shape given in (26) then  can be designed by following equation:  Definition 1 for  gives each generator freedom in the choice of parameter  thanks to the shape of .
The nominal value for the actual energy price is typically set at 100%. The choice of the considered initial condition is up to the designer of the concrete solution. Parameter  is inversed because the price function gradient  is also considered in its inverse form. Term  indicates the energy stored in the battery system. It will further be established that  (a vector of ones). Finally,  represents the consensus weight.
Next, it will be focused on the procedure for constructing the weight matrix W.
Definition 2.  For all  and  one can define a positive scalar  for which:At the same time, the values of  must hold  for a given row of the weight matrix W.  From now on, it is essential to note that the indices i and j represent all types of power plants, including conventional, renewables, and BESS. The  lower bound ensures that the information link between agents i and j will not be too weak. Furthermore, in line with Definition 2, the entire weight matrix W associated with the graph  is row stochastic  and .
Each generation unit  only requires its local information, denoted as  (the number of incoming edges), to construct the row-stochastic weight matrix W. Each agent can independently determine  value without needing information from its neighbors.
In order to fulfill this requirement, the values for 
 should be chosen according to:
In this case, Definition 2 is satisfied by choosing .
Next, it will be moved to the shape of the 
 gradient calculation. The gradient of 
 calculation have following shape:
The variable 
 is bounded from above due to the sum of maximum possible power 
 and virtual required loads 
 across all generators:
The variable 
 indicates a virtual local demand with no physical meaning. It is used only for the ability to build a distributed algorithm. Thus, 
 values can be chosen randomly across all agents in the network only under the condition that their sum corresponds to the required load 
 to meet the condition stated in (
34) [
8].
In the article [
62], it is stated that the standard gradient method without weighting by the term 
 can only lead to the minimization of the term 
 instead of term 
, especially for the reason of unbalancedness of directed graph. Here 
 applies where it is the 
i-th member of the vector 
. It is, therefore, a left-normalized vector of eigenvalues (Perron vector) of the matrix 
W that satisfies:
The vector , sometimes called the “Perron vector”, is relevant in the context of the “Perron–Frobenius Theorem” (The Perron–Frobenius Theorem stated that a real square matrix with positive entries has a unique largest real eigenvalue and that the corresponding eigenvector can be chosen to have strictly positive components, and then a similar statement for certain classes of non-negative matrices. This Theorem has essential applications to probability theory, theory of dynamical systems, economics, and many more.) Computing this vector in advance would enable scaling the gradient by it. However, determining the Perron vector in advance is challenging since the algorithm cannot perform this step until each generator knows its local . To address this, the variable  is introduced for asymptotic estimation of the Perron vector.
The re-scaling gradient technique was initially introduced in [
63]. It is essential to note that one requirement for this method to function correctly is that each generator knows the total required network load 
. Knowledge of 
 can be ensured through a strongly connected graph, information transmission, and unique identifiers for each generator.
Now, let us delve into the calculation for the quadratic price function, which applies to conventional generators and is the most complex part. In (
23), the argument of the 
 function involving 
 does not have a closed-form solution for a universal convex cost function. Moreover, for 
, will be received:
If a quadratic price function of 
 (
21) is considered then 
 has form:
        where 
 and 
 are parameters of the 
i-th conventional generator.
Similarly, renewable sources and BESS, which have maximum energy limits, can be constrained by  or . In the case of BESS, this function also includes deciding whether to provide power to the grid or store it, denoted as the  decision function.
  4.4.1. Sequence of Operations for Deploying the Algorithm
The possible implementation of the described algorithm will be outlined here in a very simple way. A simplified flowchart of the operations sequence with the presented algorithm is shown in 
Figure 4. The entire process runs in a continuous loop. The calculation block contains the calculation of the Equations of the algorithm (
22)–(
24). The yellow block indicates the starting initialization. Finding a consensus means that all online agents in the network have reached the same value of 
. If the convergence has been achieved then the production plan can be passed to the individual generators, which is represents by green block. The gray block represents changes in the network settings, desired load, or other inputs from other agents. These modifications can lead to a change in the 
 value or the local requirements of 
, and the entire algorithm is thus recalculated.
At this place it is important to mention that the entire algorithm runs online and thus reacts to any changes in the input information itself. This fact will be further demonstrated by examples in 
Section 5. The aim of this analysis is to provide better insight into the possible integration of the presented algorithm.
  4.4.2. Convergence Analysis
In this section, the analysis of convergence for the algorithm will be conducted. Before delving into the convergence analysis, it is essential to establish specific facts about the directed graph  and the weight matrix W. The subsequent Lemmas and Theorems will be stated generically using the index i, ensuring their applicability to all source types.
Lemma 1.  Definitions 1 (Equation (
25)
) and 2 (Equation (
28)
) hold for the graph  and the matrix W. Parameter  is left normalized eigenvalues vector of the matrix W. Then there exists a parameter  and  such that  and , it holds that [63]:Furthermore, a constant  will be introduced such that:This Lemma will subsequently be used to establish results for asymptotic consensus.  Lemma 2.  In this Lemma, the following sequence will be introduced [63]: Here, Definition 1 still holds for . Subsequently, a variable  will be introduced:where the parameter  was defined in Lemma 1. Furthermore, if it is considered that  then: In this Lemma, the deterministic counterpart to the supermartingale convergence Theorem is thus relied upon to achieve asymptotic convergence for the dual variable . (Doob’s martingale convergence Theorems, named after mathematician Joseph L. Doob, deal with the limits of supermartingales. Supermartingales are like decreasing sequences in the world of random variables. The main idea is that, under certain conditions, a supermartingale will always converge. This Theorem is akin to the monotone convergence Theorem, which tells us that bounded decreasing sequences converge.)
 Lemma 3.  In the next step, a non-negative scalar sequence  will be introduced for  such that it satisfies [64]:where for the parameters  with the condition for  and :It follows that , where σ is a non-negative constant for which  and at the same time .  Lemma 4.  (Asymptotic consensus) Here, it will be returned to the algorithm defined by the Equations (22)–(24). Furthermore, it will be assumed that Assumptions 1–3 and Definitions 1 and 2 still hold true. Subsequently, a variable  will be introduced [8]: Then the form for the limit can be written as: This results in the convergence of  to the optimal value reached by all agents in the network. Proof can be found in Appendix A.  Lemma 5.  It will be assumed that Assumptions 1–3 and Definitions 1 and 2 hold true again. Consequently, for any  and , the following holds [8]:Proof can be found in Appendix B.  Lemma 6.  Renewable sources cannot be controlled. Their operation is thus directly dependent on the current weather, as stated in Assumption 1. However, if their electricity production is available, it can be decided whether and in what quantity it will be consumed locally, provided to the grid, stored in battery systems or unused. In the case of using all the provided energy, this can be imagined as a change in the value of the required load  for the entire system: Thus, the entire right side can be marked as , which represents the reduced value of the total required load D by renewable resources: Similarly, based on the current needs and requirements, the claim could be modified only for partial use of the total power provided by renewable sources or its partial storage in the BESS.
 Lemma 7.  Similar to the Lemma 6 BESSs can either provide energy to the local network in island mode (discharge), to the grid (discharge), absorb it from local assets or from the grid (charge). Their state depends on the upcoming input, which determines their operation. This decision-making process relies on specific design and logic.
In the case of using energy from BESS or storing the energy to the BESS, change to the  can be written as:where a new value of the total required load  can be introduced again, which will increase or decrease the original value of  depending on whether the BESS is being discharged or charged:  Remark 4.  If the connection to the grid is ensured,  will be preserved and used in the equations. If the island mode of the local network is considered, then the term  will be considered as zero.
 Based on all the mentioned Lemmas, Theorem 1 can be constructed.
Theorem 1.  Let Assumptions 1–3 and Definitions 1 and 2 hold true. Then the algorithm stated in (22)–(24) solves the problem defined in Section 3 in Equation (2)–(4). This can be written as for  applies:where variable  represents optimal incremental cost and  denotes optimal power generation for each i-th generator in the graph . It follows that the algorithm converges to the optimal solution. Proof can be found in Appendix C.  From Lemma 6 and Lemma 7, it becomes evident that renewables generate power according to weather conditions. At the same time, BESSs can supply or draw power from the grid through a control function both in island mode and when connected to the grid.
  4.4.3. Zero Cost for Renewables
In the case of the considered zero fuel price 
 and 
 for renewable sources, the calculation of the Equation for (
22) for 
 will be changed. The remaining two Equations (
23) and (
24) remain unchanged.
          
		  This adjustment can be afforded because the price for solar or wind energy is zero, and its availability depends only on the weather. This simplification will also be used in 
Section 5 in the simulation examples.