# Joint Acquisition Time Design and Sensor Association for Wireless Sensor Networks in Microgrids
## 4 Problem Formulation and Problem Solution
### Overall Algorithm Design  
Based on the previous description, we propose a total iterative Algorithm 1 to obtain the acquisition time \(T\) and sensor associations \(\mathbf{X}\) to solve the problem effectively with low computational complexity. First, the CHs, sensor association \(\mathbf{X}\) and Lagrangian multipliers \(\{\mathbf{\lambda},\
u\}\) are randomly initialized, and then the acquisition time \(T\) from steps 6 to 9 is obtained through multiple iterations of the sub-gradient algorithm, until the sub-gradient algorithm converges to the specified accuracy. We can solve the problem **P2** and obtain the sub-optimal sensor association \(\mathbf{X}\) based on above description from steps 10 to 22. In the process of solving this problem, \(w_{ij}\) needs to be calculated. It represents the price of the knapsack problem. Then, we iteratively consider all CMs. When all CMs are associated with the CHs, the sensor association \(\mathbf{X}\) is obtained. As for the problem **P**, we use multiple iterations to find its solution. By applying the BCD method, the process of obtaining the acquisition time \(T\) and the sensor association \(\mathbf{X}\) requires multiple iterations to obtain a sub-optimal solution. Finally, the CHs are selected based on the sensor association result according to the CHs selection algorithm from steps 25 to 26. Of course, the CHs selection and acquisition time \(T\) and sensor association \(\mathbf{X}\) also need to be iterated many times until the CH and \(\mathbf{X}\) no longer change. This is because the CHs are randomly initialized during initialization, and a high-quality topology control strategy can be obtained after multiple iterations. Finally, after a finite number of iterations when the algorithm converges to the predetermined accuracy, we believe that the problem **P** is successfully solved. The details of the algorithm are summarized as algorithm ATSAO. Figure 2 shows the flowchart of the ATSAO algorithm. Firstly, CHs and sensor association are initialized randomly. Secondly, the BCD algorithm is used to solve the optimization problem formulated in this paper. In each iteration, the acquisition time is optimized through the Lagrangian dual method under the given sensor association. The sensor association is optimized based on the optimization results of acquisition time. When the change of the optimization objective function is below a predefined threshold, it shows that the BCD algorithm converges. After that, a low-complexity CH selection algorithm is proposed to obtain the CHs. After the CHs and sensor association are no longer changed, the algorithm ATSAO converges. In the system model of this paper, we assume that there are \(K\) CHs and \(N-K\) CMs in the WSN, and the number of CMs in each cluster is \(|\mathcal{Z}_{1}|,\cdots,|\mathcal{Z}_{K}|\). In the ATSAO, the algorithm complexity involved in solving the problem \(P2\) is \(o(K(N-K)^{2})\), the complexity of CHs selection algorithm is \(o(K(|\mathcal{Z}_{1}|^{2}+|\mathcal{Z}_{2}|^{2}+\cdots+|\mathcal{Z}_{k}|^{2}))\). Due to \(|\mathcal{Z}_{1}|^{2}+|\mathcal{Z}_{2}|^{2}+\cdots+|\mathcal{Z}_{k}|^{2}\leq \left(|\mathcal{Z}_{1}|+|\mathcal{Z}_{2}|+\cdots+|\mathcal{Z}_{k}|\right)^{2}\) and \(\left(|\mathcal{Z}_{1}|+|\mathcal{Z}_{2}|+\cdots+|\mathcal{Z}_{k}|\right)^{2}= (N-K)^{2}\), the total algorithm complexity is \(o(K(N-K)^{2})\). If the problem \(P2\) is solved by GREEDY algorithm, its complexity is \(o(K(N-K))\). ```
1:Initialize CHs and sensor association \(X^{0}\) randomly. 2:Initialize \((\lambda,\
u)^{1}\) and \(r_{1},r_{2},r_{3}=0\). 3:repeat
4:repeat
5:repeat
6: Update \(T^{r_{1}}\) according to Equation (16). 7: Update \((\lambda,\
u)^{r_{1}+1}\) according to Equations (17) and (18), respectively. 8: Update \(r_{1}=r_{1}+1\). 9:until Sub-gradient algorithm converges to a prescribed accuracy. 10: Calculate \(w_{ij}\) according to Equation (20). 11:while\(\mathcal{L}\
eq\oslash\)do
12:\(d^{*}=-\infty\). 13:for each node \(i\in\mathcal{L}\)do
14:\(j^{\prime}=\arg\max\{w_{ij},\forall i\in\mathcal{L}\}\).