## 2 Methodology
### An Optimal Energy Resources Allocation Method Based on Clustering Optimization
#### 2.2.1 Clustering and Cluster Head Initialization Based on Improved K-Medoids
The specific steps of cluster initialization based on improved K-medoids algorithm (Algorithm 1) are defined as follows:```
Input: Location and energy information of \(T\) sensor node in in the monitoring sub-network area of \(N\times N\) Output: \(T\) sensor nodes are allocated to \(K\) clusters in the mode of optimal energy consumption Step 1: Determining the optimal clustering group number \(k_{opt}\); Step 2: Selecting a sensor node as the first cluster center randomly; Step 3: Calculating the distance from each node to the selected cluster center; repeat for\(i=1,2,\ldots,k\) for\(j=1,2,\ldots,T-k\) \(d_{CloC_{j}}=\sqrt{\left(x(j)-x(i)\right)^{2}+\left(y(j)-y(i)\right)^{2}}\) until the distances between all nodes are calculated Step 4: Selecting the \(k\)-th (\(1<k<k_{opt}\)) clustering center repeat for\(j=1,2,\ldots,T-k\) for\(i=1,2,\ldots,k\) \(d_{CloC_{j}}=\min\)\(\left(d_{CloC_{j}}\right)\); \(\sum\)\(\left(d\left(x_{CloC_{j}}\right)\right)=\sum\limits_{j=1}^{T-k}d_{CloC_{j}}\) \(p_{j}=\frac{d\left(x_{CloC_{j}}\right)}{\sum\)\(\left(d\left(x_{CloC_{j}}\right)\right)\) until all \(k_{opt}\) cluster centers had been selected Step 5: Initialization of all clusters based on selected \(k_{opt}\) cluster centers repeat for\(i=1,2,\ldots,k_{opt}\) for\(j=1,2,\ldots,T-k_{opt}\) \(d_{CloC_{j}}=\sqrt{\left(x(j)-x(i)\right)^{2}+\left(y(j)-y(i)\right)^{2}}\) for\(j=1,2,\ldots,T-k_{opt}\) for\(i=1,2,\ldots,k_{opt}\) \(d_{CloC_{j}}=\min\)\(\left(d_{CloC_{j}}\right)\); until all sensor nodes are allocated to the cluster with the lowest energy consumption. ```

**Algorithm 1** Cluster initialization based on improved K-medoids algorithm

In Step 4, the node far from the selected cluster center is more likely to be selected as the new cluster center, which can ensure the decentralization of the cluster center in the whole monitoring area. In Step 5, on the basis of determining the cluster center, each sensor chooses to join the cluster corresponding to the nearest cluster center, thus the initialization of the cluster would be completed. In the process of assigning all sensor nodes in the sub-network to \(K\) clusters by using the improved K-medoids algorithm, the cluster center is not the final cluster head. Therefore, after initialization of cluster, in order to minimize the total energy consumption of cluster members and cluster heads, the node with the smallest sum of distances from all nodes in the cluster is chosen as the cluster head. According to Equation (5), the position of virtual cluster head (the center of all nodes) is calculated, and then the nearest node to the virtual cluster head is selected as the initial cluster head node. \[Virtual_{H(x(k),y(k))}=(\frac{\sum_{i=1}^{n_{k}}x(i)}{n_{k}},\frac{\sum_{i=1}^{ n_{k}}y(i)}{n_{k}}) \tag{5}\]

Compared with other existing methods, cluster initialization based on improved K-medoids algorithm can divide the nodes with similar distance into the same cluster, which can reduce the energy consumption of information transmission between cluster members and cluster heads, and greatly improve the life cycle of the network. #### 2.2.2 Cluster Head Selection and Rotating Probability Model

In the routing protocol of cluster communication, the energy consumption of cluster head node is much larger than that of non-cluster head node. Therefore, the cluster head should be re-selected before each round of communication. It could effectively guarantee the energy balance among sensor nodes and avoid the failure of cluster head node due to excessive energy consumption. In the cluster head selection and rotating probability model, the candidate probability of cluster head, the residual energy rate of nodes, and the energy consumption rate of cluster head prediction are considered. In order to maintain the balance of energy consumption among nodes, each node in the cluster should have a relatively equal opportunity to serve as cluster head.