Пример #1
0
        public void createOffspring(Random rng, Function f, CrossOver cs)
        {
            scramble();
            int popSize = pop.Count;

            for (int i = 0; i < popSize; i = i + 2)
            {
                GenoType p1 = pop[i];
                GenoType p2 = pop[i + 1];
                Tuple <BitArray, BitArray> childrenTuple = cs.Cut(p1.Bits, p2.Bits, rng);
                GenoType c1 = new GenoType(rng, childrenTuple.Item1);
                GenoType c2 = new GenoType(rng, childrenTuple.Item2);

                //Console.WriteLine("---------------------------------------");
                //Console.WriteLine("parent1: {0}", p1.print());
                //Console.WriteLine("parent2: {0}", p2.print());
                //Console.WriteLine("child1:  {0}", c1.print());
                //Console.WriteLine("child2:  {0}", c2.print());
                //Console.ReadLine();

                //aan dezelfde lijst toevoegen # gevaarlijk zeg jeez
                pop.Add(c1);
                pop.Add(c2);
            }

            //yolo hackaton ez
            pop = pop.OrderByDescending(x => f.Evaluate(x.Bits)).Take(popSize).ToList();


            ////dit is voor mijzelf dit is inefficient
            //double weightPopulation = 0;
            //pop.ForEach(x => weightPopulation += f.Evaluate(x.Bits));
            //Console.WriteLine(weightPopulation);
        }
Пример #2
0
 public Row(Function f, CrossOver cs, int popSize)
 {
     F            = f;
     Cs           = cs;
     PopSize      = popSize;
     FirstHits    = new List <int>();
     GenConverges = new List <int>();
     FctEvals     = new List <int>();
     CPUTime      = new List <int>();
 }