Skip to main content
. 2023 Mar 20;23(6):3293. doi: 10.3390/s23063293
Algorithm 3 Pseudo-code for PSO Algorithm.
  • 1:

    Determine objective function f(x).

  • 2:

    Initialize parameters c1, c2, wmax, wmin, and population size nPop.

  • 3:

    Evaluate the fitness of each particle and set all initial positions as Pbest,x.

  • 4:

    Generate an initial population of particles.

  • 5:

    whilet<MaxGenerationdo

  • 6:

        Select the Gbest particle in the swarm, which has the minimum fitness value

  • 7:

        for i=1:nPop do

  • 8:

            Calculate the velocity of particle xi.

  • 9:

            Update the position of particle xi.

  • 10:

        end for

  • 11:

        for i=1:nPop do

  • 12:

            Evaluate the fitness of updated particle xi.

  • 13:

            if f(xi)<f(Pbest,x) then

  • 14:

               Set current position as Pbest,x.

  • 15:

            end if

  • 16:

        end for

  • 17:

        Find the best particle

  • 18:

    end while