# Double-Consensus Based Distributed Optimal Energy Management for Multiple Energy Hubs
## 3 Distributed Algorithm
### DDC Algorithm without Inequality Constraints  
In this section, none of the inequality constraints are taken into consideration; the consideration of inequality constraints will be discussed in the next section. Based on the KKT conditions, we can obtain the relationship between the optimal solutions and the Lagrange multipliers (see Appendix B-(b) for details). This indicates that the optimal \(E_{i}^{e}\), \(E_{i}^{g,\rho}\) and \(E_{i}^{g,1-\rho}\) can be obtained if the optimal \(\lambda_{\text{e}}\) and \(\lambda_{\text{g}}\) can be calculated. Please note that \(\lambda_{\text{e}}\) and \(\lambda_{\text{g}}\) are both global decision variables. In contrast to centralized approaches, there is no central controller to correct the global information to calculate the optimal \(\lambda_{e}\) and \(\lambda_{g}\) and send the solution to each component. On the contrary, the challenge of this paper is to obtain the optimal \(\lambda_{e}\) and \(\lambda_{g}\) by using only local information and messages exchanged with neighbors. Meanwhile, \(\lambda_{e}\) and \(\lambda_{g}\) are interactive with each other. Inspired by the feature of (P1), the basic concept is to establish two different consensus protocols, in which the one is to make all \(\lambda_{i,e,p}\)(\(k\)) and \(\lambda_{i,e,c}\)(\(k\)) run a common value and the other is to make all \(\lambda_{i,g,c}\)(\(k\)) run another common value. Meanwhile a feedback term is added into the corresponding consensus protocol to obtain the optimal \(\lambda_{e}\) and \(\lambda_{g}\). Therein, the feedback term uses local estimation of the electricity and heat power mismatches to ensure power and heat supply-demand balances. Then, the designed DDC algorithm, mainly consisting of three parts, is given by:  
1. The united updating rules for energy hubs' coordination to estimate the electricity and heat multipliers are designed for \[\lambda(k+1)=R\lambda(k)+\eta\ y(k)\] (7) where \(R=[ \begin{array}{cc}R&0\\ 0&\overline{R}\end{array} ]\), \(R=[ \begin{array}{cc}R_{pp}&R_{pc}\\ R_{cp}&R_{cc}\end{array} ]\), \(\lambda=[\lambda_{e,p}^{T},\lambda_{e,c}^{T},\lambda_{g,c}^{T}]^{T}\) and \(y=[y_{e,p}^{T},y_{e,c}^{T},y_{g,c}^{T}]^{T}\). Based on the relationship between the optimal solutions and Lagrange multipliers, the updating rules for energy hubs to estimate the optimal \(E_{i}^{\epsilon}\), \(E_{i}^{\mathcal{E}\rho}\) and \(E_{i}^{\mathcal{S}1-\rho}\) are designed for \[x(k+1)\ =\ \mathbb{A}\lambda(k+1)+B\] (8) \[E(k+1)\ =\ \ x(k+1)\] (9) where \(\mathbb{A}\ =\ \left[ \begin{array}{ccc}A^{p}&0&0\\ 0&A^{pc}&-O^{pc}\\ 0&-O^{hc}&A^{h}\end{array} \right]\), \(B\ =\ \left[B_{p}^{T},B_{pc}^{T},B_{hc}^{T}\right]^{T}\), \(x\ =\ \left[x^{\tau T},x^{\delta\rho T},x^{\delta\rho T},x^{\delta\rho T -\rho T}\right]^{T}\) and \(E\ =\ \left[E^{\varepsilon T},E^{\delta\rho T},E^{\mathcal{S}1-\rho T}\right]^{T}\). Therein, \(A^{p}\ =\ diag(\overline{a}_{i}^{p})\), \(A^{pc}\ =\ diag(\overline{a}_{i}^{p,\mathcal{C}})\), \(A^{hc}\ =\ diag(\overline{a}_{i}^{h,c})\), \(O^{pc}\ =\ diag(\overline{a}_{i}^{p,\mathcal{C}})\), \(O^{hc}\ =\ diag(\overline{a}_{i}^{h,c})\), \(B_{p}^{T}\ =\ \left[\overline{p}_{i}^{p}\right]^{T}\), \(B_{pc}^{T}\ =\ \left[\overline{b}_{i}^{p,\mathcal{C}}\right]^{T}\) and \(B_{hc}^{T}\ =\ \left[\overline{b}_{i}^{h,\mathcal{C}}\right]^{T}\). 3. Please note that the electricity and heat power supply-demand balance constraints, i.e., Equations (4a) and (4b), are global constraints. Similar to the solving method for \(\lambda_{e}\) and \(\lambda_{g}\), the concept of local estimation of the mismatch between demand and total generations, obtained by using only neighbors' information, is used to solve the two global constraints in a distributed manner. Inspired by the features of (P2), the updating rules for the energy hubs' coordination to estimate the electricity and heat power mismatches are designed as follows: \[y(k+1)\ =\ Sy(k)-(E(k+1)-\ E(k))\] (10) where \(S\ =\ \left[ \begin{array}{cc}S&0\\ 0&\overline{S}\end{array} \right]\), \(S\ =\ \left[