예제 #1
0
 /// <summary>
 /// Initializes a new instance of a GeneticAlgorithm.
 /// </summary>
 /// <param name="mutationFunction">Mutation function to apply during evolution.</param>
 /// <param name="crossoverFunction">Crossover Function used during evolution.</param>
 /// <param name="selectionFunction">Selection Function used in chromosome selection.</param>
 /// <param name="pairingFunction">Pairing function used to select pairs of chromosomes during crossover.</param>
 public GeneticAlgorithm(IMutationFunction mutationFunction, ICrossoverFunction crossoverFunction,
                         ISelectionFunction selectionFunction, IPairingFunction pairingFunction)
 {
     this.Mutation  = mutationFunction;
     this.Crossover = crossoverFunction;
     this.Selection = selectionFunction;
     this.Pairing   = pairingFunction;
 }
예제 #2
0
파일: BaseGenetic.cs 프로젝트: toroerp/numl
        public void Test_Crossover <T>(Func <T> factory, int length, Func <IChromosome, IChromosome, IChromosome, bool> fnTest)
            where T : ICrossoverFunction
        {
            ICrossoverFunction crossover = factory();

            var s1      = Vector.Create(length, i => (i + 1) * 100);
            var parent1 = new Chromosome()
            {
                Sequence = s1.Copy()
            };

            var s2      = Vector.Create(length, i => (i + 1));
            var parent2 = new Chromosome()
            {
                Sequence = s2.Copy()
            };

            var child = crossover.Crossover(parent1, parent2);

            bool result = fnTest(parent1, parent2, child);

            Assert.True(result);
        }