Ejemplo n.º 1
0
        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);
                }
            }
        }