top of page
  • Writer's pictureAdisorn O.

Firefly Algorithm (FA): Part I -- Introduction & Concept

Adisorn Owatsiriwong

ALPS Consultants


Firefly algorithm is another metaheuristic approach for global optimization. The method was developed by Xin-She Yang (2008) based on the behavior of flashing fireflies to attract mates or prey. In this and the following articles, we will ground the basics of the Firefly algorithm; moreover, the pros and cons of the method compared to Particle Swarm Optimization (PSO) will be investigated by example of multi-modal objective functions. It can be later seen that FA and PSO share a similar concept of exploration and exploration in updating particle position. As seen in the figure below, this includes inertia, global best, and personal randomness.


Like most population approaches, the Firefly algorithm starts by popularizing the agents (flyfires). Each firefly contains the element of design variables. Three main concepts are the backbone of the Flyfire algorithm:

  1. Attraction: This is the key behavior of fireflies when interacting with others. In Yang's approach, fireflies will attract others regardless of gender. The less bright firefly will move towards the brighter one to achieve the exploration goal.

  2. Brightness: The brightness is a source that attracts other fireflies regardless of the distance between them. The value of the objective function can represent brightness.

  3. Absorptions: The brightness will decrease as the distance between two flies increases. This enforces the exploitation scheme as the fly would choose to move towards the closest brighter source (bringing the solution toward local minima).

The flowchart of Firefly algorithm can be shown in the figure below.

  1. Initialize Parameters: Set the number of fireflies, light absorption coefficient, attractiveness, and other parameters.

  2. Generate Initial Population: Randomly initialize the positions of the fireflies.

  3. Evaluate Fireflies: Calculate the light intensity (objective function value) for each firefly.

  4. Update Positions: For each firefly, compare its light intensity with others and move it towards brighter fireflies.

  5. Update Intensity: Recalculate the light intensity after moving the fireflies.

  6. Check Termination: If the maximum number of generations is reached or another stopping criterion is met, terminate; otherwise, go back to step 4.

  7. Output Best Solution: Report the best solution found :


XS Yang, Nature-Inspired Metaheuristics Algorithms, 2nd Ed., Luniver Press

OpenAI. (2024). ChatGPT (4) [Large language model].



bottom of page