Skip to main content
. 2020 Jan 8;20(2):356. doi: 10.3390/s20020356
Algorithm 1 Particle Swarm Optimization (PSO) Algorithm.
Input:
        Maximum number of iterations (MaxIt).
        Population size (PopSize).
        Lower and upper bound variables (varmin,varmax).
Output:
        Best value of all particles (GlobalBestrssi).
  • 1:

    for i=1:PopSize do

  • 2:

        Vi=0

  • 3:

        posi=rand(varmin,varmax)

  • 4:

        rssii=pathloss(posi)

  • 5:

        Bestposi=posi

  • 6:

        if Bestrssii<GlobalBestrssi then

  • 7:

            GlobalBestrssi=Bestrssii

  • 8:

        end if

  • 9:

    end for

  • 10:

    for t=1:MaxIt do

  • 11:

        for i=1:PopSize do

  • 12:

            Vi(t)=WVi(t)+r1c1(Bestposi(t)Loci(t))+r2c2(GlobalBestpos(t)posi(t))

  • 13:

            posi(t)=posi(t)+Vi(t))

  • 14:

            rssii=pathloss(posi)

  • 15:

            if rssii<Bestrssii then

  • 16:

               Bestposi(t)=posi(t)

  • 17:

               Bestrssii=rssii

  • 18:

               if Bestrssi<GlobalBestrssi then

  • 19:

                   GlobalBestrssi=Bestrssii

  • 20:

               end if

  • 21:

            end if

  • 22:

        end for

  • 23:

    end for