Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: April 30, 2023
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.
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.
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:
In short, the bubble-net hunting of humpback whales may resemble the image below:
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:
Let’s take a look at the mathematical model behind each phase of the whale hunting process.
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 , 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)
(2)
Where is a random position vector selected from the current population, and {
,
} are coefficient vectors. Besides, here are the equations of {
and
} that can be used to find the best search agents:
(3)
(4)
Where is a random vector in range [0, 1] and
decreases linearly from 2 to 0 during the iterations.
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)
(6)
Where t is the current iteration, is the position of the best solution,
refers to the position vector of a solution, and {
,
} are coefficient vectors as shown in Equations 3 and 4.
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:
(7)
Where represents the distance between the whale and the prey (best solution obtained so far),
is a random number between [-1, 1], and
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)
Where 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,
is a random number in [0, 1]. Here’s the graph that explains the spiral updating position in more detail:
Let’s take a look at the flowchart:
First, we must initialize the whale population 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 {
,
,
} with the new position of the search agent. Afterward, we check the constraints of equality and inequality of
and
for the new position of each search agent and then increase the iteration number.
Finally, if we reach the maximum number of iterations , we’ll stop and save the fitness value as the best solution; otherwise, we’ll repeat the process until we find a solution.
Let’s discover a simple example to understand the whale optimization algorithm:
Here’s the result of the fitness function after setting a random initialization of the population for five search agents:
| Sr. No | X(1) | X(2) | Fitness |
|---|---|---|---|
| 1. | -1.5002 | -1.4834 | 16.0964 |
| 2. | -3.0340 | 3.3083 | 1.4945 |
| 3. | -2.4892 | 0.8526 | 2.1752 |
| 4. | 1.1604 | 0.4972 | 1.4192 |
| 5. | -0.2671 | 4.1719 | 2.4043 |
As a result, the optimal solution is the one with the lowest fitness value of all search agents. Thus, is the optimal solution for the first iteration.
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.