Beispiel #1
0
        protected override Chromosome Perform(Chromosome father, Chromosome mother, GAConfiguration configuration)
        {
            var geneCount = father.Genes.Length;

            var childOne = new UnorderedChromosome(geneCount);
            var childTwo = new UnorderedChromosome(geneCount);

            var crossoverPoint = configuration.GetRandomInteger(1, father.Genes.Length - 1);

            for (int i = 0; i < geneCount; i++)
            {
                if (i < crossoverPoint)
                {
                    childOne.Genes[i] = father.Genes[i];
                    childTwo.Genes[i] = mother.Genes[i];
                }
                else
                {
                    childOne.Genes[i] = mother.Genes[i];
                    childTwo.Genes[i] = father.Genes[i];
                }
            }

            if (configuration.GetNextDouble() < 0.5)
            {
                return(childOne);
            }
            else
            {
                return(childTwo);
            }
        }
Beispiel #2
0
 public void Mutate(Chromosome chromosome, GAConfiguration settings)
 {
     for (int i = 0; i < chromosome.Genes.Length; i++)
     {
         if (settings.GetNextDouble() < settings.MutationRate)
         {
             Perform(settings, chromosome, i);
         }
     }
 }
        protected override Chromosome Perform(Chromosome father, Chromosome mother, GAConfiguration configuration)
        {
            DetermineCrossoverPoints(father.Genes.Length, configuration);

            var children = DetermineChildren(father, mother, _firstCrossoverPoint, _secondCrossoverPoint);

            if (configuration.GetNextDouble() < 0.5)
            {
                return(children[0]);
            }
            else
            {
                return(children[1]);
            }
        }