本文整理汇总了C#中IChromosome.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# IChromosome.Clone方法的具体用法?C# IChromosome.Clone怎么用?C# IChromosome.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IChromosome
的用法示例。
在下文中一共展示了IChromosome.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueuePopulation
/// <summary>
/// Initializes a new instance of the <see cref="Population"/> class.
/// </summary>
///
/// <param name="size">Initial size of population.</param>
/// <param name="ancestor">Ancestor chromosome to use for population creatioin.</param>
/// <param name="fitnessFunction">Fitness function to use for calculating
/// chromosome's fitness values.</param>
/// <param name="selectionMethod">Selection algorithm to use for selection
/// chromosome's to new generation.</param>
///
/// <remarks>Creates new population of specified size. The specified ancestor
/// becomes first member of the population and is used to create other members
/// with same parameters, which were used for ancestor's creation.</remarks>
///
/// <exception cref="ArgumentException">Too small population's size was specified. The
/// exception is thrown in the case if <paramref name="size"/> is smaller than 2.</exception>
///
public QueuePopulation(int size,
IChromosome ancestor,
IFitnessFunction fitnessFunction,
ISelectionMethod selectionMethod)
{
if (size < 2)
throw new ArgumentException("Too small population's size was specified.");
this.fitnessFunction = fitnessFunction;
this.selectionMethod = selectionMethod;
this.size = size;
// add ancestor to the population
ancestor.Evaluate(fitnessFunction);
population.Add(ancestor.Clone());
// add more chromosomes to the population
for (int i = 1; i < size; i++)
{
// create new chromosome
IChromosome c = ancestor.CreateNew();
// calculate it's fitness
c.Evaluate(fitnessFunction);
// add it to population
population.Add(c);
}
}
示例2: DefaultPopulation
/// <summary>
/// Konstruktor.
/// </summary>
/// <param name="prototype">Osobnik-wzorzec, który będzie kopiowany na potrzeby utworzenia populacji.</param>
/// <param name="initialSize">Początkowy rozmiar populacji.</param>
public DefaultPopulation(IChromosome prototype, UInt32 initialSize)
{
Generation = 0;
Specimens = new IChromosome[initialSize];
for (Int32 i = 0; i < initialSize; ++i)
{
IChromosome chromosome = prototype.Clone();
chromosome.Randomize();
Specimens[i] = chromosome;
}
}