Firefly Algorithm Simulator: Light-Based Swarm Optimization

simulator intermediate ~10 min
Loading simulation...
3 of 4 optima located — multi-modal discovery

40 fireflies with γ=1.0, β₀=1.0, α=0.2 naturally cluster around 3 of 4 global optima on a multi-modal landscape within 50 iterations — demonstrating the algorithm's inherent multi-modal capability.

Formula

β(r) = β₀ × exp(−γ × r²) (attractiveness decays with distance)
x_i ← x_i + β(r_ij) × (x_j − x_i) + α × ε (movement toward brighter firefly)
I(x) = f(x) (brightness equals objective function value)

Bioluminescent Inspiration

On warm summer nights, fireflies flash to attract mates. Brighter flashes draw more attention, and the light fades with distance following the inverse-square law modified by atmospheric absorption. Xin-She Yang formalized this behavior in 2008 as an optimization algorithm where solution quality maps to brightness and movement follows attraction gradients. The result is a uniquely visual algorithm — this simulation renders each firefly as a glowing point whose brightness reflects its fitness value.

Distance-Dependent Attraction

The defining feature of the firefly algorithm is that attractiveness β decays exponentially with distance: β = β₀·exp(-γr²). This simple mechanism produces profound consequences. Nearby fireflies interact strongly and cluster together, while distant ones barely influence each other. The swarm naturally partitions into sub-swarms, each converging on a different local optimum. This emergent multi-modal behavior is the algorithm's greatest strength, visible in the simulation as distinct glowing clusters forming across the landscape.

Tuning Light and Shadow

The absorption coefficient γ is the algorithm's most important parameter. When γ → 0, attraction is distance-independent and all fireflies converge to a single global optimum (PSO-like behavior). When γ is large, only nearest neighbors interact, producing many small clusters with high diversity. Intermediate values balance global communication and local search. The randomization parameter α adds exploration noise, preventing clusters from freezing prematurely. The simulation lets you sweep γ and watch the swarm reorganize in real time.

Multi-Modal Power

Many real-world problems have multiple acceptable solutions — an antenna can meet specifications with different geometries, a robot can reach a target via multiple paths. Standard optimizers find just one solution; the firefly algorithm naturally identifies several. This makes it valuable for design space exploration, where understanding the landscape of feasible solutions matters as much as finding the single best. The simulation demonstrates this on a test function with four equal optima, showing how firefly clusters independently locate each one.

FAQ

What is the firefly algorithm?

The Firefly Algorithm (FA), proposed by Xin-She Yang in 2008, is inspired by the flashing behavior of fireflies. Each firefly represents a solution; its brightness corresponds to fitness. Less bright fireflies move toward brighter ones, with attraction decreasing with distance (due to light absorption). This distance-dependent attraction naturally subdivides the swarm into groups around multiple optima.

How does light absorption affect the algorithm?

The absorption coefficient γ controls the range of attraction. High γ means light fades quickly with distance, so fireflies only attract nearby individuals, forming local clusters around separate optima. Low γ means all fireflies interact globally, converging to a single optimum. This parameter gives FA a natural multi-modal search capability that PSO lacks.

What is the advantage over particle swarm optimization?

The key advantage is multi-modal optimization. PSO's global best drives all particles to one optimum. FA's distance-dependent attraction naturally partitions the swarm into subgroups, each converging on a different optimum. This makes FA superior for problems with multiple equally good solutions, such as multi-modal function optimization and design space exploration.

What are real-world applications of the firefly algorithm?

FA has been applied to structural engineering optimization, antenna array design, image compression, feature selection in machine learning, scheduling problems, and economic dispatch in power systems. Its multi-modal capability is particularly valuable in engineering design where multiple feasible configurations may exist.

Sources

Embed

<iframe src="https://homo-deus.com/lab/swarm-intelligence/firefly-algorithm/embed" width="100%" height="400" frameborder="0"></iframe>
View source on GitHub