Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#TOO_LARGE_TOURNAMENT_ARITY

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#TOO_LARGE_TOURNAMENT_ARITY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TournamentSelection.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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) {
        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();
}
 
Example 2
Source File: TournamentSelection.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 choosen.
 * @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) {
        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();
}
 
Example 3
Source File: TournamentSelection.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 choosen.
 * @return the selected chromosome.
 * @throws MathIllegalArgumentException if the tournament arity is bigger than the
 * population size
 */
private Chromosome tournament(final ListPopulation population) {
    if (population.getPopulationSize() < this.arity) {
        throw new MathIllegalArgumentException(LocalizedFormats.TOO_LARGE_TOURNAMENT_ARITY,
                                               arity, population.getPopulationSize());
    }
    // auxiliary population
    ListPopulation tournamentPopulation = new ListPopulation(this.arity) {
        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();
}
 
Example 4
Source File: TournamentSelection.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 choosen.
 * @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) {
        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();
}
 
Example 5
Source File: TournamentSelection.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 choosen.
 * @return the selected chromosome.
 * @throws MathIllegalArgumentException if the tournament arity is bigger than the
 * population size
 */
private Chromosome tournament(final ListPopulation population) {
    if (population.getPopulationSize() < this.arity) {
        throw new MathIllegalArgumentException(LocalizedFormats.TOO_LARGE_TOURNAMENT_ARITY,
                                               arity, population.getPopulationSize());
    }
    // auxiliary population
    ListPopulation tournamentPopulation = new ListPopulation(this.arity) {
        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();
}
 
Example 6
Source File: TournamentSelection.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 choosen.
 * @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) {
        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();
}
 
Example 7
Source File: TournamentSelection.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 choosen.
 * @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) {
        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();
}
 
Example 8
Source File: TournamentSelection.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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) {
        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();
}