## 1. Introduction

**The Dragonfly Algorithm is one of the most recently developed heuristic optimization techniques**. Moreover, it has shown its ability to optimize different real-world problems. In this tutorial, we’ll talk about the Dragonfly Algorithm and present the different steps of the algorithm.

## 2. What Is the Dragonfly Algorithm?

Mirjalili created the Dragonfly Algorithm at Griffith University in 2016.** The Dragonfly Algorithm was inspired by the static and dynamic swarming behavior of dragonflies in the wild**. In fact, the two required phases of optimization, exploration and exploitation, are represented by the static and dynamic swarming behaviors.

Also, dragonflies form sub-swarms and fly over different areas in a static swarm. This is similar to exploration, and it aids the algorithm in locating appropriate search space locations. On the other hand, dragonflies in a dynamic swarm fly in a larger swarm and in the same direction. In addition, this type of swarming is the same as using an algorithm to assist it converges to the global best solution.

## 3. Dragonfly Algorithm Steps

**Generally, the behavior of swarms of the Dragonfly Algorithm follows three primitive principles:**

- Separation: which indicates the avoidance of neighboring static collisions
- Alignment: which returns the speed of individuals paired with neighboring individuals
- Cohesion: which indicates the individual tendency toward the center of the herd

Since the ultimate purpose of any swarm is to survive, all of the members should be drawn to food sources and away from potential attackers. **So, there are five primary aspects in position updating of individuals in swarms when considering these two behaviors: Separation, Alignment, Cohesion, Attraction, and Distraction as shown in the figure below:**

## 4. Dragonfly Algorithm Mathematical Model

As we mentioned in the previous section, the positioning movement of dragonflies consists of the following five behaviors. So, let’s define the operations:

### 4.1. Separation

**We can calculate the Separation between two adjacent dragonflies as follows:**

(1)

where presents the position of the current individual, indicates the neighboring individual and is the number of neighboring individuals.

### 4.2. Alignment

**The equation is used to determine the alignment of dragonflies:**

(2)

where describes the velocity of * *neighboring individual.

### 4.3. Cohesion

**We can derive the Cohesion as follows:**

(3)

where shows the position of the current individual, indicates the neighboring individual, and is the number of neighboring individuals.

### 4.4. Attraction

**We compute the Attraction operation toward the source of food using this equation:**

(4)

Where presents the position of the current individual, and describes the position of the food source.

### 4.5. Distraction

**We can determine the Distraction from the enemy as shown here :**

(5)

Where *, *shows the position of the current individual and denotes the natural enemy.

To update the position of artificial dragonflies in a search space and replicate their motions, two vectors are considered: step vector () and position vector ().

**So, the step vector presents the direction of the movement of the dragonflies. We can define this vector by the equation :**

(6)

where , , , and are weights for the phases: separation, alignment, cohesion, attraction, and distraction. Also, presents the inertia weight, and is the iteration counter.

Exploration and exploitation stages can be achieved by changing the values of these weights.

The position vector is easily determined with the help of the step vector, as shown in the equation :

(7)

In fact, low cohesion weight () and high alignment weight () are allocated to the exploration phase. Similarly, low alignment weight () and high cohesion weight () are assigned to the exploitation phase.

**The position vector indicates the dragonfly’s location; however, if no surrounding solutions exist, the dragonflies must fly in a random search space, and their position must be updated using the adjusted equation :**

(8)

where is:

(9)

where we range , in [0,1], is constant,

is defined as follows:

(10)

## 5. Pseudocode of the Dragonfly Algorithm

Let’s now take a look at the different steps of the algorithm:

The Algorithm begins the optimization process by randomly producing a set of solutions to given optimization problems. To initialize the position and step vectors of dragonflies, random values defined within the lower and higher ranges of the variables are employed.

Each dragonfly’s position and step were updated in each cycle. In addition, the neighborhood of each dragonfly is picked for updating and vectors by computing the Euclidean distance between all dragonflies and picking N of them. Then, we continued the position updating process iteratively until the end criterion was satisfied.

## 6. Example

We show here one specific example of a dragonfly’s behavior to better understand this method. This figure shows an example of dragonfly swarming behavior with increasing neighborhood radius using the previous mathematical model:

Indeed, different explorative and exploitative behaviors may be created during optimization using separation, alignment, cohesion, food, and enemy factors (s, a, c, f, r and w). Because the neighbors of dragonflies are so crucial, each dragonfly is supposed to have a neighborhood with a specific radius.

We utilize s=, a=, c=, f=, r=, and w is linearly decreased from to and with the parameters, we were able to stimulate different swarming behavior. Also, the green circle is a food source, black circles are individuals, the red circle indicates the enemy, and purple lines are the step vector of the dragonflies.

In fact, this image demonstrates how the suggested model moves individuals throughout the search area in relation to each other as well, food source, and enemy.

## 7. Conclusion

**Generally, the Dragonfly Algorithm in applied science is offered in the following area: networking, machine learning, image processing, and wireless**. Indeed, in this tutorial, we presented the Dragonfly Algorithm by describing its different steps and the mathematical model.