## 4 Models and Algorithm Design
### Algorithm Development
The gradient of \(\Phi_{i}(\lambda_{i})\) calculation have following shape:  
\[\
abla\Phi_{i}(\lambda_{i})=P_{i}(\lambda_{i})-P_{D_{i}}.\]  
The variable \(\Phi_{i}(\lambda_{i})\) is bounded from above due to the sum of maximum possible power \(P_{i}\) and virtual required loads \(P_{D_{i}}\) across all generators:  
\[|\
abla\Phi_{i}(\lambda_{i})|=|P_{i}(\lambda_{i})-P_{D_{i}}|\leq\max_{i\in \mathcal{G}}P_{i}^{max}+\max_{i\in\mathcal{G}}P_{D_{i}}.\]  
The variable \(P_{D_{i}}\) indicates a virtual local demand with no physical meaning. It is used only for the ability to build a distributed algorithm. Thus, \(P_{D_{i}}\) values can be chosen randomly across all agents in the network only under the condition that their sum corresponds to the required load \(P_{D}\) 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 \(y_{ii}\) can only lead to the minimization of the term \(\sum_{i=1}^{N}\pi_{i}\Phi_{i}(\lambda)\), instead of term \(\sum_{i=1}^{N}\Phi_{i}(\lambda)\), especially for the reason of unbalancedness of directed graph. Here \(\pi_{i}\in(0,1)\) applies where it is the \(i\)-th member of the vector \(\pi=[\pi_{1},...,\pi_{N}]^{T}\in R^{N}\). It is, therefore, a left-normalized vector of eigenvalues (Perron vector) of the matrix \(W\) that satisfies:  
\[\lim_{k\rightarrow+\infty}W^{k}=1_{N}\pi^{T},\quad\text{and}\quad 1_{N}^{T}\pi=1.\]  
The vector \(\pi\), 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 \(\pi_{i}\). To address this, the variable \(y_{i}(k)\) 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 \(P_{D}\). Knowledge of \(P_{D}\) 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 \(\varphi\)function involving \(\
abla C_{c_{i}}^{-1}\big{(}\lambda_{c_{i}}(k+1)\big{)}\) does not have a closed-form solution for a universal convex cost function. Moreover, for \(\varphi_{i}\big{(}\
abla C_{c_{i}}^{-1}(\lambda_{c_{i}}(k+1))\big{)}\), will be received:  
\[\varphi_{c_{i}}\big{(}C_{c_{i}}^{-1}(\lambda_{c_{i}}(k+1))\big{)}= \begin{cases} P_{c_{i}}^{max},&\text{if}\quad C_{c_{i}}^{-1}\big{(}\lambda_{c_{i}}(k) \big{)}>P_{c_{i}}^{max},\\ \
abla C_{c_{i}}^{-1}\big{(}\lambda_{c_{i}}(k)\big{)},&\text{if}\quad P_{c_{i} }^{min}\leq C_{c_{i}}^{-1}\big{(}\lambda_{c_{i}}(k)\big{)}\leq P_{c_{i}}^{max},\\ P_{c_{i}}^{min},&\text{if}\quad C_{c_{i}}^{-1}\big{(}\lambda_{c_{i}}(k) \big{)}<P_{c_{i}}^{min}.\end{cases} \]  
If a quadratic price function of \(C_{c_{i}}\) (21) is considered then \(\
abla C_{c_{i}}^{-1}(\lambda_{c_{i}})\) has form:  
\[\
abla C_{c_{i}}^{-1}(\lambda_{c_{i}})=\beta_{c_{i}}\lambda_{c_{i}}+\alpha_{c _{i}},\]  
where \(\alpha_{c_{i}}\) and \(\beta_{c_{i}}\) are parameters of the \(i\)-th conventional generator. Similarly, renewable sources and BESS, which have maximum energy limits, can be constrained by \(\varphi_{s,u_{i}}\) or \(\varphi_{b_{i}}\).