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 viRD for i = 1 to N
    Initialize personal bests pbestxi, evaluate  f(pbesti)
       Set  gbestargmini·f(pbesti)
For t = 1  to Tmax 
DO
  For  i = 1  to N
  DO
        Update velocity viωvi+c1randpbestixi+c2randgbestixi
        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)