示例#1
0
        public void CrossoverAll1()
        {
            var chars = CharSeq.Of("a-zA-Z");
            var g1    = new CharacterChromosome(chars, 20).ToSeq();
            var g2    = new CharacterChromosome(chars, 20).ToSeq();

            var crossover = new MultiPointCrossover <CharacterGene, double>(2000);
            var points    = new int[g1.Length];

            for (var i = 0; i < points.Length; ++i)
            {
                points[i] = i;
            }

            var ms1 = g1.Copy();
            var ms2 = g2.Copy();

            crossover.Crossover(ms1, ms2);
        }
示例#2
0
        public void ReverseCrossover(int npoints)
        {
            for (var i = 1; i < 500; ++i)
            {
                var chars = CharSeq.Of("a-zA-Z");
                var a     = new CharacterChromosome(chars, i).ToSeq().Select(g => g.Allele).ToImmutableSeq();
                var b     = new CharacterChromosome(chars, i).ToSeq().Select(g => g.Allele).ToImmutableSeq();

                var ma1    = a.Copy();
                var mb1    = b.Copy();
                var points = Base.Subset(
                    a.Length + 1,
                    Math.Min(npoints, a.Length + 1),
                    new Random(1234)
                    );

                MultiPointCrossover.Crossover(ma1, mb1, points);
                MultiPointCrossover.Crossover(ma1, mb1, points);

                Assert.Equal(a, ma1);
                Assert.Equal(b, mb1);
            }
        }