示例#1
0
 // Mutate an individual
 private static void mutate(Individual indiv)
 {
     // Loop through genes
     for (int i = 0; i < indiv.size(); i++)
     {
         if (Rnd.NextDouble() <= MutationRate)
         {
             // Create random gene
             byte gene = (byte)Math.Round(Rnd.NextDouble());
             indiv.setGene(i, gene);
         }
     }
 }
示例#2
0
        // Crossover individuals
        private static Individual crossover(Individual indiv1, Individual indiv2)
        {
            Individual newSol = new Individual();

            // Loop through genes
            for (int i = 0; i < indiv1.size(); i++)
            {
                // Crossover
                if (Rnd.NextDouble() <= UniformRate)
                {
                    newSol.setGene(i, indiv1.getGene(i));
                }
                else
                {
                    newSol.setGene(i, indiv2.getGene(i));
                }
            }
            return(newSol);
        }
示例#3
0
 // Mutate an individual
 private static void mutate(Individual indiv)
 {
     // Loop through genes
     for (int i = 0; i < indiv.size(); i++) {
         if (Rnd.NextDouble() <= MutationRate) {
             // Create random gene
             byte gene = (byte)Math.Round(Rnd.NextDouble());
             indiv.setGene(i, gene);
         }
     }
 }
示例#4
0
 // Crossover individuals
 private static Individual crossover(Individual indiv1, Individual indiv2)
 {
     Individual newSol = new Individual();
     // Loop through genes
     for (int i = 0; i < indiv1.size(); i++) {
         // Crossover
         if (Rnd.NextDouble() <= UniformRate) {
             newSol.setGene(i, indiv1.getGene(i));
         } else {
             newSol.setGene(i, indiv2.getGene(i));
         }
     }
     return newSol;
 }