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


C# Population.getFittest方法代码示例

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


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

示例1: evolvePopulation

    public static Population evolvePopulation(Population pop)
    {
        Population newPopulation = new Population(pop.size(), false);
        Genome champion = pop.getFittest();

        // Keep our best Genome
        if (elitism)
        {
            newPopulation.saveGenome(0, champion);
        }

        // Crossover population
        int elitismOffset;
        if (elitism)
        {
            elitismOffset = 1;
        }
        else
        {
            elitismOffset = 0;
        }

        // half of the new population is the champion and mutations of him
        int halfPopSize = (int)Mathf.Floor((float) pop.size() / 2);
        tournamentSize = pop.size() - (halfPopSize + 1);

        for (int i = elitismOffset; i < halfPopSize; i++)
        {
            Genome clone = champion.copy();
            mutateGenome(clone);
            newPopulation.saveGenome(i, clone);
        }

        // Loop over the population size and create new genomes with
        for (int i = halfPopSize; i < pop.size(); i++)
        {
            Genome localChampion = tournamentSelection(pop);
            Genome clone = localChampion.copy();
            mutateGenome(clone);
            // Genome newGenome = crossover(genome1, genome2);
            newPopulation.saveGenome(i, clone);
        }

        /*
            // Mutate population
            for (int i = elitismOffset; i < newPopulation.size(); i++) {
                mutate(newPopulation.getGenome(i));
            }
            */

        return newPopulation;
    }
开发者ID:roschly,项目名称:simple-runner-ai,代码行数:52,代码来源:Algorithm.cs

示例2: tournamentSelection

 // Select Genomes for crossover
 private static Genome tournamentSelection(Population pop)
 {
     // Create a tournament population
     Population tournament = new Population(tournamentSize, false);
     // For each place in the tournament get a random Genome
     for (int i = 0; i < tournamentSize; i++)
     {
         int randomId = (int)(Random.value * pop.size());
         tournament.saveGenome(i, pop.getGenome(randomId));
     }
     // Get the fittest
     Genome fittest = tournament.getFittest();
     return fittest;
 }
开发者ID:roschly,项目名称:simple-runner-ai,代码行数:15,代码来源:Algorithm.cs


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