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


Java LocalizedFormats.TOO_LARGE_TOURNAMENT_ARITY属性代码示例

本文整理汇总了Java中org.apache.commons.math3.exception.util.LocalizedFormats.TOO_LARGE_TOURNAMENT_ARITY属性的典型用法代码示例。如果您正苦于以下问题:Java LocalizedFormats.TOO_LARGE_TOURNAMENT_ARITY属性的具体用法?Java LocalizedFormats.TOO_LARGE_TOURNAMENT_ARITY怎么用?Java LocalizedFormats.TOO_LARGE_TOURNAMENT_ARITY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.commons.math3.exception.util.LocalizedFormats的用法示例。


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

示例1: tournament

/**
 * Helper for {@link #select(Population)}. Draw {@link #arity} random chromosomes without replacement from the
 * population, and then select the fittest chromosome among them.
 *
 * @param population the population from which the chromosomes are chosen.
 * @return the selected chromosome.
 * @throws MathIllegalArgumentException if the tournament arity is bigger than the population size
 */
private Chromosome tournament(final ListPopulation population) throws MathIllegalArgumentException {
    if (population.getPopulationSize() < this.arity) {
        throw new MathIllegalArgumentException(LocalizedFormats.TOO_LARGE_TOURNAMENT_ARITY,
                                               arity, population.getPopulationSize());
    }
    // auxiliary population
    ListPopulation tournamentPopulation = new ListPopulation(this.arity) {
        /** {@inheritDoc} */
        public Population nextGeneration() {
            // not useful here
            return null;
        }
    };

    // create a copy of the chromosome list
    List<Chromosome> chromosomes = new ArrayList<Chromosome> (population.getChromosomes());
    for (int i=0; i<this.arity; i++) {
        // select a random individual and add it to the tournament
        int rind = GeneticAlgorithm.getRandomGenerator().nextInt(chromosomes.size());
        tournamentPopulation.addChromosome(chromosomes.get(rind));
        // do not select it again
        chromosomes.remove(rind);
    }
    // the winner takes it all
    return tournamentPopulation.getFittestChromosome();
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:34,代码来源:TournamentSelection.java


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