Skip to main content
. 2024 Dec 16;9(12):765. doi: 10.3390/biomimetics9120765
Algorithm 2 The Improved Spider Wasp Optimization Algorithm
Input: N, Nmin, CR, TR, tmax,lb,ub,dim,
Output: SW*
1. Initialize parameters
2.  Set boundary conditions lb,ub
3.  Initialize SW* as a zero vector
4.  Set optimal fitness to infinity
5. Initialize positions of search agents
6. Use initialization function to generate initial positions xi
7. Generate an opposite population using opposition learning xi
8.  Combining the original and inverse populations
9. Evaluate each SWi and finding the one with the best fitness in SW*
10. Main loop (t=0 to tmax)
11.  To calculate the values of TR, Cr, and k using Equations (26), (41) and (42),
12.  Randomly shuffle the index
13.  Judgement of hunting and nesting behavior based on TR
14.   rand between 0 and 1
15.   If rand<TR, perform hunting and nesting behavior
16.   The optimal solution SW* can be calculated using Formulas (4)–(8) from the exploration phase and Formulas (10), (12), (16) and (17) from the follow-escape phase.
17.   Perform boundary check
18.   Else, perform mating behavior (DE + COA hybrid strategy)
19.   Differential Evolution (DE) operates using Equations (38) and (39)
20.   Perform crossover operations
21.   Apply boundary check
22.   The optimal SW* solution can be obtained by combining COA using Formulas (29)–(37), and then fusing the results of DE and COA, applying Formula (40).
23. Apply opposition-based learning (OBL) every 10 iterations
24. Generate an opposite population using opposition learning xi
25.  Combining the original and inverse populations
26.  if fU<f(X)
27.   X=SW*
28.  Else, U =SW*
29. Reduce population size
30.  Compute the new population size ensuring it is not less than the minimum size
31.  Update the population accordingly