示例#1
0
        public void PopulationRecombine()
        {
            RandomRegistry.Using(new Random(123), r =>
            {
                var pop  = TestUtils.NewDoubleGenePopulation(5, 1, 2);
                var copy = pop.Copy();

                var recombinator = new LineCrossover <DoubleGene, double>(1);

                recombinator.Alter(pop, 10);

                for (var i = 0; i < pop.Count; ++i)
                {
                    ISeq <DoubleGene> genes = pop[i]
                                              .GetGenotype()
                                              .GetChromosome()
                                              .ToSeq();

                    ISeq <DoubleGene> genesCopy = copy[i]
                                                  .GetGenotype()
                                                  .GetChromosome()
                                                  .ToSeq();

                    foreach (var t in genes)
                    {
                        Assert.NotEqual(t, genesCopy[i]);
                    }
                }
            });
        }
示例#2
0
        public void Recombine()
        {
            DoubleGene Factory()
            {
                return(DoubleGene.Of(0, 100));
            }

            var v = MutableSeq.Of(Factory, 10);
            var w = MutableSeq.Of(Factory, 10);

            var recombinator = new LineCrossover <DoubleGene, double>();

            recombinator.Crossover(v, w);

            Assert.True(v.ForAll(dg => dg.IsValid));
            Assert.True(w.ForAll(dg => dg.IsValid));
        }