# A PSO-Based Uneven Dynamic Clustering Multi-Hop Routing Protocol for Wireless Sensor Networks
## 5 Proposed Algorithm
### Set-Up Phase  
After determining circular areas where the candidate CH nodes are located, CH nodes are selected by a multi-objective function. The CH nodes in each circular area are determined according to the residual energy of nodes, the distance from the nodes to the BS, and the number of neighbor nodes covered in the communication range. The multi-objective function is as follows.  
\[Weight_{ij}=\omega_{1}\times\frac{E_{ij}}{E_{0}}+\omega_{2}\times\frac{n_{nb_ {i}}}{n}+\omega_{3}\times\frac{d_{min_{j}}}{d_{s_{i}}},0\leq i\leq n,0\leq j\leq m \tag{19}\]  
where, we assign each factor the corresponding coefficient \(w_{1}\), \(w_{2}\) and \(w_{3}\), weighing the importance of each factor to CH election. \(w_{1}+w_{2}+w_{3}=1\), \(0\leq w_{1}\), \(w_{2}\), \(w_{3}\leq\)1, \(E_{ij}\) is the residual energy of a candidate CH node \(s_{i}\) in the \(j\)th circular area, \(E_{0}\) is the initial energy of nodes, \(n_{nbi}\) is the number of neighbor nodes in the communication range of the node \(s_{i}\), \(d_{minij}\) is the minimum distance between the BS and candidate CH nodes in the \(j\)th circular area, and \(d_{si}\) is the distance between the candidate CH node \(s_{i}\) and the BS. \(E_{ij}\) divided by \(E_{0}\), \(n_{nbi}\) divided by \(n\), and \(d_{minj}\) divided by \(d_{si}\) are normalized to adjust their values in the range [0,1]. The purpose of normalization is to adjust the values measured on different scales into a common scale so that there will be the same impact when multiple objectives are superposed. The node with the largest \(Weight_{ij}\) in the candidate circular area is selected as the CH node.  
The experimental results in a 200 m \(\times\) 200 m network with 100 nodes are shown in Figures 9-11. Where FND indicates the round in which the first dead node occurs. HND indicates the round in which half of nodes die. LND indicates the round in which 80% nodes die. According to above experimental results, \(w_{1}\), \(w_{2}\) and \(w_{3}\) are set to 0.8, 0.05 and 0.15. After CH nodes are determined, each sensor node determines which cluster it wants to join by choosing the CH that requires the minimum communication energy. Once all the nodes are organized into clusters, each CH creates a schedule for the nodes in its cluster. This allows the radio components of each non-cluster head node to be turned off at any time, except at its transmission time, thereby minimizing the energy consumed by a single sensor. Once the CH node has all the data from the nodes in its cluster, it aggregates the data and then transmits the compressed data to the BS. Because the distance between the CH nodes near the BS is smaller than the ones farther away from the BS, the area of clusters which near the BScan be smaller than the ones farther away from the BS, which can alleviate the hotspot problem due to forwarding data and balance the energy consumption of the network.  
The pseudocode of the PSO-based CH selection algorithm is given in Algorithm 2.  
Figure 11: Network lifetime schematic diagram of the trend of \(w_{3}\).  
Figure 9: Network lifetime schematic diagram of the trend of \(w_{1}\).  
```
Input: Set of sensor nodes: S = {\(s_{1}\), \(s_{2}\),..., \(s_{n}\)}.  Optimal number of circular areas: C.  Number of dimensions of a particle: \(D=2\). Output: Optimal positions of cluster heads: CH = {\(CH_{1}\), \(CH_{2}\),..., \(CH_{m}\)}.
```  
**Algorithm 2**Pseudocode of PSO-based CH selection