예제 #1
0
 /*
  * Returns a new population, which is created by concatenating the two
  * given parameters.
  * */
 public Population Concat(Population p2)
 {
     Population p3 = new Population();
     foreach (Individual i in this)
     {
         p3.Add(i);
     }
     if (p2 != null) {
         foreach (Individual i in p2)
         {
             p3.Add(i);
         }
     }
     return p3;
 }
예제 #2
0
        public void Rank()
        {
            ranking = new List<Population>();
            ranking.Add(new Population());
            foreach (Individual p in population)
            {
                p.DominatedBy = 0;
                foreach (Individual q in population)
                {
                    if (!p.Equals(q))
                    {
                        if (p.Dominates(q))
                        {
                            p.AddToDominatedSet(q);
                        }
                        else
                        {
                            if (q.Dominates(p))
                            {
                                p.DominatedBy++;
                            }
                        }
                    }

                }
                if(p.DominatedBy == 0)
                {
                    ranking[0].Add(p);
                }
            }

            int i = 0;
            Population front = ranking[0];
            // do until nextFront has elements
            // else, there are no other fronts

            while (front.getPopulationCount() > 0)
            {
                var nextFront = new Population();
                foreach(Individual p in front)
                {
                    foreach(Individual q in p.getDominatedSet())
                    {
                        q.DominatedBy--;
                        if(q.getDominatedSet().getPopulationCount() <= 0)
                        {
                            nextFront.Add(q);
                            q.Fitness = i + 1;
                        }
                    }
                }
                i++;
                ranking.Add(nextFront);
                front = ranking.Last();
            }
            //int i = 0;
            //List<Solution> front = rankings.GetFront(i);
            //while (front.Count > 0)
            //{
            //    foreach (Solution p in front)
            //    {
            //        foreach (Solution q in p.DominatedSolutions)
            //        {
            //            q.DominationCount--;
            //            if (q.DominationCount == 0)
            //            {
            //                rankings.AddIndividual(i + 1, q);
            //            }
            //        }
            //    }
            //    i++;
            //    front = rankings.GetFront(i);
            //}

            // i hope this removes the empty (last) front
            ranking.Remove(front);
        }