void UpdateGlobalBest(Particle particle) { if (particle.LocalBestFitness >= globalBestFitness) return; globalBest = particle.LocalBest; globalBestFitness = particle.LocalBestFitness; }
public Point DoAlgorithm(int numberParticles, int numberLoops) { globalBestFitness = Int32.MaxValue; List<Particle> particles = new List<Particle>(); for (int i = 0; i != numberParticles; ++i) { Particle particle = new Particle(FindRandomPoint(), this); particles.Add(particle); UpdateGlobalBest(particle); } for (int turn = 0; turn != numberLoops; ++turn) { foreach (Particle particle in particles) { particle.Update(globalBest); UpdateGlobalBest(particle); } } return globalBest; }