Skip to main content
. 2023 Jul 4;25(7):1021. doi: 10.3390/e25071021
Algorithm 3 Firefly Algorithm
  • 1:

    Objective function f(x), x=(x1,,xd)T

  • 2:

    Generate initial population of fireflies xi(i=1,2,,n)

  • 3:

    Light intensity I is given by f(xi) where f(·) is the chosen objective function

  • 4:

    Define light absorption coefficient γ

  • 5:

    while t< maxGeneration do

  • 6:

        for 1in do

  • 7:

         for 1jn do

  • 8:

         if Ii<Ij then

  • 9:

           Move firefly i towards firefly j

  • 10:

          end if

       Vary attractiveness according to r

  • 11:

       Evaluate new solution and update light intensity

  • 12:

         end for

  • 13:

        end for

  • 14:

        Rank the fireflies and find the current global best g*

  • 15:

    end while