- Introduced by
- Xin-She Yang
- Year
- 2008
- Type
- Swarm intelligence metaheuristic
What does it do?
The Firefly Algorithm (FA), introduced by Xin-She Yang in 2008 and formally published in 2010, is a nature-inspired swarm metaheuristic modelled on the flashing attraction of fireflies.
Each candidate solution is a firefly whose brightness reflects its objective value, and fireflies move toward brighter ones with an attraction that weakens with distance. The method is gradient-free, so it needs only objective-function evaluations.
The intuition behind the method
Picture fireflies on a dark night: each drifts toward brighter ones it can see, and the glow fades with distance. In FA, brightness encodes solution quality, so the population is pulled toward good solutions. Because attraction is local rather than global, the population may split into groups around several bright spots. This can help on landscapes with multiple peaks, but it is not guaranteed and depends on parameter choice. No gradient is computed at any stage.
History
Xin-She Yang introduced the Firefly Algorithm in 2008, and the formulation was published in 2010 in the International Journal of Bio-Inspired Computation. The 2010 paper applied the method to pressure vessel design and proposed new test functions with known global optima for validating optimisation algorithms. The method is inspired by the bioluminescent flashing behaviour of fireflies.
When to use it
Choose the Firefly Algorithm for continuous problems with bounded variables where the objective is expensive, noisy or non-differentiable and the landscape may contain several competing optima. Because it needs only objective values, it fits black-box settings such as engineering design or fitting a simulation model. Do not choose it for purely discrete or combinatorial problems unless you are prepared to adapt the representation. Avoid it when the pairwise comparison cost of a large swarm would exceed your evaluation budget. For smooth, unimodal problems where gradients are available, gradient-based methods are usually more efficient.
Limitations and considerations
- The attraction step compares every firefly with every other, so the cost per iteration grows with the square of the population size, which limits how large a swarm can be run within a fixed budget.
- In high-dimensional spaces a swarm has more volume to cover, so the population often has to grow to maintain coverage, and the pairwise cost grows with it.
- Performance depends on γ: a poorly chosen value either collapses the swarm prematurely or prevents it from converging.
- The standard formulation is defined over continuous spaces; discrete or combinatorial variants require problem-specific changes.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Pairwise attraction can form sub-swarms that may locate several optima at once, which may suit multimodal objectives, depending on parameter choice.
- Gradient-free: only objective evaluations are needed, so black-box and non-differentiable objectives are accessible.
- Tuning centres on a small set of controls: the attraction coefficient β₀ and the absorption parameter γ, together with the randomisation term in the position update.
- Makes no distributional assumptions about the objective function or the search space.
Applications
- Engineering design optimisation, such as the pressure vessel design problem treated in the 2010 original paper.
- Hyper-parameter tuning of machine-learning models where the objective is stochastic or non-differentiable.
- Model fitting in scientific work where gradients are unavailable and the objective is multimodal.
- Determining criteria weights in multi-criteria decision making, where weights are obtained by solving a non-linear multi-objective problem with the Firefly algorithm, as in a TOPSIS-based study on q-rung orthopair fuzzy sets.
- Scheduling and resource allocation, typically using discrete adaptations of the algorithm.
How it works
How it works
A population of fireflies is scattered uniformly at random across the continuous search space. Each firefly's position represents one candidate solution to the problem.
The objective function is computed for every firefly and converted into brightness so that better solutions are brighter. For maximisation, brightness can follow the objective directly. For minimisation, the objective must be mapped to a brightness that decreases as the objective increases and is nonnegative, because attraction is defined as proportional to brightness. State the explicit mapping used and make sure it matches the formulation being implemented. Negating the objective is not a default, since it can produce negative brightness.
Each firefly compares itself with every other firefly and is pulled toward each brighter one. The pull is scaled by the attraction coefficient β₀ and weakened as distance grows, with the rate of decay set by the light-absorption parameter γ. Because every pair is examined, the cost of this step grows with the square of the population size. β₀ and γ are the main tuning parameters.
Each firefly moves toward the brighter fireflies that attract it and receives a small random perturbation. The globally brightest firefly has no brighter firefly to follow, so it moves only randomly and keeps exploring. Over iterations the population may organise into sub-swarms around local or global optima, depending on the parameter settings.
The loop over evaluation → attraction → update repeats for a fixed number of iterations or until a convergence criterion is met. The brightest firefly position across all iterations is returned as the best solution found.
Common pitfalls
- A large γ makes attraction fall off so quickly that each firefly interacts only with very close neighbours. The swarm then behaves more like independent local moves and shares little information. Scale γ to the extent of the search space.
- A small γ makes attraction nearly global, pulling the whole swarm toward one point early, which can remove the potential benefit for multimodal landscapes.
- In high dimensions a small population covers the space sparsely. Increase the population as the number of variables grows rather than keeping it fixed.
- Monitor the best-fitness curve over iterations. If the curve flattens while the spread of positions has collapsed, the swarm has converged to one point and may have missed other optima.
- FA is stochastic because the position update includes a random perturbation. Results therefore differ between runs and random seeds, and no single run establishes the optimum. Report results over several independent runs, for example the best, mean and spread of the final best fitness.
Frequently asked questions
How do I choose the light-absorption parameter γ?
γ controls how quickly attraction decays with distance. Relate it to the size of the search space so that attraction remains meaningful across the region where fireflies move. Then test a few values on a representative run and compare convergence before committing to one.
How does the Firefly Algorithm compare to Particle Swarm Optimization?
Both are swarm methods, but PSO guides each particle with personal-best and global-best memories, whereas FA moves each firefly toward every brighter firefly it can perceive. The pairwise mechanism may give FA a tendency to form sub-swarms around several optima, depending on parameters. Which performs better depends on the problem and should be tested on it.
Can the Firefly Algorithm handle discrete or combinatorial problems?
Not directly in its standard form, which is defined over continuous spaces. Discrete variants have been proposed in the literature, but they are not part of the original formulation and require problem-specific adaptation of the representation and operators.
How many fireflies (population size) should I use?
There is no fixed rule. The attraction step compares all pairs of fireflies, so the cost per iteration grows with the square of the population size. Start with a moderate population, increase it if coverage seems sparse in high dimensions, and compare runs at equal evaluation budgets.
Related methods
Sources
Yang, X.S. (2010). Firefly Algorithm, Stochastic Test Functions and Design Optimisation. International Journal of Bio-Inspired Computation, 2(2), 78-84.
Open DOI referenceYang, X.S. (2014). Nature-Inspired Optimization Algorithms. Elsevier.
ISBN: 978-0-12-416743-8Garg_2022_qROFS_Theory_Applications_Springer, p. 132