本文整理汇总了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!");
}
示例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);
}
示例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!");
}