1. Overview

In this tutorial, we’ll go over what the Whale Optimization Algorithm (WOA) is and what it does. Furthermore, we’ll go over the algorithm and use an example to demonstrate how WOA would solve some simple optimization.

2. What Is the Whale Optimization Algorithm?

WOA is a meta-heuristics algorithm. As implied by the name, this algorithm was proposed for optimizing numerical problems by Mirjalili and Lewis, 2016. The inspiration for WOA comes, in particular, from the social behavior and the bubble-net hunting of humpback whales in oceans.

3. Who Are the Humpback Whales?

Humpback whales are among the largest mammals in the world. They are also one of seven different types of whales. It also has a one-of-a-kind hunting mechanism known as the bubble-net feeding method. They are unquestionably intelligent because their brains contain spindle cells. This foraging behavior is accomplished by the formation of special bubbles in the form of a spiral or path. As a result, let’s investigate the whale leadership hierarchy:

  • The leader whale finds the prey and dives down for about 12 meters approximately, creating a spiral-shaped bubble around the prey, and then swimming up to the surface while following the bubbles
  • An experienced whale who support the leader by making a call to synchronize
  • The others form a formation behind the leader and take the same position for each lunge

In short, the bubble-net hunting of humpback whales may resemble the image below:

Whales search randomly for a pry

4. Mathematical Model of the Whale Optimization Algorithm

The WOA algorithm imitates the social behavior and hunting method of humpback whales in oceans. So, let’s go over the fundamentals of whale hunting:

  1. Exploration phase: search for the prey
  2. Encircling the prey
  3. Exploitation phase: attacking the prey using a bubble-net method

Let’s take a look at the mathematical model behind each phase of the whale hunting process.

4.1. Exploration Phase: Searching Model

The search agent (humpback whale) looks for the best solution (the prey) randomly based on the position of each agent. We update the position of a search agent during this phase by using a randomly selected search agent rather than the best search agent. Following that, if {|A| > 1}, as defined in Equation 3, then force the search agent to move away from a reference whale. Here’s the mathematical model behind this phase:

(1)   \begin{equation*}  \vec{D} = | \vec{C} * {\vec{X _{rand}}} - \vec{X}| \end{equation*}

(2)   \begin{equation*}  \vec{X}(t+1) =  {\vec{X _{rand}}} - \vec{A} * \vec{D} \end{equation*}

Where \vec{X _{rand}} is a random position vector selected from the current population, and {\vec{A}, \vec{C}} are coefficient vectors. Besides, here are the equations of {\vec{A} and \vec{C}} that can be used to find the best search agents:

(3)   \begin{equation*} \vec{A} = 2 * \vec{a} * \vec{r} - \vec{a} \end{equation*}

(4)   \begin{equation*} \vec{C} = 2 * \vec{r} \end{equation*}

Where \vec{r} is a random vector in range [0, 1] and \vec{a} decreases linearly from 2 to 0 during the iterations.

4.2. Encircling Model

Humpback whales encircle the prey during hunting. Then, they consider the current best candidate solution as the best solution and near the optimal one. In short, here’s the model of encircling behavior that is used to update the position of the other whales towards the best search agent:

