## 4 Models and Algorithm Design
### Algorithm Development
The second option represents renewable sources like solar and wind, which are not controllable and which belong to the set \(O_{s,w}\). 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 \(O_{b}\). Variables \(P_{i}(k)\) and \(\lambda_{i}(k)\) represent primal and dual variables, while \(y_{i}(k+1)\) denotes the consensus variable. The parameter \(w_{ij}\) signifies the consensus weight, and parameters \(\mu_{c_{i}}\), \(\mu_{s,w_{i}}\), and \(\mu_{b_{i}}\) represent the variable fuel price for conventional power plants, renewables, and BESS, respectively, in percentage (\(100\%=1\)). Function \(\mathrm{Y}()\) denotes the charging or discharging decision function of the BESS, and \(\gamma_{i}(k)\) designates the step size, sometimes called learning gain. **Remark 3**. : _An agent representing only the local load in the considered network topology \(P_{D_{i}}\) and would not provide any produced power information to the network._  
**Definition 1**. : _For all \(i\in O_{c,s,w,b}\) and \(k\geq 0\) the uncoordinated learning gain has a form [8]:_  
\[\gamma_{i}(k)=\frac{1}{k+1}+a_{i}(k)>0, \tag{25}\]  
_where the term \(a_{i}(k)\) from Equation (25) satisfies:_  
\[|a_{i}(k)|\leq a(k),\qquad\sum_{k=0}^{\infty}a(k)<\infty.\]  
_Term \(a_{i}(k)\) can be chosen in the following form:_  
\[a_{i}(k)=\frac{M_{i}}{(k+1)^{c_{i}}}-\frac{1}{k+1}, \tag{26}\]  
_where terms \(c_{i}\in\langle 0.5,1\rangle\) and \(M_{i}>0\) are adjustable parameters of \(a_{i}(k)\). If \(a_{i}(k)\) has the shape given in (26) then \(\gamma_{i}(k)\) can be designed by following equation:_  
\[\gamma_{i}(k)=\frac{M_{i}}{(k+1)^{c_{i}}}. \tag{27}\]  
**Definition 1** for \(\gamma_{i}(k)\) gives each generator freedom in the choice of parameter \(\gamma_{i}(k)\) thanks to the shape of \(a_{i}(k)\). 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 \(\mu_{c_{i}}^{-1}(k)\) is inversed because the price function gradient \(\
abla C_{c_{i}}(k)\) is also considered in its inverse form. Term \(E_{b_{i}}(t)\) indicates the energy stored in the battery system. It will further be established that \(\mu_{b_{i}}=1^{T}\) (a vector of ones). Finally, \(w_{ij}\) represents the consensus weight. Next, it will be focused on the procedure for constructing the weight matrix \(W\). **Definition 2**. : _For all \(i\in O_{c,s,w,b}\) and \(\kappa\geq 0\) one can define a positive scalar \(\kappa\in(0,1)\) for which:_  
\[w_{ij}= \begin{cases}>\kappa,\quad j\in\mathcal{G}\ \bigcup\ i,\\ \\ 0\quad\text{otherwise}.\end{cases}  \tag{28}\]  
_At the same time, the values of \(w_{ij}\) must hold \(\sum_{j=1}w_{ij}=1\) 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 \(\kappa\) 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 \(\mathcal{G}\) is row stochastic \(W=[w_{ij}]\in R^{N\times N}\) and \(W1_{N}\). Each generation unit \(i\in O_{c,s,w,b}\) only requires its local information, denoted as \(d_{i}^{in}\) (the number of incoming edges), to construct the row-stochastic weight matrix \(W\). Each agent can independently determine \(d_{i}^{in}\) value without needing information from its neighbors. In order to fulfill this requirement, the values for \(w_{ij}\) should be chosen according to:  
\[w_{ij}= \begin{cases}\frac{1}{d_{i}^{in}+1},\quad j\in\mathcal{G}\;\bigcup\;i,\\ \\ 0.\quad\text{otherwise}.\end{cases}  \tag{29}\]  
In this case, **Definition 2** is satisfied by choosing \(\kappa=\frac{1}{N}\). Next, it will be moved to the shape of the \(\Phi_{i}(\lambda_{i})\) gradient calculation.