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.