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


C# ICell.GetTagByIndex方法代码示例

本文整理汇总了C#中ICell.GetTagByIndex方法的典型用法代码示例。如果您正苦于以下问题:C# ICell.GetTagByIndex方法的具体用法?C# ICell.GetTagByIndex怎么用?C# ICell.GetTagByIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICell的用法示例。


在下文中一共展示了ICell.GetTagByIndex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Mutate

        /// <summary>
        /// Perform a single point crossover.
        /// </summary>
        public static void Mutate(ICell cell)
        {
            if (cell == null) throw new ArgumentNullException("cell");

            // Iterate the tags and the resources within the tags
            for (int i = 0; i < cell.ActiveTagsInModel; i++)
            {
                // Potentially modify existing tag resources
                Tag activeTag = cell.GetTagByIndex(i);
                for (int j = 0; j < activeTag.Data.Count; j++)
                {
                    if (ShouldMutateThisPoint())
                    {
                        activeTag.Data[j] = Resource.Random(true);
                    }
                }

                // Potentially add a resource
                if (activeTag.Data.Count < Tag.MaxSize && ShouldMutateThisPoint())
                {
                    int insertionIndex = RandomProvider.Next(0, activeTag.Data.Count);
                    activeTag.Data.Insert(insertionIndex, Resource.Random(true));
                }

                // Potentially remove a resource
                if (activeTag.Data.Count > 2 && ShouldMutateThisPoint())
                {
                    activeTag.Data.RemoveRandom();
                }
            }
        }
开发者ID:andrewanderson,项目名称:Web-Critters,代码行数:34,代码来源:PointMutation.cs

示例2: Reproduce

        /// <summary>
        /// Perform a multi-point crossover.
        /// </summary>
        protected override IList<ICell> Reproduce(ICell actor, ICell target)
        {
            if (actor == null) throw new ArgumentNullException("actor");
            if (target == null) throw new ArgumentNullException("target");

            // Percentage of each tag crossing over is normalized to produce one
            // cross on average by default.  This is modified by the CrossoverFactor.
            int crossoverPercent = (int) (100 / actor.ActiveTagsInModel * CrossoverFactor);

            ICell child1 = actor.CreateEmptyCell();
            ICell child2 = actor.CreateEmptyCell();

            for (int i = 0; i < actor.ActiveTagsInModel; i++)
            {
                if (RandomProvider.Next(100) < crossoverPercent)
                {
                    Tag actorTag = actor.GetTagByIndex(i);
                    Tag targetTag = target.GetTagByIndex(i);

                    Tag childTag1 = null;
                    Tag childTag2 = null;

                    CrossoverInteraction.CrossOverTags(actorTag, targetTag, out childTag1, out childTag2);

                    child1.SetTagByIndex(i, childTag1);
                    child2.SetTagByIndex(i, childTag2);
                }
                else
                {
                    child1.SetTagByIndex(i, Tag.New(actor.GetTagByIndex(i)));
                    child2.SetTagByIndex(i, Tag.New(target.GetTagByIndex(i)));
                }
            }

            if (AllowMutation)
            {
                PointMutation.Mutate(child1);
                PointMutation.Mutate(child1);
            }

            return new List<ICell>() { child1, child2 };
        }
开发者ID:andrewanderson,项目名称:Web-Critters,代码行数:45,代码来源:MultipointCrossoverInteraction.cs

示例3: Reproduce

        /// <summary>
        /// Perform a single point crossover.
        /// </summary>
        protected override IList<ICell> Reproduce(ICell actor, ICell target)
        {
            if (actor == null) throw new ArgumentNullException("actor");
            if (target == null) throw new ArgumentNullException("target");

            // Select the tag to crossover
            int crossoverIndex = RandomProvider.Next(0, actor.ActiveTagsInModel - 1);

            // Create two new cells like this (assuming crossover in tag 3):
            //
            // AAAA AAAA AATT TTTT
            // TTTT TTTT TTAA AAAA

            ICell child1 = actor.CreateEmptyCell();
            ICell child2 = actor.CreateEmptyCell();

            for (int i = 0; i < actor.ActiveTagsInModel; i++)
            {
                if (i < crossoverIndex)
                {
                    child1.SetTagByIndex(i, Tag.New(actor.GetTagByIndex(i)));
                    child2.SetTagByIndex(i, Tag.New(target.GetTagByIndex(i)));
                }
                else if (i > crossoverIndex)
                {
                    child1.SetTagByIndex(i, Tag.New(target.GetTagByIndex(i)));
                    child2.SetTagByIndex(i, Tag.New(actor.GetTagByIndex(i)));
                }
                else // i == crossoverIndex
                {
                    // There are length+1 crossover points for a Tag (start, end, length-1 midpoints)
                    Tag actorTag = actor.GetTagByIndex(i);
                    Tag targetTag = target.GetTagByIndex(i);

                    Tag childTag1 = null;
                    Tag childTag2 = null;

                    CrossOverTags(actorTag, targetTag, out childTag1, out childTag2);

                    child1.SetTagByIndex(i, childTag1);
                    child2.SetTagByIndex(i, childTag2);
                }
            }

            if (AllowMutation)
            {
                PointMutation.Mutate(child1);
                PointMutation.Mutate(child1);
            }

            return new List<ICell>() {child1, child2};
        }
开发者ID:andrewanderson,项目名称:Web-Critters,代码行数:55,代码来源:CrossoverInteraction.cs


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