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


C# IChromosome.GetGene方法代码示例

本文整理汇总了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;
        }
开发者ID:denmerc,项目名称:GeneticSharp,代码行数:9,代码来源:Issue1Fitness.cs

示例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);
            }
        }
开发者ID:joaokucera,项目名称:GeneticSharp,代码行数:19,代码来源:TworsMutation.cs

示例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;
        }
开发者ID:mahmoud-samy-symbyo,项目名称:GeneticSharp,代码行数:21,代码来源:BitmapEqualityFitness.cs

示例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;
        }
开发者ID:denmerc,项目名称:GeneticSharp,代码行数:31,代码来源:OrderedCrossover.cs


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