# Improving Monarch Butterfly Optimization Algorithm with Self-Adaptive Population
## 4 SPMBO Algorithm
### Greedy Strategy  
In this subsection, we will make a further in-depth study on the migration operator. In the basic MBO algorithm, all the newly-generated butterfly individuals are accepted as the new butterfly individuals for the next generation. If the newly-generated butterfly individual is worse than before, this updating will lead to population degradation, and slow the convergence speed. More seriously, if this happens at the later stages of the search, the population will oscillate.  
In this paper, a greedy strategy is introduced in the basic MBO algorithm. Only newly-generated butterfly individuals with better fitness will be accepted and passed to the next generation. This selection scheme guarantees the generated population is not worse than before, and the algorithm evolves in the proper way. After introducing the greedy strategy, for minimal problems, the new butterfly individual is given as:  
\[x_{i,new}^{t+1}=\left\{\begin{array}{ll}x_{i}^{t+1},&f(x_{i}^{t+1})<f(x_{i}^{t} )\\ x_{i}^{t},&else\end{array}\right., \tag{10}\]  
where \(x_{i,new}^{t+1}\) is a newly-generated butterfly that will be passed to the next generation, and \(f(x_{i}^{t+1})\) and \(f(x_{i}^{t})\) are the fitness of butterfly \(x_{i}^{t+1}\) and \(x_{i}^{t}\), respectively.  
After introducing this greedy strategy to the migration operator, the mainframe of the updated migration operator can be constructed, as shown in Algorithm 1.  
```
1:for\(i=1\) to \(NP_{1}\)do// butterflies in SP1
2:for\(k=1\) to \(D\)do//\(D\) is the length of a butterfly individual
3: Randomly generate a number \(rand\).
4:\(r=rand*peri\).
5:if\(r\leq p\)then
6: Randomly select a butterfly in subpopulation 1 (say \(r_{1}\));
7: Generate \(x_{i,k}^{t+1}\) by Equation (1);
8:else
9: Randomly select a butterfly in subpopulation 2 (say \(r_{2}\));
10: Generate \(x_{i,k}^{t+1}\) by Equation (3);
11:endif
12:endfor
13: Generate \(x_{i,new}^{t+1}\) according to greedy strategy as shown in Equation (10).
14:endfor
```  
**Algorithm 1** Updated Migration Operator.  
After incorporating the self-adaptive strategy and greedy strategy into the basic MBO algorithm, the SPMBO approach is complete; a description of the approach is given in Algorithm 2.  
```
1:Initialization. Set the generation counter \(t=1\), and set the maximum generation \(t_{m},NP_{1},NP_{2},BAR,peri\), and the lower (\(p_{\min}\)) and upper (\(p_{\max}\)) bounds of parameter \(p\).
2:Population evaluation. Calculate the fitness according to the objective function.
3:while\(t<t_{m}\)do
4: Sort the butterfly population.
5: Compute parameter \(p\) according to Equation (7).
6: Determine the number of butterflies in land 1 (\(NP_{1}\)) and land 2 (\(NP_{2}\)).
7: Divide butterfly individuals into two subpopulations.
8:for\(i=1\) to \(NP_{1}\)do// butterflies in SP1
9: Perform updated migration operator as Algorithm 1.
10:endfor
11:for\(j=1\) to \(NP_{2}\)do// butterflies in SP2
12: Perform butterfly adjusting operator as the basic MBO algorithm.
13:endfor
14: Calculate the fitness of newly-generated butterfly individuals.
15:\(t=t+1\).
16:endwhile
17: Print the final solution.
```  
**Algorithm 2** SPMBO Algorithm.  
In order to verify the performance of the prosed SPMBO algorithm, thirteen benchmark problems are solved by the proposed approach. The thirteen benchmark problems are minimal functions, so the MBO and SPMBO algorithms are striving to search for the smallest possible function values. A more detailed description of these experiments can be found in Section 5.