// Crossover internal DNA crossover(DNA partner) { // A new child DNA child = new DNA(genes.Length); int midpoint = (int)(Helper.GenerateRandomNumber(0,genes.Length)); // Pick a midpoint // Half from one, half from the other for (int i = 0; i < genes.Length; i++) { if (i > midpoint) child.genes[i] = genes[i]; else child.genes[i] = partner.genes[i]; } return child; }
public Population(String p, double m, int num) { target = p; mutationRate = m; population = new DNA[num]; for (int i = 0; i < population.Length; i++) { population[i] = new DNA(target.Length); } calcFitness(); matingPool = new List<DNA>(); finished = false; generations = 0; perfectScore = 1; }