*2.5. The Sperm-Whale Algorithm*

The search used by the SWA mimics the hunting behavior of sperm whales, which live alone or in small groups at the bottom of the sea and must come to the surface to hunt and breathe [43]. In each iteration, the population of the SWA is split into smaller search groups consisting in uniformly distributed better and worse adapted members ('sperm whales'). Consequently, the search for the optimal solution occurs independently in each group. First, the sperm whales change their position from the bottom of the sea to the surface. This step is simulated only for the worst adapted member of the group, for which the opposite position is computed. The positions of the leader and of the worst individual in a group *g*, *leader(g,it)* and *worst(g,it)*, are used to compute an in-between distance *dist(g,it)*:

$$\text{dist}^{(\text{g,it})} = \text{worst}^{(\text{g,it})} + w \cdot \text{lender}^{(\text{g,it})} \tag{16}$$

The reflex position of *worst(g,it)* is then computed with Equation (17).

$$reflex^{(g,it)} = worst^{(g,it)} + 2 \cdot (dist^{(g,it)} - worst^{(g,it)}) = 2 \cdot dist^{(g,it)} - worst^{(g,it)} \tag{17}$$

The newly computed individual *reflex(g,it)* will replace *worst(g,it)* only if its fitness function is better. At the beginning of the iterative process, when the inertia *w* from Equation (16) is large, the individual will search beyond *leader(g,it)* (exploration phase, Figure 7a). As *w* decreases, the search will focus between *worst(g,it)* and *leader(g,it)*, exploiting the search space around the known optimal solution (Figure 7b).

**Figure 7.** Reflex search in the SWA algorithm: (**a**) exploration, (**b**) exploitation.

In the second stage, a Good Gang is formed within the group, gathering the best *gg* individuals ranked according to their fitness function. Every Good Gang member performs several local searches in which its elements *k* are displaced randomly, within a small radius *r*:

$$\mathbf{x}\_{j,k} = \pm r \cdot \mathbf{x}\_{j,k} \qquad j = 1 \ldots \mathbf{g} \,\mathbf{g} \tag{18}$$

The original Good Gang members are replaced only if better sperm-whale positions are found during the local search.

Finally, the best Good Gang member from the group (the dominant sperm-whale) performs genetic crossover with all other group individuals. One of the two resulting children is chosen randomly to replace the worst of the two parents.

At the end of the iteration, the groups are reunited in the final population, which will repeat the search process until the stopping criterion of the algorithm is met. The basic flowchart of a SWA iteration is presented in Figure 8.

**Figure 8.** The flowchart of a SWA iteration.

The SWA offers several tuning options for the user. The population size, number of search groups within the population, the inertia *w* and its decrement, the Good Gang size and number of local searches for its members, the local search radius *r*, and the crossover method can be adjusted for better performance.
