Skip to main content
. 2021 Sep 29;7:e685. doi: 10.7717/peerj-cs.685

Algorithm 1. Particle swarm optimization.

input: D (search space), f (objective function)
output: g (swarm’s best known location)
hyperparameters: swarmsize, maxiter, minfunc, ω, ϕp, ϕg
begin
let swarmgenerateSwarm(swarmsize);
for each particleswarm do set its location as the best known position;
let gargminpf(p) p: each particles best known position
for i1 to maxiter do
  for particleswarm do
   let x, v, p as the particle’s position, current velocity, best known position;
   let rp,rgrandom(0,1);
    vωv+rpϕp(px)+rgϕg(gx);
    xx+v;
   if f(x) < f(p) then px;
  end
   gargminpf(p);
end
end