最基本PSO算法的C++实现

按照James Kennedy & Russell Eberhart (1995)的版本,算法过程如下:

[x*] = PSO()
P = Particle_Initialization();
For i=1 to it_max
  For each particle p in P do
    fp = f(p);
    If fp is better than f(pBest)
      pBest = p;
    end
  end
  gBest = best p in P;
  For each particle p in P do
    v = v + c1*rand*(pBest – p) + c2*rand*(gBest – p);
    p = p + v;
  end
end

 【NOTE】

pbest是个体在移动过程中的历史最佳位置;

gbest是全局最佳位置;

c1表示自我认知系数,c2为社会认知系数,rand是[0,1]之间的随机数。

 

C++实现代码:https://github.com/wxiaoli/PSO

原文地址:https://www.cnblogs.com/wxiaoli/p/5557797.html