public List <IParticle> Initialize(IProblem problem, int number) { List <IParticle> particles = new List <IParticle>(number); for (int i = 0; i < number; i++) { StandardParticle particle = new StandardParticle(); particle.Parameters = Parameters; particle.Initialize(problem); particles.Add(particle); } return(particles); }
public override void Adapt(PSO algorithm) { double avgVelocity = AverageAbsoluteVelocity(algorithm); double idealVelocity = IdealVelocity(algorithm); for (int i = 0; i < algorithm.SwarmSize; i++) { StandardParticle particle = algorithm.Particles[i] as StandardParticle; double newInertia; if (avgVelocity >= idealVelocity) { newInertia = Math.Max(particle.Parameters.InertiaWeight.Parameter - Delta, Minimum); } else { newInertia = Math.Min(particle.Parameters.InertiaWeight.Parameter + Delta, Maximum); } particle.Parameters.InertiaWeight = new ConstantControlParameter(newInertia); } }
/// <summary> /// Calculate the velocity as an unbounded vector using the standard inertia weight model. /// </summary> /// <param name="particle">The particle to calculate velocity.</param> /// <returns>An unbounded Vector containing the velocity.</returns> public void UpdateVelocity(IParticle particle) { StandardParticle sp = particle as StandardParticle; //TODO: update previous velocity int dim = sp.Position.Length; double w = sp.Parameters.InertiaWeight.Parameter; double c1 = sp.Parameters.CognitiveAcceleration.Parameter; double c2 = sp.Parameters.SocialAcceleration.Parameter; Vector velocity = sp.Velocity; Vector pos = sp.Position; Vector lGuide = LocalGuiderProvider.GetGuide(sp); Vector nGuide = NeighbourhoodGuideProvider.GetGuide(sp); for (int i = 0; i < dim; i++) { double inertiaTerm = w * sp.Velocity[i]; double cognitiveTerm = c1 * RandomProvider.NextDouble() * (lGuide[i] - pos[i]); double socialTerm = c2 * RandomProvider.NextDouble() * (nGuide[i] - pos[i]); velocity[i] = inertiaTerm + cognitiveTerm + socialTerm; } }