## 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
#### 2.2.3 Clustering Generation and Optimization Model

After the cluster head is determined, the system will optimize the cluster with the goal of minimizing the total energy consumption and balancing the energy consumption among nodes, so as to maximize the lifetime of the special wireless sensor network sub-network. By optimizing the number of cluster members and the corresponding relationship between cluster head and cluster members, the minimization of energy consumption is taken into account under the premise of ensuring the balance of energy consumption, effectively guaranteeing the maximization of sub-network life cycle. The energy consumption of cluster head node is determined together by the distance between cluster head and sink node and the number of cluster members. However, the distance between cluster head and sink node varies with the choice of cluster head. Therefore, the number of cluster members should also change to ensure the energy balance between cluster head nodes. The cluster size optimization model is defined as follows:

\[f_{1}(E_{Ci}(n_{i}))=\min\frac{\sum_{i=1}^{k}\left(E_{Ci}(n_{i})-\overline{E_ {C}}\right)^{2}}{k} \tag{16}\]

where the objective of \(f_{1}(E_{Ci}(n_{i}))\) is to minimize the variance of energy consumption among all cluster heads, it represents the equilibrium of energy consumption of each cluster head. \(E_{Ci}\) represents cluster head energy consumption of \(i\)-th cluster, \(\overline{E_{C}}\) represents mean energy consumption of cluster heads for all clusters, \(k\) represents the number of clusters and cluster heads. After cluster size optimization, the energy consumption among cluster heads is basically balanced, while the cluster size optimization model only determines the number of members in each cluster, and it does not determine the corresponding relationship between non-cluster head nodes and cluster heads. However, when the same cluster member node is assigned to different clusters, the communication energy consumption varies with the distance from the cluster head node. In order to minimize the communication energy consumption of non-cluster head nodes, the corresponding relationship between cluster head and cluster members needs to further optimize. The total energy consumption model for all nodes is defined as:

\[E_{R}^{i}(r)=E_{R}^{i}(r-1)-E_{C_{0}}^{i}(r-1) \tag{8}\]0

where the objective of \(f_{2}\Big{(}E_{Cj},E_{non-Ci}\Big{)}\) is to minimize the total energy consumption of all nodes, \(E_{non-Ci}\) represents energy consumption of the \(i\)-th non-cluster head node, \(E_{Cj}\) represents energy consumption of the \(j\)-th cluster head. The optimization of cluster size is used to balance the energy consumption among cluster head nodes, while the optimization of the corresponding relationship between cluster head and cluster members can effectively reduce the total energy consumption of non-cluster head nodes. At the same time, the optimization of the corresponding relationship between cluster head and cluster members will affect the optimization of cluster size in turn. Therefore, the optimization of cluster size and the corresponding relationship between cluster head and cluster members is a multi-objective optimization problem, which can be summed up as a kind of problem which can make multiple objectives reach optimal simultaneously under certain constraints. For example, in order to select the appropriate cutting speed and feed ratio in mechanical processing, the objectives are put forward: (1) The lowest machining cost, (2) the highest productivity, and (3) the longest cutter life. The comprehensive optimization model of node clustering is defined as:

\[E_{R}^{i}(r)=E_{R}^{i}(r-1)-E_{C_{0}}^{i}(r-1) \tag{8}\]1

There are two constraints which must be satisfied for clustering multi-objective optimization model: The first constraint is that the total number of nodes in each cluster should be at least two, and the second constraint is that failed sensor nodes do not participate in the formation and optimization of a new round of node clustering.