本文整理汇总了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();
}