示例#1
0
        public virtual void AssignNeighborhoodBests(PSOSubpopulation subpop)
        {
            for (var j = 0; j < subpop.Individuals.Count; j++)
            {
                var hoodBest = subpop.NeighborhoodBests[j];
                var start    = (j - subpop.NeighborhoodSize / 2);
                if (start < 0)
                {
                    start += subpop.Individuals.Count;
                }

                for (var i = 0; i < subpop.NeighborhoodSize; i++)
                {
                    var ind = (DoubleVectorIndividual)subpop.Individuals[(start + i) % subpop.Individuals.Count];
                    if ((hoodBest == null) || ind.Fitness.BetterThan(hoodBest.Fitness))
                    {
                        hoodBest = ind;
                    }
                }

                if (hoodBest != subpop.NeighborhoodBests[j])
                {
                    subpop.NeighborhoodBests[j] = (DoubleVectorIndividual)hoodBest.Clone();
                }
            }
        }
示例#2
0
 public virtual void AssignPersonalBests(PSOSubpopulation subpop)
 {
     for (var i = 0; i < subpop.PersonalBests.Length; i++)
     {
         if ((subpop.PersonalBests[i] == null) || subpop.Individuals[i].Fitness.BetterThan(subpop.PersonalBests[i].Fitness))
         {
             subpop.PersonalBests[i] = (DoubleVectorIndividual)subpop.Individuals[i].Clone();
         }
     }
 }
示例#3
0
        public virtual void AssignGlobalBest(PSOSubpopulation subpop)
        {
            var globalBest = subpop.GlobalBest;

            foreach (var t in subpop.Individuals)
            {
                var ind = (DoubleVectorIndividual)t;
                if ((globalBest == null) || ind.Fitness.BetterThan(globalBest.Fitness))
                {
                    globalBest = ind;
                }
            }
            if (globalBest != subpop.GlobalBest)
            {
                subpop.GlobalBest = (DoubleVectorIndividual)globalBest.Clone();
            }
        }