## 4 Proposed Algorithm
### PSO for Clustering  
First we use PSO to find appropriate nodes to be CHs. Because we divided the network into different segments, the percentage of CHs within each segment is highly related to the sparsity of the segment. In general, we set the CH ratio \(q\) to be 0.4, only in some segments which have relative low sparsity, the value of \(q_{i}\) increases slightly in a trend like \(q_{i}=0.4+0.05\times\lceil s_{i}-0.08\rceil\) where \(s_{i}\) is the sparsity of the \(i\)th segment. The particle's dimension is the same as the number of CHs. To initialize the particle, we generate \(M\) random integer numbers within \([1,N]\). For example, the \(i\)-th particle \(\mathbf{P}_{i}\) is \(M\) dimensional and \(P_{i,m}\) represents the \(m\)-th value of it. If \(P_{i,m}=25\), it means that in this particle, we choose node 25 to be the \(m\)-th CH. As a node cannot be chosen repeatedly in one particle, if a particle has duplicated numbers, it will be assigned a penalty fitness value \(-1\) to be excluded during later progress. After initializing all the particles, we calculate the fitness value for each particle. According to their fitness value, we choose the local best and the global best particles, update the particle position which corresponds to the coordinates of the nodes in this particle and velocity to get new fitness values. In this part, we mainly focus on energy consumption and uniformity of cluster head distribution, hence the fitness function \(f\) does not include the measurements for signal recovery qualities in current stage. The fitness function \(f_{1}\) comprises of three parts as below:  
* \(E_{p}\), represents the energy evaluation factor and \(E_{p}\) is given by \[E_{p}=\frac{\sum_{m=1}^{M}E_{res_{m}}}{\sum_{i=1}^{N}E_{init_{i}}},\] (22) which measures the remaining energy of the chosen CHs. Note that \(E_{init_{i}}\) is the initial energy of the \(i\)-th node while \(E_{res_{m}}\) is the residual energy of the \(m\)-th node and equals to \(E_{inin_{m}}-E_{res_{m}}\), and \[E_{res_{m}}=\left\{ \begin{array}{ll}0&\quad\text{if node $m$ was not involved in the routing}\\ t_{hop}(L,l_{m,r})\times P_{r}+t_{hop}(L,l_{m,t})\times P_{t}^{el}&\quad\text{if node $m$ was involved in the routing},\end{array} \right.\] where \(l_{m,r}\) measures the hop length when node \(m\) is the receiver and \(l_{m,t}\) measures the hop length when node \(m\) is the transceiver. We tend to choose nodes with higher residual energy to be CHs due to the fact that cluster heads consume more energy than normal nodes. * \(E_{c}\) indicates the evaluation factor for the intra-cluster compactness and measures the average distance between nodes and their cluster heads. We calculate \[f=\max_{m=1,2,\ldots,M}\sum_{\exists i_{l}\in C_{m}}d_{i,CH_{m}}/|C_{m}|,\]which measures the maximum average Euclidean distance between nodes and their CHs. \(d_{i,CH_{m}}\) measures the distance between node \(i\) and \(CH_{m}\). \(|C_{m}|\) is the number of nodes that belong to cluster \(C_{m}\). Our aim is to minimize \(f\) because the nodes are closer to its cluster heads with smaller \(f\). Therefore, \(E_{c}=1/f\). * \(E_{e}\) is the evaluation factor of the uniformity of CH distribution. It measures the uniformity of CH distribution. Firstly we calculate all nodes' distances to each other. \(\mathbf{D}=\mathbf{d_{1}},...,\mathbf{d_{N}}\) where \(\mathbf{d_{j}}=d_{j,1},...d_{j,i},...,d_{j,N},i\
eq j\) and \(d_{j,i}\) measures the distance between node \(j\) and node \(i\). In an unevenly distributed network, the sum of \(\mathbf{D}\) must be higher than relatively evenly distributed network. As a consequence, we add this value \(E_{e}=\sum_{j=1}^{M}d_{j}/|C_{m}|\) on our fitness function. To sum up, the final form of fitness function \(f_{1}\) of our cluster choosing algorithm is given by: \[f_{1}=w_{1}E_{p}+w_{2}E_{c}+w_{3}E_{e},\] where \[\left\{ \begin{aligned} & w_{1}+w_{2}+w_{3}=1\\ & w_{i}\geq 0,i\in\{1,2,3\}\end{aligned} \right.\] and \(w_{i}\) is the weighting factor for the \(i\)-th item.