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); }
List <GenoType> initPop(int n) { List <GenoType> pop = new List <GenoType>(); for (int i = 0; i < n; i++) { GenoType geno = new GenoType(rng); pop.Add(geno); } return(pop); }
private bool sameGeno(GenoType genoType1, GenoType genoType2) { bool equal = true; int i = 0; while (equal && i < genoType1.Bits.Count) { equal = genoType1.Bits[i] == genoType2.Bits[i]; i++; } return(equal); }