# Cluster Head Selection Method for Edge Computing WSN Based on Improved Sparrow Search Algorithm
## 4 Improved SSA Algorithm
### The Sparrow Search Algorithm
#### 4.2.3 Adaptive Population Adjustment Strategy  
In the sparrow search algorithm, the number of producers is usually fixed. However, in the process of cluster head selection, if there are fewer producers in the early stage of the iteration, the search cannot be entirely performed; similarly, in the later stage of the iteration, there should be more followers to perform a local search to prevent falling into the local optimum untie. Therefore, we introduce adaptive parameters to adjust the number of producers and followers dynamically. The specific formula is as follows:  
\[\begin{split} a&=0.15\cdot\left(2\mathrm{e}^{-(2t/T_{ \mathrm{max}})}-0.1k\right)+0.1\\ P&=a\cdot N\\ S&=(1-a)\cdot N\end{split} \tag{19}\]  
where \(N\) is the total population, \(k\) is a random number in the [0, 1) interval, \(P\) is the number of producers, and \(S\) is the number of followers.  
The specific steps of the flow chart of optimizing the clustering scheme of WSN based on ICSSA-CHS are as follows Figure 2, and in Algorithm 1 the pseudocode is provided.  
Figure 2: The flow chart of optimizing the clustering scheme of WSN based on ICSSA-CHS.  
Step 1: Initialize the number of sensor nodes, the initial energy, the size of the node distribution area, and use Formula (17) to initialize the sparrow population.  
Step 2: Each node in the network sends its own position and energy information to the edge nodes. At this time, update the position and energy information of each node in the WSN at the edge node.  
Step 3: If the maximum number of iterations is reached, go to step 6; otherwise go to step 4.  
Step 4: Use Formula (10) to calculate the objective function value, and obtain the current optimal and worst clustering scheme, the cluster head node set, and the global optimal clustering scheme.  
Step 5: Adaptively adjust the population according to Formula (19), select the currently optimal \(P\) sparrow individuals as discoverers and S sparrow individuals as followers, and update the discoverers and followers through Formulas (14) and (15).  
Step 6: Randomly select 20% of individuals in the population as vigilantes, and update the position of the vigilantes through Formula (18), and execute step 3.  
Step 7: Edge nodes broadcast cluster head information. After the cluster head node receives the information that it is selected as the cluster head node, it broadcasts to other nearby nodes, and other nodes join the cluster.  
Step 8: The cluster head node collects the data collected by other nodes, and sends them to the edge nodes after fusion.  
Step 9: Repeat until the lifetime of the WSN network ends Algorithm 1.  
```
Input: population number \(N\), the maximum number of iterations \(T_{max}\), number of vigilantes \(R\) Output: cluster head election result
1 initialize the population according to Equation (17);
2 while\(t<T_{\max}\)do
3 obtain \(P\), \(S\), and \(a\) according to Equation (19);
4 for\(i\gets 0\)to\(N\)do
5 Calculate the Fitness function \(F_{i}\) value according to Equation (10);
6 end for
7\(BF\leftarrow\)BestFitness(\(F\));
8 for\(i\gets 0\)to\(P\)do
9 obtain the position of the producer according to Equation (14);
10 end for
11 for\(i\gets 0\)to\(S\)do
12 obtain the position of the follower according to Equation (15);
13 end for
14 for\(i\gets 0\)to\(S\)do
15 obtain the position of the vigilante according to Equation (18);
16 end for
17 record the optimal cluster head scheme;
18
19 end for
```  
**Algorithm 1**ICSA-CHS