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


C# Population.ElementAt方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            const int replayLength = 750;
            //IReplayGenerator replayGenerator = new FromStringReplay("AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA A");
            IReplayGenerator replayGenerator = new RandomReplayGenerator(new ReplayCharacterSet(), replayLength);

            var game = new Game();
            if (!HandleCommandLineArgs(game, args))
            {
                ShowHelp(options);
                return;
            }

            Console.WriteLine("Mutation Rate: {0}%", mutationRate * 100);
            Console.WriteLine("Crossover Rate: {0}%", crossoverRate * 100);
            Console.WriteLine("Truncation Rate: {0}%", truncationRate * 100);
            Console.WriteLine("Chromosomes / population: {0}", chromosomeCount);
            Console.WriteLine("Elitism / population: {0} ({1}%)", elitismRate * chromosomeCount, elitismRate);
            Console.WriteLine("Fitness Calculator: {0}", fitness);
            Console.WriteLine("Crossover Type: {0}", crossover);
            Console.WriteLine();

            //game.Start(new Replay("AAAA A00A AAAA AAAA AAA2 8000 AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA"));
            var fitnessCalculator = new HighestScoreFitnessCalculator(game);

            var ga = new GeneticAlgorithm(0.6, 0.25, 0.1, 0.8, chromosomeCount,
                new RouletteWheelSelection(),
                new OnePointCrossover(fitnessCalculator),
                new SinglePointMutation(new ReplayCharacterSet(),fitnessCalculator),
                fitnessCalculator);

            Console.WriteLine(DateTime.Now);
            Population population = new Population(GenerateRandomReplays(replayGenerator, chromosomeCount), fitnessCalculator);
            int generation = 1;
            while(true)
            {
                var bestOne = population.ElementAt(0);

                Console.WriteLine("Generation {0}", generation++);
                Console.WriteLine("Top fitness: {0}", bestOne.Fitness);
                Console.WriteLine("Replay: {0}\n", bestOne.Replay);

                population = ga.AdvancePopulation(population);
            }
        }
开发者ID:dreasgrech,项目名称:HATETRIS-GA,代码行数:45,代码来源:Program.cs


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