Skip to main content
. 2025 Nov 18;25(22):7032. doi: 10.3390/s25227032
Algorithm 1. Particle Swarm Optimization Procedure
Input: Objective function f(x), number of particles N, dimension D, inertia weight ω, acceleration coefficients c1, c2, max iterations  Tmax
    Initialize particle positions xi ∈RD and velocities vi∈RD for i = 1 to N
    Initialize personal bests pbest←xi, evaluate  f(pbesti)
       Set  gbest←argmini·f(pbesti)
For t = 1  to Tmax 
DO
  For  i = 1  to N
  DO
        Update velocity vi←ω∗vi+c1∗rand∗pbesti−xi+c2∗rand∗gbesti−xi
        Update position xi ← xi + vi
        Evaluate fitness f(xi)
        If f(xi) < f(pbesti) then
          pbesti ←xi
        If f(pbesti) < f(gbest) then
           gbest ← pbesti
        END IF
     END IF
   END FOR
  END FOR
return gbest, fgbest
Output: Global best position gbest and value f(gbest)