当前位置: 首页>>代码示例>>C#>>正文


C# Chromosome.Recombine方法代码示例

本文整理汇总了C#中Chromosome.Recombine方法的典型用法代码示例。如果您正苦于以下问题:C# Chromosome.Recombine方法的具体用法?C# Chromosome.Recombine怎么用?C# Chromosome.Recombine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chromosome的用法示例。


在下文中一共展示了Chromosome.Recombine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestAsymetricCrossoverRecombinator

        public void TestAsymetricCrossoverRecombinator()
        {
            Chromosome<BoolGene> father = new Chromosome<BoolGene>(2);
            Chromosome<BoolGene> mother = new Chromosome<BoolGene>(2);
            IRecombinationProvider recombinator = new AsymmetricCrossoverRecombinator();

            father[0] = true;
            father[1] = false;
            mother[0] = false;
            mother[1] = true;

            Chromosome<BoolGene> child = father.Recombine(mother, recombinator);
            Assert.IsTrue(child.GeneCount == 2);
            Assert.IsTrue(child[0] == true && child[1] == true, "Fix recombination not correct!");

            father[0].Mutate();
            mother[1].Mutate();

            child = father.Recombine(mother, recombinator);
            Assert.IsTrue(child[0].Equals(father[0]) && child[1].Equals(mother[1]), "Variable recombination not correct!");

            father = new Chromosome<BoolGene>(3);
            mother = new Chromosome<BoolGene>(5);

            father[0] = true;//child 0
            father[1] = false;//child 1
            father[2] = true;
            mother[0] = false;
            mother[1] = true;
            mother[2] = false;
            mother[3] = true; //child 2
            mother[4] = false; // child 3

            child = father.Recombine(mother, recombinator);
            Assert.IsTrue(child.GeneCount == 4);
            Assert.IsTrue(child[0] == true && child[1] == false && child[2] == true && child[3] == false, "Fix recombination in asymetric Mother/Father not correct!");
        }
开发者ID:ningboliuwei,项目名称:Genetic-Algorithms,代码行数:37,代码来源:GeneticAlgorithmsTest.cs

示例2: TestCrossoverRecombinatorException

 public void TestCrossoverRecombinatorException()
 {
     Chromosome<BoolGene> chrom1 = new Chromosome<BoolGene>(1);
     Chromosome<BoolGene> chrom2 = new Chromosome<BoolGene>(2);
     IRecombinationProvider recom = new CrossoverRecombinator();
     Chromosome<BoolGene> newChrom = chrom1.Recombine(chrom2, recom);
 }
开发者ID:ningboliuwei,项目名称:Genetic-Algorithms,代码行数:7,代码来源:GeneticAlgorithmsTest.cs

示例3: TestCrossoverRecombinator

        public void TestCrossoverRecombinator()
        {
            Chromosome<BoolGene> father = new Chromosome<BoolGene>(2);
            Chromosome<BoolGene> mother = new Chromosome<BoolGene>(2);
            IRecombinationProvider recombinator = new CrossoverRecombinator();

            father[0] = true;
            father[1] = false;
            mother[0] = false;
            mother[1] = true;

            Chromosome<BoolGene> child = father.Recombine(mother, recombinator);
            Assert.IsTrue(child[0] == true && child[1] == true, "Fix recombination not correct!");

            // Following only functional with inverting Mutation!
            father[0].Mutate();
            Assert.IsFalse(father[0]);
            father[0].Mutate();
            Assert.IsTrue(father[0]);
            mother[1].Mutate();

            child = father.Recombine(mother, recombinator);
            Assert.IsTrue(child[0].Equals(father[0]) && child[1].Equals(mother[1]), "Variable recombination not correct!");
        }
开发者ID:ningboliuwei,项目名称:Genetic-Algorithms,代码行数:24,代码来源:GeneticAlgorithmsTest.cs


注:本文中的Chromosome.Recombine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。