本文整理汇总了C#中IChromosome.GetGene方法的典型用法代码示例。如果您正苦于以下问题:C# IChromosome.GetGene方法的具体用法?C# IChromosome.GetGene怎么用?C# IChromosome.GetGene使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IChromosome
的用法示例。
在下文中一共展示了IChromosome.GetGene方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
public double Evaluate(IChromosome chromosome)
{
double n = 9;
var x = (int)chromosome.GetGene(0).Value;
var y = (int)chromosome.GetGene(1).Value;
double f1 = System.Math.Pow(15 * x * y * (1 - x) * (1 - y) * System.Math.Sin(n * System.Math.PI * x) * System.Math.Sin(n * System.Math.PI * y), 2);
return f1;
}
示例2: PerformMutate
/// <summary>
/// Mutate the specified chromosome.
/// </summary>
/// <param name="chromosome">The chromosome.</param>
/// <param name="probability">The probability to mutate each chromosome.</param>
protected override void PerformMutate(IChromosome chromosome, float probability)
{
if (RandomizationProvider.Current.GetDouble() <= probability)
{
var indexes = RandomizationProvider.Current.GetUniqueInts(2, 0, chromosome.Length);
var firstIndex = indexes[0];
var secondIndex = indexes[1];
var firstGene = chromosome.GetGene(firstIndex);
var secondGene = chromosome.GetGene(secondIndex);
chromosome.ReplaceGene(firstIndex, secondGene);
chromosome.ReplaceGene(secondIndex, firstGene);
}
}
示例3: Evaluate
/// <summary>
/// Evaluates the specified chromosome.
/// </summary>
/// <param name="chromosome">The chromosome.</param>
/// <returns>The chromosome fitness.</returns>
public double Evaluate(IChromosome chromosome)
{
double fitness = 0;
for (int i = 0; i < m_pixelsCount; i++)
{
var targetPixel = m_targetBitmapPixels[i];
var chromosomePixel = (Color)chromosome.GetGene(i).Value;
fitness -= Math.Abs(targetPixel.R - chromosomePixel.R);
fitness -= Math.Abs(targetPixel.G - chromosomePixel.G);
fitness -= Math.Abs(targetPixel.B - chromosomePixel.B);
}
return fitness;
}
示例4: CreateChild
/// <summary>
/// Creates the child.
/// </summary>
/// <returns>The child.</returns>
/// <param name="firstParent">First parent.</param>
/// <param name="secondParent">Second parent.</param>
/// <param name="middleSectionBeginIndex">Middle section begin index.</param>
/// <param name="middleSectionEndIndex">Middle section end index.</param>
private static IChromosome CreateChild(IChromosome firstParent, IChromosome secondParent, int middleSectionBeginIndex, int middleSectionEndIndex)
{
var middleSectionGenes = firstParent.GetGenes().Skip(middleSectionBeginIndex).Take((middleSectionEndIndex - middleSectionBeginIndex) + 1);
var secondParentRemainingGenes = secondParent.GetGenes().Except(middleSectionGenes).GetEnumerator();
var child = firstParent.CreateNew();
for (int i = 0; i < firstParent.Length; i++)
{
var firstParentGene = firstParent.GetGene(i);
if (i >= middleSectionBeginIndex && i <= middleSectionEndIndex)
{
child.ReplaceGene(i, firstParentGene);
}
else
{
secondParentRemainingGenes.MoveNext();
child.ReplaceGene(i, secondParentRemainingGenes.Current);
}
}
return child;
}