Пример #1
0
 void UpdateGlobalBest(Particle particle)
 {
     if (particle.LocalBestFitness >= globalBestFitness)
         return;
     globalBest = particle.LocalBest;
     globalBestFitness = particle.LocalBestFitness;
 }
Пример #2
0
        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;
        }