## 4 Distributed Optimal Dispatching Model and Algorithm of MGs and ESP Based on ADMM  
### Distributed Optimal Dispatching Model of MGs and ESP Based on ADMM  
Due to the excellent performance in robustness and convergence, ADMM has been widely applied in large-scale distributed optimization problems recently [40]. The standard form of ADMM can be presented as:  
\[min s(\mathbf{x})+t(\mathbf{z})\] \[s.t. A\mathbf{x}+\mathbf{B}\mathbf{z}=\mathbf{c} \tag{16}\]  
where \(\mathbf{x}\in\mathbb{R}^{n}\); \(\mathbf{z}\in\mathbb{R}^{m}\); \(\mathbf{A}\in\mathbb{R}^{p\times n}\); \(\mathbf{B}\in\mathbb{R}^{p\times m}\); \(\mathbf{c}\in\mathbb{R}^{p}\). According to (12), the objective function is decomposed into two parts including \(s(\mathbf{x})\) and \(t(\mathbf{z})\), and the constraint denotes the equality constraint of decision variable \(\mathbf{x}\) in \(s(\mathbf{x})\) and decision variable \(\mathbf{z}\) in \(t(\mathbf{z})\). The algorithm can converge to the optimal solution under the condition that the convex function \(s\) is fit with \(\mathbb{R}^{n}\rightarrow\mathbb{R}\cup\{+\infty\}\) and \(t\) is a convex function in accordance with \(\mathbb{R}^{m}\rightarrow\mathbb{R}\cup\{+\infty\}\)[40]. In addition, functions \(s\) and \(t\) can take the value of \(+\infty\). Therefore, \(s\) and \(t\) not only can express specific optimization objectives, but they also can represent some equality constraints or inequality constraints. When variables dissatisfy these constraints, the function takes the value of zero; otherwise, the function takes the value \(+\infty\). The optimization problem including objective function and constraints in this paper can be converted into the standard form of ADMM, which is shown as follows:  
\[min\qquad\sum_{n=1}^{N}C_{n}(\mathbf{x}_{n})+g(\mathbf{w}) \tag{17}\]  
\[s.t.\ \ \left[ \begin{array}{cccc}x_{1}^{in}&\cdots&x_{N}^{in}&x_{grid1}&\cdots&x _{gridN}\\ \end{array} \right]^{T}+\mathbf{B}\mathbf{w}=0 \tag{18}\]  
\[\mathbf{B}=\left[ \begin{array}{cc}\mathbf{B}_{1}&\mathbf{0}\\ \mathbf{0}&\mathbf{B}_{2}\\ \end{array} \right] \tag{19}\]  
where \(\mathbf{B}\) is a matrix with \(2N\) rows and \(2N\) columns and \(\mathbf{B}_{1}\) and \(\mathbf{B}_{2}\) are matrices with \(N\) rows and \(N\) columns. As for \(\mathbf{B}_{1}\), the diagonal elements are \(-1\); the last element of first row is one; the \((n-1)\)-th (\(n\
eq 1\)) column element of the \(n\)-th row is one; the other elements are zero. In terms of \(\mathbf{B}_{2}\), the diagonalelements are \(-1\), and the other elements are zero. The constraint (18) ensures that the expected exchange power decided by MGs is equal to the adjusted expected exchange power decided by ESP, which indicates that optimal scheduling is achieved with a comprehensive consideration of purchasing electricity cost, energy storage cost and power loss cost. According to the basic principle of ADMM [40], the final iteration form of the distributed optimization problem in this paper can be expressed as follows:  
\[\mathbf{x}_{n}^{k+1}=\arg\min_{\mathbf{x}}(C_{n}(\mathbf{x}_{n})+\frac{\rho}{2}\left\| \left[ \begin{array}{c}x_{n}^{in}\\ x_{gridin}\end{array} \right]+\left[ \begin{array}{c}(\mathbf{B}\mathbf{w}^{k})_{n}\\ (\mathbf{B}\mathbf{w}^{k})_{N+n}\end{array} \right]+\left[ \begin{array}{c}\mathbf{u}_{n}^ {k}\\ \mathbf{u}_{N+n}^{k}\end{array} \right]\right\|_{2}^{2}) \tag{20}\]  
\[\mathbf{w}^{k+1}=\arg\min_{\mathbf{w}}(g(\mathbf{w})+\sum_{n=1}^{N}\frac{\rho}{2}\left\| \left[ \begin{array}{c}x_{n}^{in^{k+1}}\\ x_{gridin}^{k+1}\end{array} \right]+\left[ \begin{array}{c}(\mathbf{B}\mathbf{w})_{n} \\ (\mathbf{B}\mathbf{w})_{N+n}\end{array} \right]+\left[ \begin{array}{c}\mathbf{u}_{n}^{k}\\ \mathbf{u}_{N+n}^{k}\end{array} \right]\right\|_{2}^{2}) \tag{21}\]  
\[\mathbf{u}^{k+1}=\mathbf{u}^{k}+\left[ \begin{array}{cc}x_{1}^{in^{k+1}}&\cdots&x_{N}^ {in^{k+1}}&x_{grid1}^{k+1}&\cdots&x_{gridN}^{k+1}\\ \end{array}