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


C# Engine.NextGeneration方法代码示例

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


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

示例1: ThreeAliveCellsRotate

        public void ThreeAliveCellsRotate()
        {
            var p11 = new CartesianPosition(1, 1);
            var p12 = new CartesianPosition(1, 2);
            var p13 = new CartesianPosition(1, 3);

            var stateHolder = new StateHolder();
            stateHolder.SetState(p11, new Alive());
            stateHolder.SetState(p12, new Alive());
            stateHolder.SetState(p13, new Alive());

            var engine = new Engine<CartesianPosition>(stateHolder, new CartesianSpaceLimits());
            var secondGeneration = engine.NextGeneration();
            Assert.Equal(new Dead(), secondGeneration.GetState(p11));
            Assert.Equal(new Alive(), secondGeneration.GetState(p12));
            Assert.Equal(new Dead(), secondGeneration.GetState(p13));

            var thirdGeneration = engine.NextGeneration();
            Assert.Equal(new Alive(), thirdGeneration.GetState(p11));
            Assert.Equal(new Alive(), thirdGeneration.GetState(p12));
            Assert.Equal(new Alive(), thirdGeneration.GetState(p13));
        }
开发者ID:tristanles,项目名称:gameoflife-calisthenics-csharp,代码行数:22,代码来源:AcceptanceTests.cs

示例2: EasyGaTest

        public void EasyGaTest()
        {
            MultipointCrossover<ListGenotype<BitGene>, BitGene, double> crossover =
                new MultipointCrossover<ListGenotype<BitGene>, BitGene, double>(1);

            EasyGa<ListGenotype<BitGene>, double> algorithm =
                new EasyGa<ListGenotype<BitGene>, double>.Builder()
                    .WithElitismPercentage(0.5)
                    .WithFitnessFunction(g => g.Count(b => b.Value))
                    .WithStopCriteria(
                        StopCriteriaBuilder.StopAtGeneration<ListGenotype<BitGene>, double>(2500)
                            .Or(StopCriteriaBuilder.StopAtFitness<ListGenotype<BitGene>, double>(20)))
                    .RegisterBreeder(new BitBreeder(20, 20))
                    .Register(new RouletteWheelSelector<ListGenotype<BitGene>>(20))
                    .Register(new Recombinator<ListGenotype<BitGene>, double>(crossover, 2, 10,
                        Recombinator<ListGenotype<BitGene>, double>.RecombinatioNumberType.Absolute))
                    .Register(new BitBaseMutator<ListGenotype<BitGene>, double>(0.05))
                    .Build();

            Engine<ListGenotype<BitGene>, double> engine = new Engine<ListGenotype<BitGene>, double>.Builder()
                .WithAlgorithm(algorithm)
                .Build();

            while (!engine.HasReachedStopCriteria)
            {
                //if (engine.World != null)
                //{
                //    TestContext.WriteLine($"Generation {engine.World.Generation} (Size: {engine.World.Population.Count})");
                //    foreach (Individual<ListGenotype<BitGene>, double> individual in engine.World.Population)
                //    {
                //        TestContext.WriteLine(individual);
                //    }
                //}
                engine.NextGeneration();
            }

            TestContext.WriteLine($"{engine.CurrentWorld.Generation} generations reached");
            TestContext.WriteLine($"{engine.Statistics.BestIndividualGeneration} is best indivual's generation");
            TestContext.WriteLine($"{engine.Statistics.BestFitness} is best Fitness");
            TestContext.WriteLine($"{engine.Statistics.BestGenotype} is best Genotype");
        }
开发者ID:bgarate,项目名称:Evolution,代码行数:41,代码来源:GaTest.cs

示例3: FourAliveCellsStayAlive

        public void FourAliveCellsStayAlive()
        {
            var p00 = new CartesianPosition(0, 0);
            var p01 = new CartesianPosition(0, 1);
            var p11 = new CartesianPosition(1, 1);
            var p10 = new CartesianPosition(1, 0);

            var stateHolder = new StateHolder();
            stateHolder.SetState(p00, new Alive());
            stateHolder.SetState(p01, new Alive());
            stateHolder.SetState(p11, new Alive());
            stateHolder.SetState(p10, new Alive());

            var engine = new Engine<CartesianPosition>(stateHolder, new CartesianSpaceLimits());
            var secondGeneration = engine.NextGeneration();

            Assert.Equal(new Alive(), stateHolder.GetState(p00));
            Assert.Equal(new Alive(), stateHolder.GetState(p01));
            Assert.Equal(new Alive(), stateHolder.GetState(p11));
            Assert.Equal(new Alive(), stateHolder.GetState(p10));
        }
开发者ID:tristanles,项目名称:gameoflife-calisthenics-csharp,代码行数:21,代码来源:AcceptanceTests.cs


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