Introduction
Firefly Optimization Algorithm
B.Tech (AI & ML) VI SEM
Lecture by:
Ranjeet Kumar
Department of Artificial Intelligence & Machine Learning
Mohan Babu University
Tirupati, India
March 28, 2025
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Contents
1 Introduction
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Introduction
Firefly Algorithm (FA):
The Firefly Algorithm (FA) is a metaheuristic optimization
algorithm inspired by the flashing behavior of fireflies.
It was developed by Xin-She Yang in 2008.
Used to solve optimization problems in various fields, including
engineering, machine learning, and operations research.
Used for solving continuous and discrete optimization
problems.
Algorithm mimics the way fireflies use bioluminescent signals
to attract mates or potential partners.
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Characteristics
Attractiveness and Distance Dependence:
The attractiveness of a firefly is inversely proportional to the
square of the distance from another firefly.
A firefly moves toward another firefly with a higher brightness
(better fitness value).
If no brighter firefly is found, it moves randomly.
Light Intensity and Objective Function:
The brightness of each firefly is associated with the objective
function value.
Fireflies move toward the best solutions in the population,
improving their position iteratively.
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Exploration and Exploitation:
Exploration: Random movement ensures that the algorithm
does not get trapped in local optima.
Exploitation: The attractiveness mechanism ensures
convergence towards better solutions.
Adaptability and Flexibility:
The algorithm can handle both continuous and discrete
optimization problems.
It is simple to implement and has fewer parameters compared
to other metaheuristic algorithms.
Global and Local Search Balance:
Maintains a balance between global and local search through
the parameters γ (light absorption coefficient) and α
(randomization factor).
A higher α increases randomness, promoting exploration.
A higher value of γ reduces the search space exploration,
focusing on local solutions.
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Movement of Fireflies:
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
Step 1: Initialization of Parameters
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
Step 2: Initialize Population (Fireflies)
Generate an initial population of n fireflies with random
positions in the search space.
Each firefly i is represented by a position xi in the solution
space.
Compute the objective function (brightness) for each firefly.
Step 3: Evaluate Brightness of Fireflies
The brightness of a firefly i is determined by the value of the
objective function f (xi ).
In maximization problems, brightness is directly proportional
to the objective function value.
In minimization problems, brightness is inversely
proportional to the objective function value.
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
Step 4: Compute Distance Between Fireflies
The Euclidean distance rij between two fireflies i and j is
given by :
rij = ∥xi − xj ∥.
This distance is used to determine attractiveness.
Step 5: Compute Attractiveness of Fireflies
The attractiveness β between two fireflies i and j is given by:
2
β = β0 e −γr
where:
β0 is the base attractiveness.
γ is the light absorption coefficient.
r is the Euclidean distance.
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
Step 6: Move Fireflies Towards Brighter Fireflies
Fireflies move toward brighter fireflies using the formula:
2
xi = xi + βe −γr (xj − xi ) + αϵ
where:
2
βe −γr controls movement towards brighter fireflies.
αϵ introduces randomness to avoid local optima.
ϵ is a random number drawn from a uniform distribution.
Step 7: Apply Boundary Conditions
If a firefly moves outside the search space, adjust its position
to stay within bounds.
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
Step 8: Update Brightness Values
After fireflies move, re-evaluate their brightness based on the
objective function.
Step 9: Check for Termination Condition
If the maximum number of iterations (MaxGen) is reached or
an optimal solution is found, stop.
Otherwise, return to Step 3 and repeat the process.
Step 10: Return Best Solution
The firefly with the highest brightness (best objective function
value) is chosen as the optimal solution.
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Advantages:
Efficient Global Optimization.
Simple and Easy to Implement.
Parallelism and Distributed Computing.
Adaptability to Different Problems.
Fast Convergence Rate.
Robustness and Stability.
No Need for Initial Good Guess.
Self-Organizing Behavior.
Flexibility in Constraint Handling.
Better Performance Compared to Other Metaheuristic
Algorithms.
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Disadvantages:
Parameter Sensitivity.
Slow Convergence in Some Cases.
Computational Complexity for Large Problems.
Premature Convergence.
Lack of Diversity in Later Stages.
Difficulty in Handling Discrete Problems.
Performance Depends on Initialization.
Requires Large Number of Iterations for High Accuracy.
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
When to use:
When You Need Global Optimization.
When You Have Continuous Optimization Problems.
When the Objective Function is Non-Differentiable.
When You Need a Parallel or Distributed Algorithm.
When the Problem Has Many Local Minima.
When Other Metaheuristic Algorithms Struggle.
When You Need a Flexible Algorithm.
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
When to Avoid:
When the Problem is Low-Dimensional.
When High Precision is Required.
When the Problem is Discrete (Without Modifications).
When Computational Efficiency is a Priority.
When the Problem Has Well-Defined Gradients.
When FA Gets Trapped in Local Minima (Premature
Convergence).
When There is No Defined Fitness Function.
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Variants:
Chaos-Based Firefly Algorithm (CFA).
Quantum-Inspired Firefly Algorithm (QFA).
Lévy Flight Firefly Algorithm (LFA).
Adaptive Firefly Algorithm (AFA).
Multi-Objective Firefly Algorithm (MOFA).
Hybrid Firefly Algorithm (HFA).
Discrete Firefly Algorithm (DFA).
Dynamic Firefly Algorithm (DFA).
Parallel Cuckoo Search (PCS).
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm
Introduction
Working of FA
B.Tech (AI & ML) VI SEM Mohan Babu University, Tirupati
Firefly Optimization Algorithm