## 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  
K-medoids algorithm can cluster all nodes and distribute the nodes with similar distances into a unified cluster. However, the initial cluster centers of K-medoids algorithm are randomly selected. The clustering effect depends on the selection of the initial cluster centers. Unbalanced distribution of cluster centers will lead to local optimum clustering results. Therefore, the improved K-medoids algorithm is proposed to cluster in this paper. It ensures that the initial cluster centers are distributed as evenly as possible in the whole monitoring area, and improves the global optimal performance of the clustering results. In addition, when the improved K-medoids algorithm is used to optimize clustering based on genetic algorithm, its optimization speed and effect are improved significantly. When improved K-medoids algorithm is used to initialize clusters, the optimal number of clusters must be determined firstly. When the number of clusters is too small, the number of cluster members increases correspondingly, which will greatly increase the communication burden and energy consumption of cluster head nodes. When the number of clusters is too large, most sensor nodes and sink nodes transmit data directly, and the clustering optimization algorithm will become meaningless. So, it is necessary to optimize the number of clusters with the objective of minimizing the total energy consumption of all nodes in the sub-network. Suppose that \(T\) sensor nodes are evenly located in the monitoring sub-network area of \(N\times N\), where \(\mathrm{x}\in[-N/2,N/2]\), \(\mathrm{y}\in[-(1+\varepsilon)N,-\varepsilon N]\), \(\varepsilon\) is a distance adjustment parameter, it is used to adjust the vertical distance between monitoring sub-network area and sink node. The probability density of distribution is \(S(x,y)=1/M^{2}\). The sink node is located at the origin of coordinates. All sensors distributed in the sub-network are divided into cluster head nodes and cluster member nodes, so the total energy consumption of sub-network nodes is also composed of two parts as follows:  
\[E_{total}=\sum_{i=1}^{k}\left(E_{C}^{i}+\sum_{j=1}^{n-1}E_{Non-C}^{ji}\right) \tag{4}\]  
where \(E_{C}^{i}\) represents energy consumption of the \(i\)-th cluster head node, \(E_{Non-C}^{ji}\) represents energy consumption of the \(j\)-th non-cluster head node in the \(i\)-th group, \(n\) represents the number of sensor nodes within each cluster, \(k\) represents the number of clusters. Assuming that \(T\) nodes within the sub-network are evenly allocated to each cluster, there are \(n=T/k\) nodes in each cluster, including one cluster head and \(T-1\) non-cluster head nodes. When all nodes have enough energy to receive, process, and send all data in the cluster with the role of cluster head. However, the residual energy of sensor nodes decreases with the increase of communication rounds. When the energy of all nodes in a cluster is below a certain threshold, it is not enough to send all data in the cluster to the sink node as the cluster head. In this paper, the number of sensor nodes in each cluster and the amount of data transmitted by cluster head will be reduced by increasing the number of clusters, effectively reducing the energy consumption of cluster head so that the communication of the system can be restored and continued. In this paper, based on the optimal cluster groups, an improved K-medoids algorithm is used to initialize the clusters. According to the distance information of all sensor nodes in the sub-network, it is allocated to \(K\) clusters.