Skip to main content
. 2020 Apr 6;20(7):2056. doi: 10.3390/s20072056
Algorithm 3 Compact co-Firefly Algorithm

 ** Initialization **

generation=0;

 Initialize PVbetter and PVworse by setting all the probabilities inside as 0.5;

 generate elitebetter and eliteworse through PVbetter and PVworse, respectively;

 ** Evolving Process **

while generation<maxGen do

  ** Exploitation **

  generate a solution indnew through PVbetter;

  indnew = alpha-step(indnew); // see also Algorithm 1

  ** Competition **

  compete(elitebetter,indnew);

  if winner==indnew then

   elitebetter=indnew;

  end if

  ** PV Update **

  for i=0; i<PVbetter.length; i++ do

   if winner[i]==1 then

    PVbetter[i]better=PVbetter[i]+step;

   else

    PVbetter[i]=PVbetter[i]step;

   end if

  end for

  ** Exploration **

  generate a solution indnew through PVworse;

  indnew = beta-step(indnew, indworse); // see also Algorithm 2

  ** Competition **

  compete(eliteworse,indnew);

  if winner==indnew then

   swap(eliteworse,indnew);

  end if

  ** PV Update **

  for i=0; i<PVworse.length; i++ do

   if winner[i]==1 then

    PVworse[i]=PVworse[i]+step;

   else

    PVworse[i]=PVworse[i]step;

   end if

  end for

  ** Communication **

  compete(elitebetter,eliteworse);

  if winner==eliteworse then

   swap(elitebetter,eliteworse);

   swap(PVbetter,PVworse);

  end if

  update PVworse; // see also Section 4.2.2

  ** Judge whether the algorithm converges **

  if all elements of PVbetter and PVworse are equal to 1 or 0 then

   break;

  end if

end while

 output elitebetter;