## 4 Proposed Method
### The Pseudo-Code of the Proposed Algorithm  
Algorithm 1 is a pseudo-code that uses the SO algorithm to select the best set of CHs and Algorithm 2 is a pseudo-code that uses the GJO method to find the best route between CH and BS. ```
0: Set of sensor nodes: \(S=\{s_{1},s_{2},s_{3},\cdots,s_{n}\}\)
0: Optimal positions of cluster heads \(CH=\{CH_{1},CH_{2},CH_{3},\cdots,CH_{m}\}\)  Step1: Initialize population \(X\);  Step2: for i = 1:N do  Calculate \(Fitness(X_{i})\) using Equations (24)-(27); endfor  Take the minimum value of Fitness as \(Gbest\);  Take the individual whose Fitness value is \(Gbest\) as \(X_{food}\); /*Diving the swarm into two equal groups males and females*/  Define \(N_{m}=\frac{N}{2}\) as the male individual numbers;  Define \(N_{f}=N-N_{m}\) as the female individual numbers; for i = 1:N do  Calculate \(Fitness_{m}(X_{i,m})\); endfor \(i=1:N\)do  Calculate \(Fitness_{f}\Big{(}X_{i,f}\Big{)}\); endfor  Take the minimum value of \(Fitness_{m}\) as \(f_{best,m}\);  Take the minimum value of \(Fitness_{f}\) as \(f_{best,f}\);  Take the male individual whose \(Fitness_{m}\) value is \(f_{best,m}\) as\(X_{best\_m}\);  Take the female individual whose \(Fitness_{f}\) value is \(f_{best,f}\) as\(X_{best\_f}\);  Step3:
```  
**Algorithm 1** SO-Clustering  
### The Pseudo-Code of the Proposed Algorithm  
Algorithm 1 is a pseudo-code that uses the SO algorithm to select the best set of CHs and Algorithm 2 is a pseudo-code that uses the GJO method to find the best route between CH and BS. ```
while\(t<t_{max}\)do  Define Temp using Equation (11);  Define food Quantity \(Q\) using Equation (12); if\(Q<0.25\)then /*Exploration phase (no food)*/ for i = 1:\(N_{m}\)do  Define \(A_{m}\) using Equation (7);  Update position of \(X_{new\_m}\) using Equation (6); endfor for i = \(N_{f}\):\(N\)do  Define \(A_{f}\) using Equation (9);  Update position of \(X_{new\_f}\) using Equation (8); endfor else /*Exploitation phase (food exists) */ ifTemp > 0.6 then for i = 1:\(N_{m}\)do  Using the Brownian motion function to replace the constant coefficients \(C_{3}\), Update position of \(X_{i,new\_m}\) using Equation (13); endfor for i = \(N_{f}\):\(N\)do  Using the Brownian motion function to replace the constant coefficients \(C_{3}\), Update position of \(X_{i,new\_f}\) using Equation (13); endfor else if\(rand>0.6\)then /*Fight Mode*/ for i = 1:\(N_{m}\)do  Define \(FM\) using Equation (16);  Using the Brownian motion function to replace the constant coefficients \(C_{3}\), Update position of \(X_{new\_m}\) using Equation (14); endfor for i = \(N_{f}\):\(N\)do  Define \(FM\) using Equation (17);  Using the Brownian motion function to replace the constant coefficients \(C_{3}\), Update position of \(X_{new\_f}\) using Equation (15); endfor else /*Mating Mode*/ for i = 1:\(N_{m}\)do  Define \(M_{m}\) using Equation (20);  Using the Brownian motion function to replace the constant coefficients \(C_{3}\), Update position of \(X_{new\_m}\) using Equation (18); endfor for i = \(N_{f}\):\(N\)do  Define \(M_{f}\) using Equation (21);  Using the Brownian motion function to replace the constant coefficients \(C_{3}\), Update position of \(X_{new\_f}\) using Equation (19); endfor endif  Change the worst male and female Equations (22) and (23); endif endif if\(f_{best\_m}<f_{best\_f}\)then \(Gbest=f_{(best\_m)}\); \(X_{food}=X_{best\_m}\); else \(Gbest=f_{(best\_f)}\); \(X_{food}=X_{best\_f}\); endif \(t=t+1\); endwhile  Step4: Repeat Step3 until it reaches the maximum number of iterations;  Step5: Return best solution \(X_{food}\) /*Optimal cluster head*/
```  
**Algorithm 1**_Cont_.