## 4 Models and Algorithm Design
### Algorithm Development
#### 4.4.2 Convergence Analysis
\begin{split}\sum_{i=1}^{N}\pi_{i}||\lambda_{i}(k+1)-u||^{2}\leq \sum_{i=1}^{N}\pi_{i}||\lambda_{i}(k)-u||^{2}-\frac{2}{k+1}(\Phi(\overline{ \lambda}(k)-\Phi(u)))\\ +\frac{6 lh}{k+1}\sum_{i=1}^{N}\pi_{i}||\lambda_{i}(k)-\overline{ \lambda}(k)||+2 lha(k)\sum_{i=1}^{N}\pi_{i}||\lambda_{i}(k)-u||+h^{2}l^{2}\sum _{i=1}^{N}\pi_{i}\gamma_{i}^{2}(k)\\ +\frac{2 nh\beta^{k}_{\ast}}{k+1}||\overline{\lambda}_{i}(k)-u||. \end{split}  \tag{31}\]  
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 \(P_{D}\) for the entire system:_  
\[\sum_{i=1}^{N_{e}}P_{c_{i}}+\sum_{i=1}^{N_{b}}P_{b_{i}}+P_{g}=\Big{(}P_{D}- \sum_{i=1}^{N_{e}}P_{s_{i}}-\sum_{i=1}^{N_{w}}P_{w_{i}}\Big{)}.\]  
_Thus, the entire right side can be marked as \(P_{D_{num_{1}}}\), which represents the reduced value of the total required load \(D\) by renewable resources:_  
\[\sum_{i=1}^{N_{e}}P_{c_{i}}+\sum_{i=1}^{N_{b}}P_{b_{i}}+P_{g}=P_{D_{num_{1}}}.\]  
_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 \(P_{D}\) can be written as:_  
\[\sum_{i=1}^{N_{c}}P_{c_{i}}+\sum_{i=1}^{N_{t}}P_{s_{i}}+\sum_{i=1}^{N_{w}}P_{w_{i }}+P_{g}=\left(P_{D}-\sum_{i=1}^{N_{h}}P_{b_{i}}\right),\]  
_where a new value of the total required load \(P_{D_{new_{i}}}\) can be introduced again, which will increase or decrease the original value of \(P_{D}\) depending on whether the BESS is being discharged or charged:_  
\[\sum_{i=1}^{N_{c}}x_{c_{i}}+\sum_{i=1}^{N_{t}}x_{s_{i}}+\sum_{i=1}^{N_{w}}x_{w_ {i}}+P_{g}=P_{D_{new_{2}}}.\]  
**Remark 4**. : _If the connection to the grid is ensured, \(P_{g}\) will be preserved and used in the equations. If the island mode of the local network is considered, then the term \(P_{g}\) 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 \(k\to\infty\) applies:_  
\[\lambda_{i}(k)\to\lambda^{*},\quad P_{i}(k)\to P^{*},\quad\forall i\in \mathcal{G}, \tag{32}\]  
_where variable \(\lambda^{*}\) represents optimal incremental cost and \(P^{*}\) denotes optimal power generation for each \(i\)-th generator in the graph \(\mathcal{G}\). 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.