## 3 Preliminary Work
### Algorithm to Calculate Mileage Matrix  
For the calculation of the mileage matrix \([M]_{n\times n}\), we needed to decide whether a branch lies in the path between two nodes, which is a time-consuming process. A simple algorithm is discussed here for calculating the mileage matrix from the edge weight matrix of a graph. Suppose that \([W]_{(n+1)\times(n+1)}\) is the edge weight matrix, and its element \(W_{ij}(i,j\in\{0,1,2\ldots n\})\) is the length of the branch between node \(i\) and node \(j\) if it exists. Otherwise, \(W_{ij}\) is 0. The pseudocode for algorithm is shown in Algorithm 1. ``` Input: \(M\), \(P\), \(M\), \(P\)



## 4 Power-mileage-based Network Optimization

The main task of network optimization is to separate the sub-graph that is far from the national grid and whose power is imbalanced. As we illustrated in Section 2, this means the optimal overall voltage profile, or, minimum power mileage. So, the object of the network optimization algorithms is to find the specific separation of a grid \(G\) satisfy:

\[ \begin{array}{c}\min f=\max\{PM(G_{1}),PM(G_{2}),\cdots\cdots PM(G_{n})\}\\ G_{1}\cup G_{2}\cup G_{3}\cup\cdots\cdots G_{n}=G\\ \underset{i\
eq j}{\forall}G_{i}\cap G_{j}=\varnothing\end{array}  \tag{6}\]

where PM(\(G_{i}\)) means the total power mileage of \(G_{i}\). To implement such an idea, an iterative power-mileage-based method is proposed. In each turn, the algorithm only divides the grid into two sub-grids, and thus it works greedily in each turn to find the best separation which satisfies Equation (6) (which is discussed in Section 4.1). In the process of network optimization, there were two issues that needed to be considered: how to choose the best partition and when to stop the iteration. We used an effective indicator in our algorithm, which is explained in Section 4.2. ### Network Optimization Algorithm

The scheme of the algorithm is shown as follows. Step 1: For a given graph \(G\), each possible candidate for the partition is examined and the best partition is chosen. In this process, \(G_{1}\), \(G_{2}\) and their power mileage \(PM_{1}\), \(PM_{2}\) are obtained. Step 2: Check whether the best partition satisfies the terminal condition. If so, graph \(G\) is returned. If not, repeat Steps 1 and 2 in graphs \(G_{1}\) and \(G_{2}\) separately. With the iterative operation and terminal condition, the algorithm can automatically choose the number of clusters and stops when the terminal condition is satisfied. Also, in each iteration, the objective function in Equation (6) is achieved, thus the algorithm greedily finds the optimal separation of the whole grid. The aim of this algorithm is to separate the sub-graph, which is imbalanced in power and far from the national grid. If the best partition in Step 1 does not satisfy these two purposes, the algorithm should stop. We wanted the power mileage per branch in \(G_{1}\) to be larger than that in \(G_{2}\) so that the imbalance in power is satisfied. We also did not want the voltage profile in the sub-graph to be worse than the original one, so \(\max\{PM_{1},PM_{2}\}\). should be smaller than \(\frac{PM}{2}\). In addition, the number of clusters should not be too large, and the sub-graph should not be too small. In other words, we did not want the algorithm to iterate too many times. As a result, a punishment was added to the secondterminal condition. The terminal conditions are not satisfied when both of the following formulas are met. \[\frac{PM_{1}}{\#(G_{1})}<\frac{PM_{2}}{\#(G_{2})} \tag{7}\]

\[\min_{\forall candidates}\{\max\{PM_{1},PM_{2}\}<\frac{PM}{2}\times ratio \tag{8}\]

where \(\#[G]\) means the number of nodes in \(G\) and \(ratio\) means the length of the sub-graph over the length of the original graph. Equation (7) ensures the imbalance property of the separated graph and Equation (8) ensures the quality of the separation. The existence of \(ratio\) punishes the algorithm for splitting the graph too many times.