According to James Kennedy & Russell Eberhart (1995), the algorithm process is as follows:
[x*] = PSO () P = Particle_initialization (); For i =1 to it_maxfor each particle p in P do FP = F (p); If FP is Better than F (pbest) pbest = p;endendgbest = Best p in P; For each particle p in P do v = v + c1*rand* (pbest–p) + c2*rand* (gbest–p);p = p + V; EndEnd
"NOTE"
Pbest is the best position of the individual in the process of movement;
Gbest is the best position in the world;
C1 represents a self-cognitive coefficient, C2 is a social cognitive factor, and Rand is a random number between [0,1].
< Span style= "font-style:normal; Font-variant:normal; " > < Span style= "font-style:normal; Font-variant:normal; " > < Span style= "font-style:normal; Font-variant:normal; " > C + + Implementation code: Https://github.com/wxiaoli/PSO
C + + implementation of the most basic PSO algorithm