예제 #1
0
 public static void Modulo <G>(GeneticAlgorithm <G> alg, TeachingUnit teachingUnit)
     where G : TimeslotChromosome, IEquatable <G>
 {
     alg.PerformMutation = gen =>
     {
         var g = alg.CreateEmptyChromosome();
         g.Code = (gen.Code * 17) % teachingUnit.FreeTimeslots.Count;
         return(new G[] { g });
     };
 }
예제 #2
0
 public static void Random <G>(GeneticAlgorithm <G> alg, TeachingUnit teachingUnit)
     where G : TimeslotChromosome, IEquatable <G>
 {
     alg.PerformAppearence = () =>
     {
         var g = alg.CreateEmptyChromosome();
         g.Code = alg.Rnd.Next(teachingUnit.FreeTimeslots.Count);
         return(g);
     };
 }
 public static void ByElement <G, T>(GeneticAlgorithm <G> alg, Func <Random, T> elementGenerator)
     where G : ArrayChromosome <T>, IEquatable <G>
     where T : IEquatable <T>
 {
     alg.PerformAppearence = () =>
     {
         var g = alg.CreateEmptyChromosome();
         g.SetCode(z => elementGenerator(alg.Rnd));
         return(g);
     };
 }
 public static void Mix <G, T>(GeneticAlgorithm <G> alg)
     where G : ArrayChromosome <T>, IEquatable <G>
     where T : IEquatable <T>
 {
     alg.PerformCrossover = (g1, g2) =>
     {
         var g = alg.CreateEmptyChromosome();
         g.CheckLength(g1, g2);
         g.SetCode(i => alg.Rnd.Next(2) == 0 ? g1.Code[i] : g2.Code[i]);
         return(new G[] { g });
     };
 }
예제 #5
0
            public static void Shuffle <G>(GeneticAlgorithm <G> alg)
                where G : PermutationChromosome, IEquatable <G>
            {
                alg.PerformAppearence = () =>
                {
                    var g = alg.CreateEmptyChromosome();

                    g.Shuffle(alg.Rnd);

                    return(g);
                };
            }
예제 #6
0
            public static void Swap <G>(GeneticAlgorithm <G> alg)
                where G : PermutationChromosome, IEquatable <G>
            {
                alg.PerformMutation = gen =>
                {
                    var g = alg.CreateEmptyChromosome();

                    Array.Copy(gen.Code, g.Code, gen.Code.Length);
                    g.Swap(alg.Rnd);

                    return(new G[] { g });
                };
            }
 public static void ByElement <G, T>(GeneticAlgorithm <G> alg, Func <T, T> elementMutation)
     where G : ArrayChromosome <T>, IEquatable <G>
     where T : IEquatable <T>
 {
     alg.PerformMutation = gen =>
     {
         var g = alg.CreateEmptyChromosome();
         g.CheckLength(gen);
         g.SetCode(p => gen.Code[p]);
         var position = alg.Rnd.Next(g.Code.Length);
         g.Code[position] = elementMutation(g.Code[position]);
         return(new G[] { g });
     };
 }