## 1. Overview

In this tutorial, we’ll learn about metaheuristics and the firefly algorithm. However, before doing this, let’s take a quick look at some metaheuristics concepts.

## 2. Metaheuristics

Metaheuristics are similar to heuristics, and they seek promising solutions to problems. However, metaheuristics are generic, and they can deal with a variety of problems.

In the context of metaheuristics, the characteristics of “non-measurable success” and “reasonable execution” remain the same as discussed for heuristics. But metaheuristics replace the problem-based design principle with the problem-independent design principle. Generally, metaheuristic algorithms are designed for global optimization.

## 3. The Firefly Algorithm

This section is divided into three sub-sections. First, general information regarding the firefly algorithm is given. Then, we present implementation steps and code examples for the firefly algorithm.

### 3.1. General Information

The social interactions of fireflies or lightning bugs in the tropical summer sky serve as the basis for this metaheuristic optimization technique. It was created in 2007 at Cambridge University by Dr Xin-She Yang.

It’s based on swarm behaviour seen in nature for the creatures like fish, insects, and birds. The swarm intelligence algorithms like PSO, artificial bee colony optimization, and bacterial foraging algorithms share many similarities with the firefly algorithm.

Real random numbers are used in the firefly method. It is based on the swarming particles’ ability to communicate globally (i.e., the fireflies). It seems more effective in terms of multi-objective optimization.

### 3.2. Steps of the Firefly Algorithm

The firefly algorithm is composed of three rules based on the flashing characteristics of real fireflies. These are explained and shown below:

All fireflies are unisex. They will move toward more attractive and brighter ones regardless of their sex.

The degree of attraction of a firefly is proportional to its brightness. This cuts as the distance from the other fireflies increases because the air absorbs light. If there isn’t a brighter or more attractive firefly than a particular one, it’ll then move randomly.

The brightness or light intensity of a firefly is determined by the value of the objective function of a given problem.

### 3.3. Coding for Firefly Algorithm

After understanding the concept and steps of the firefly algorithm, let’s look at the pseudocode of the firefly algorithm.

The general pseudocode for the firefly algorithm is given:

``````algorithm FireflyAlgorithm:
// INPUT
//    f = the objective function
// OUTPUT
//    The best found solution that optimizes f

Randomly generate an initial population of n fireflies

Calculate the fitness of each firefly

while termination condition are not met:
for i <- 1 to N:
for j <- 1 to N:
if fitness(y_i) > fitness(y_j):
// y_i is brighter than y_j
Move the y_i firefly towards the y_j firefly

Vary attractiveness with distance r between the fireflies

Sort the fireflies and find the global best
``````

We have multiple implementations of the firefly algorithm in different programming languages, such as Matlab and Python.

## 4. Use Cases of the Firefly Algorithm

The firefly algorithm has several applications. These are listed:

• Digital image compression and image processing: Digital image compression and image processing requires solution of optimization problems. In this context, trapped local optima is optimized by using firefly algorithm.
• Feature selection and fault detection: Firefly algorithm has been used for discriminative feature selection in classification and regression models to support decision making process using data-based learning methods.
• Antenna design: Firefly algorithm has been used in optimization of antenna arrays.
• Structural design: Firefly algorithm has been used in optimum design of the structures in the construction sector.
• Scheduling: Firefly algorithm has been used in scheduling problems to determine optimal scheduling.
• Semantic web composition: Firefly algorithm has been used to determine optimal solution in semantic web services.
• Chemical phase equilibrium: Firefly algorithm has been used to model activity coefficients in chemical reaction.
• Biomedical and healthcare: Firefly algorithm has been utilized in important medical fields such as breast cancer classification, human retinal images, breast tumor classification, detection of brain tumor, health monitoring, etc.
• Clustering: Firefly algorithm has been used to determine optimum number of clusters and to improve the performance of clustering.
• Rigid image registration problems: Image registration is an important field of image processing and automatic target recognition. It can be simplified as an optimization problem. It has three input variables (two translational parameters and one rotational parameter) and one output variable as the normalized cross correlation. In this regard, firefly algorithm has proposed in some studies.

## 5. Conclusion

In this tutorial, we learned about a metaheuristic algorithm called the firefly algorithm. First and foremost, we refreshed our knowledge about metaheuristics. Then, we looked into the implementation steps of the firefly algorithm.

Finally, we discussed the applications and use cases of the firefly algorithm.

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