本文整理汇总了C#中IGenome.Decode方法的典型用法代码示例。如果您正苦于以下问题:C# IGenome.Decode方法的具体用法?C# IGenome.Decode怎么用?C# IGenome.Decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGenome
的用法示例。
在下文中一共展示了IGenome.Decode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Mate
/// <summary>
/// Mate two genomes. Will loop over all chromosomes.
/// </summary>
///
/// <param name="father">The father.</param>
/// <param name="child1">The first child.</param>
/// <param name="child2">The second child.</param>
public void Mate(IGenome father, IGenome child1,
IGenome child2)
{
int motherChromosomes = Chromosomes.Count;
int fatherChromosomes = father.Chromosomes.Count;
if (motherChromosomes != fatherChromosomes)
{
throw new GeneticError(
"Mother and father must have same chromosome count, Mother:"
+ motherChromosomes + ",Father:"
+ fatherChromosomes);
}
for (int i = 0; i < fatherChromosomes; i++)
{
Chromosome motherChromosome = _chromosomes[i];
Chromosome fatherChromosome = father.Chromosomes[i];
Chromosome offspring1Chromosome = child1.Chromosomes[i];
Chromosome offspring2Chromosome = child2.Chromosomes[i];
_ga.Crossover.Mate(motherChromosome,
fatherChromosome, offspring1Chromosome,
offspring2Chromosome);
if (ThreadSafeRandom.NextDouble() < _ga.MutationPercent)
{
_ga.Mutate.PerformMutation(
offspring1Chromosome);
}
if (ThreadSafeRandom.NextDouble() < _ga.MutationPercent)
{
_ga.Mutate.PerformMutation(
offspring2Chromosome);
}
}
child1.Decode();
child2.Decode();
_ga.PerformCalculateScore(child1);
_ga.PerformCalculateScore(child2);
}