// Create a new generation public void generate() { // Refill the population with children from the mating pool for (int i = 0; i < population.Length; i++) { int a = (int)(Random.Range(0, matingPool.Count)); int b = (int)(Random.Range(0, matingPool.Count)); DNAchar partnerA = matingPool[a]; DNAchar partnerB = matingPool[b]; DNAchar child = partnerA.crossover(partnerB); child.mutate(mutationRate); population[i] = child; } generations++; }
public void generate() { // Refill the population with children from the mating pool for (int i = 0; i < population.Length; i++) { int a = (int)(Random.Range(0, matingPool.Count)); int b = (int)(Random.Range(0, matingPool.Count)); //exercise9.4 two unique 'parents' if (a == b) { b = b + (b > 0.5 * matingPool.Count ? -1 : 1); } DNAchar partnerA = matingPool[a]; DNAchar partnerB = matingPool[b]; DNAchar child = partnerA.crossover(partnerB); child.mutate(mutationRate); population[i] = child; } generations++; }