public Individual(Generation generation, Individual father, bool wasFatherSelectedByElitism, Individual mother, bool wasMotherSelectedByElitism) { Initialize(generation); _chromosomes = new Chromosome[TotalChromosomes]; // Initialize Secondary Mutation Chromosomes Chromosome[] parentChromosomes = new Chromosome[SecondaryMutationChromosomesAmount]; bool getFromFather = false; for (int i = 0; i < SecondaryMutationChromosomesAmount; i++) { parentChromosomes[i] = (getFromFather ? father : mother)._chromosomes[i]; getFromFather = !getFromFather; } parentChromosomes = parentChromosomes.RandomizeArray(); for (int i = 0; i < SecondaryMutationChromosomesAmount; i++) { _chromosomes[i] = parentChromosomes[i]; } // Divide The Rest Of The Chromosomes Based On Elitism float getChromosomeFromFatherChance = wasFatherSelectedByElitism == wasMotherSelectedByElitism ? 0.5f : wasFatherSelectedByElitism ? ElitismChromosomeChance : 1f - ElitismChromosomeChance; for (int i = SecondaryMutationChromosomesAmount; i < TotalChromosomes; i++) { _chromosomes[i] = (RandomManager.EvaluatePercentage(getChromosomeFromFatherChance) ? father : mother)._chromosomes[i]; } SimulateMutation(); }
public void SimulateMutation() { int totalChanges = 0; for (int i = 0; i < TotalChromosomes; i++) { if (totalChanges > MaxMutableChromosomes) { break; } if (!RandomManager.EvaluatePercentage(MutationChance)) { continue; } _chromosomes[i] = new Chromosome(this, !_chromosomes[i].Usable); totalChanges++; } }