Skip to main content
. 2026 Aug 12;11(8):576. doi: 10.3390/biomimetics11080576
Algorithm 1 Particle Swarm Optimization (PSO)
  •   1:

    Initialize population X(0) within the search space.

  •   2:

    Initialize particle velocities V(0).

  •   3:

    Evaluate f(xi(0)) for all particles.

  •   4:

    Set pbesti=xi(0).

  •   5:

    Set gbest as the best pbesti.

  •   6:

    Compute vmax according to Equation (12).

  •   7:

    while t<T do

  •   8:

          for i=1 to N do

  •   9:

            Generate random vectors r1 and r2.

  • 10:

            Update velocity according to Equation (11).

  • 11:

            Limit velocity components within [−vmax,vmax].

  • 12:

            Update position according to Equation (13).

  • 13:

            Project position into the feasible search space.

  • 14:

            Evaluate f(xi(t+1)).

  • 15:

            if f(xi(t+1)) improves f(pbesti) then

  • 16:

               Update pbesti.

  • 17:

            end if

  • 18:

            if f(pbesti) improves f(gbest) then

  • 19:

               Update gbest.

  • 20:

            end if

  • 21:

        end for

  • 22:

        t=t+1.

  • 23:

    end while

  • 24:

    return gbest.