(5)   \begin{equation*}  D = | \vec{C} * {\vec{X^'}}(t) - \vec{X}(t)| \end{equation*}

(6)   \begin{equation*} \vec{X} (t+1) =  {\vec{X^'}}(t) - \vec{A} *  \vec{D} \end{equation*}

Where t is the current iteration, \vec{X^ '} is the position of the best solution, \vec{X} refers to the position vector of a solution, and {\vec{A}, \vec{C}} are coefficient vectors as shown in Equations 3 and 4.

4.3. Exploitation Phase: Bubble-Net Attacking Model

This phase focuses on using a bubble-net to attack the prey. This bubble-net strategy combines two approaches. Let’s look at the mathematical model of each approach in order to better understand this step:

  • Shrinking encircling mechanism: The value of \vec{A} in this mechanism is a random value within the [-a, a] interval, and the value of \vec{a} decreases from 2 to 0 over the course of iterations, as shown in Equation 3. Let’s now define random values for \vec{A} in [-1, 1]. We can also define the new position of a search agent anywhere between the current best agent’s position and the agent’s original position. So, let’s look at the graph that displays the possible positions from {(X, Y)} to {({X^'}, {Y^'})}:
Picture2222221
  • Spiral updating position mechanism: This method starts with the calculation of the distance between the whale {(X, Y)} and the prey {({X^'}, {Y^'})}. Here’s the spiral equation behind the helix-shaped movement of humpback whales to define the position between whale and prey:

(7)   \begin{equation*} \vec{X} (t+1) =  {\vec{D^ ''}} * e^\text{bl} * \cos(2 \pi \text{l}) + {\vec{X^ '}} \end{equation*}

Where {\vec{D^ ''}} = | {\vec{X^ '}}(t) - \vec{X}(t)| represents the distance between the whale and the prey (best solution obtained so far), \textbf{l} is a random number between [-1, 1], and \textbf{b} is a constant defining the shape of the logarithmic spiral. Let’s now define the mathematical model behind the humpback whale’s swimming style around the prey using a shrinking circle and also following a spiral-shaped path at the same time:

(8)   \begin{equation*} \vec{X} (t+1) = \left\{ \begin {array} {ll} { {\vec{X^ '}}(t) - \vec{A} *  \vec{D}  \text{    if }  p < 0.5}  \\ {{\vec{D^ ''}} * e^\text{bl} * \cos(2 \pi \text{l}) + {\vec{X^ '}}  \text{    if } p \ge 0.5}   \end{array} \end{equation*}

Where \textbf{p} represents the probability of selecting one of these two methods to update the position of whales. Next, let’s say that the probability of choosing between the two approaches is 50%. Then, \textbf{p} is a random number in [0, 1]. Here’s the graph that explains the spiral updating position in more detail:

Picture11111

5. Flowchart of a Whale Optimization Algorithm

Let’s take a look at the flowchart:

Copy of Flowchart of whale Optimization algorithm

First, we must initialize the whale population {n} as well as the values. Then, we evaluate the fitness solution value of the search agent. Next, we set the number of iterations to 1. Afterward, we use Equation 1 to search for prey. Then, we encircle it using Equation 5, after finding the prey. Following that, we update the position of search agents to attack the prey using the bubble-net strategy in Equation 8. Then, we update the values of {{a}, {A}, {C}} with the new position of the search agent. Afterward, we check the constraints of equality and inequality of {A} and {p} for the new position of each search agent and then increase the iteration number.

Finally, if we reach the maximum number of iterations \text{max\_iter}, we’ll stop and save the fitness value as the best solution; otherwise, we’ll repeat the process until we find a solution.

6. Explanation of Whale Optimization Algorithm With Example

Let’s discover a simple example to understand the whale optimization algorithm:

  • Step 1: First, let’s randomly initialize the population of whales {X_i} \text{(i=1, 2,..., n), where n = 5}
  • Step 2: Then, we initialize the iteration counter t = 0
  • Step 3: Next, let’s initialize the value of a=2 (because it decreases from 2 to 0) and {{A}, {C}} using a random values (based on the equations 3 and 4), and let’s define \text{max_iter = 100}:

    \[{a} = 2 - t * \frac{2}{max\_iter}\]

  • Step 4: Afterward, we need to evaluate each search agent \vec{X_i} by calculating its fitness function {f({X_i})}. Here’s the fitness function example:

    \[Fitness = 4 {X(1)^2}  - 2.1 {X(1)^4} + \frac{1}{3} {X(1)^6} + {X(1)}{X(2)} - 4 {X(2)^2} + 4 {X(2)^4}\]

Here’s the result of the fitness function after setting a random initialization of the population for five search agents:

    \[\begin{tabular}{ | l | l | l | l|} \hline \textbf{Sr. No} & \textbf{X(1)} & \textbf{X(2)} & \textbf{Fitness} \\ \hline \textbf{1.} & -1.5002 & -1.4834 & 16.0964\\ \hline \textbf{2.} & -3.0340 & 3.3083 & 1.4945 \\ \hline \textbf{3.} & -2.4892 & 0.8526 & 2.1752 \\ \hline \textbf{4.} & 1.1604 & 0.4972 & \textbf{1.4192} \\ \hline \textbf{5.} & -0.2671 & 4.1719 & 2.4043 \\ \hline \end{tabular}\]

As a result, the optimal solution is the one with the lowest fitness value of all search agents. Thus, {X^'}=1.4192 is the optimal solution for the first iteration.

  • Step 5: Let’s now update the position vector according to {A} and {P}:

    \[\left\{ \begin {array} {ll} \text{if } {p \ge 0.5} \text{, update by Equations 7 and 8 }\\  \text{if } {p<0.5} \left\{ \begin {array} {ll} \text{if } {A \ge 1 } \text{, update by Equations 5 and 6 } \\ \text{if } {A < 1 } \text{, update by Equations 1 and 2 } \end{array} }\]

  • Step 6: If {t < max\_iter} then update values {\text{a, A, C, l, p}} && repeat steps 4 and 5
  • Step 7: If {t \ge max\_iter} then return the best solution {X^'}

7. Conclusion

In this article, we discussed the whale optimization algorithm, and how understanding this algorithm can facilitate the search for an optimal solution to a problem using the way of whales. We introduced this algorithm because it is highly effective while remaining simple enough to be easily understood.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.