Skip to main content
. 2021 May 16;21(10):3460. doi: 10.3390/s21103460
Algorithm 1 Pseudo-code of the Moth Search Algorithm.
  •  1:

    Define the population number of moths NPop, the sub-populations NPopA and NPopB, the maximum number of generations MaxGen, and the number of decision variables MaxVar

  •  2:

    Define the maximum step size of random path in Lévy distribution stepmax = 1.0

  •  3:

    Set g = 1

  •  4:

    for (g = 1; g++; gMaxGen) do

  •  5:

     Initialize the position mi,jg, the best position mbest,jg and the fitness value OF(mi,jg) of each i-th moth in every j-th decision variable at g-th generation

  •  6:

     ——————————Lévy flight——————————

  •  7:

     Set iA = 1 and index = 1.5

  •  8:

    for (iA = 1; iA++; iANPopA) do

  •  9:

        Compute the scale factor fsc using (3)

  • 10:

      Compute the Lévy distribution parameter value using (2)

  • 11:

      Compute the position of each moth using (1)

  • 12:

    end for

  • 13:

     ——————————Straight flight——————————

  • 14:

     Set iB = 1

  • 15:

    for (iB = 1; iB++; iBNPopB) do

  • 16:

      Set j = 1

  • 17:

      for (j = 1; j++; jMaxVar) do

  • 18:

       if (rand0.5) then

  • 19:

        Compute the position of each moth using (4a)

  • 20:

       else

  • 21:

        Compute the acceleration factor using (5)

  • 22:

        Compute the position of each moth using (4b)

  • 23:

       end if

  • 24:

      end for

  • 25:

    end for

  • 26:

     Compute the updated fitness value OF(mi,jg) for each moth

  • 27:

     Update the moth with the best position mbest,jg based on the fitness value

  • 28:

    end for