## 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
That is to say, the \(T/k\) cluster members in the cluster have a chance to act as cluster head in the next \(T/k\) round communication process [19; 20]. If the sensor node in the subnet has served as cluster head in the previous \(r\)-1 round of communication, then the node will not participate in the cluster head election in the \(r\)-th round, so the candidate probability model of cluster head is defined as:

\[p_{1i}(r)=\left\{ \begin{array}{c}k/T-k\times r,\;C_{i}(r)=1\\ 0,\;\;\;\;\;\;\;\;\;\;\;C_{i}(r)=0\end{array} \right. \tag{6}\]

where \(r\in[1,T/k]\) represents that when all the nodes in the cluster have served as the cluster head once in the previous communication process, \(r\) will be reset to 1, then it gradually grows to \(T/k\). \(C_{i}(r)\) represents role state of node \(i\) in the past \(r\) round communication. If it had served as a cluster head, then \(C_{i}(r)=0\), otherwise, \(C_{i}(r)=1\). After multiple rounds of communication, the residual energy of each sensor node in the sub-network will be different from each other. In the process of cluster head selection and rotation, the probability that nodes with more residual energy are selected as cluster heads is higher. The residual energy probability model of each node is defined as follows. \[p_{2i}(r)=\frac{\left|E_{R}^{i}(r)-E_{R}^{min}(r)\right|}{\sum_{i=1}^{n}\left| E_{R}^{i}(r)-E_{R}^{min}(r)\right|} \tag{7}\]

where \(E_{R}^{i}(r)\) represents residual energy of the \(i\)-th node in the \(r\)-th round, \(E_{R}^{min}(r)\) represents minimum residual energy of intra-cluster nodes. The residual energy of the \(i\)-th node in the \(r\)-th round is calculated as follows. \[E_{R}^{i}(r)=E_{R}^{i}(r-1)-E_{C_{0}}^{i}(r-1) \tag{8}\]

where \(E_{C_{0}}^{i}(r-1)\) represents energy consumption of nodes in \((r-1)\)-th round. If the node acts as cluster head in the \((r-1)\)-th round, its energy consumption can be calculated by Equations (9)-(12). \[E_{Co-CH}(r-1)=E_{R}(r-1)+E_{D}(r-1)+E_{T}(r-1) \tag{9}\]

\[E_{R}(r-1)=(n_{k}-1)\times l\times E_{C} \tag{10}\]

\[E_{D}(r-1)=n_{k}\times l\times E_{A} \tag{11}\]

\[E_{T}(r-1)=l\times E_{C}+l\times\delta_{m}\times d_{t}^{A}(r-1) \tag{12}\]

where \(\delta_{m}\) represents energy consumption coefficient of power amplifier based on multipath attenuation model, \(d_{t}\) represents distance from cluster head node to sink node. If a node acts as a non-cluster head node in the \((r-1)\)-th round, its energy consumption can be calculated as follows. \[E_{Co-NCH}(r-1)=l\times E_{C}+l\times\vartheta_{f}\times d_{t}^{2}(r-1) \tag{13}\]

where \(\vartheta_{f}\) represents energy consumption coefficient of power amplifier based on free space model. If a node has a lot of residual energy, but it consumes a lot of energy when it is chosen as cluster head node, and even fails because of the exhaustion of energy after it is chosen as cluster head, such a node is not suitable for serving as cluster head. Therefore, in the process of cluster head selection and rotation, the energy consumption of nodes as cluster heads is predicted and compared, and higher priority probability is given to nodes with less energy consumption. The predicting energy consumption rate model of cluster head nodes in \((r+1)\)-th round is defined as follows:

\[p_{3i}(r)=\frac{\left|E_{Co}^{i}(r+1)-E_{Co}^{max}(r+1)\right|}{\sum_{i=1}^{n_ {k}}\left|E_{Co}^{i}(r+1)-E_{Co}^{max}(r+1)\right|} \tag{14}\]

where \(E_{Co}^{i}(r+1)\) represents the predicting energy consumption of node in \(r+1\) round after serving as cluster head, \(E_{Co}^{max}(r+1)\) represents the predicting maximum energy consumption of all nodes as cluster heads. Considering the above three factors, the comprehensive probability model is defined as:

\[p_{i}(r)=\mu_{1}\times p_{1i}(r)+\mu_{2}\times p_{2i}(r)+\mu_{3}\times p_{3i}(r) \tag{15}\]

where \(\mu_{1}\), \(\mu_{2}\) and \(\mu_{3}\) are weight coefficients, which are used to adjust the influence of various factors on the comprehensive model.