Exemple #1
0
        public void CrossoverChanges()
        {
            var g1 = CharacterChromosome.Of("1234567890").ToSeq();
            var g2 = CharacterChromosome.Of("abcdefghij").ToSeq();

            RandomRegistry.Using(new Random(10), r =>
            {
                var crossover = new UniformCrossover <CharacterGene, char>(0.5, 0.5);

                var statistics = new DoubleMomentStatistics();

                for (var j = 0; j < 1000; ++j)
                {
                    var g1C     = g1.Copy();
                    var g2C     = g2.Copy();
                    var changed = crossover.Crossover(g1C, g2C);

                    Assert.Equal(Enumerable
                                 .Range(0, g2C.Length)
                                 .Count(i => char.IsDigit(g2C[i].Allele)), changed
                                 );

                    statistics.Accept(changed);
                }

                Assert.Equal(5.0, statistics.Mean, 1);
            });
        }
Exemple #2
0
        public void Crossover()
        {
            var g1 = CharacterChromosome.Of("1234567890").ToSeq();
            var g2 = CharacterChromosome.Of("abcdefghij").ToSeq();

            RandomRegistry.Using(new Random(10), r =>
            {
                var crossover = new UniformCrossover <CharacterGene, char>(0.5, 0.5);

                var g1C     = g1.Copy();
                var g2C     = g2.Copy();
                var changed = crossover.Crossover(g1C, g2C);

                Assert.Equal(Enumerable.Range(0, g2C.Length).Count(i => char.IsDigit(g2C[i].Allele)), changed);
            });
        }