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


C# IChromosome.Clone方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:jbrant,项目名称:SharpNoveltyNeat,代码行数:44,代码来源:QueuePopulation.cs

示例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;
     }
 }
开发者ID:rob86,项目名称:genetic-algorithms,代码行数:16,代码来源:Population.cs


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