private void GenerationalMutation() { /* * Mutates a bit from random individuals from the population. * Number of mutations dictated in Constants.cs */ int individualIndex; int bitIndex; string completeChromosome; int softwareOrHardwareMutate; for (int times = 0; times < Constants.MutationProbability; times++) { individualIndex = MathematicalOperations.RandomIntegerInRange(0, Constants.PopulationSize); softwareOrHardwareMutate = MathematicalOperations.RandomIntegerInRange(0, 2); if (softwareOrHardwareMutate == 1) { bitIndex = MathematicalOperations.RandomIntegerInRange(0, Constants.CompleteChromosomeSize); completeChromosome = Population[individualIndex].Hardware.CompleteChromosome; completeChromosome = GeneticOperations.Mutate(bitIndex, completeChromosome); Population[individualIndex].Hardware.Mutate(completeChromosome); } else { bitIndex = MathematicalOperations.RandomIntegerInRange(0, Constants.SoftwareChromosomeSize); completeChromosome = Population[individualIndex].Software.CompleteChromosome; GeneticOperations.Mutate(bitIndex, completeChromosome); Population[individualIndex].Software.Mutate(completeChromosome); } } }
private (Robot, Robot) ReproduceIndividuals(Robot pParentA, Robot pParentB, int pId) { int hardwarePartitionIndex = MathematicalOperations.RandomIntegerInRange(1, Constants.CompleteChromosomeSize); int softwarePartitionIndex = MathematicalOperations.RandomIntegerInRange(1, Constants.SoftwareChromosomeSize); Robot child1 = new Robot(pParentA, pParentB, hardwarePartitionIndex, softwarePartitionIndex, pId, Id); Robot child2 = new Robot(pParentB, pParentA, hardwarePartitionIndex, softwarePartitionIndex, pId + 1, Id); return(child1, child2); }