Package io.jenetics

Class TournamentSelector<G extends Gene<?,G>,C extends Comparable<? super C>>

java.lang.Object
io.jenetics.TournamentSelector<G,C>
All Implemented Interfaces:
Selector<G,C>

public class TournamentSelector<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements Selector<G,C>
In tournament selection the best individual from a random sample of s individuals is chosen from the population Pg. The samples are drawn with replacement. An individual will win a tournament only if its fitness is greater than the fitness of the other s-1 competitors. Note that the worst individual never survives, and the best individual wins in all the tournaments it participates. The selection pressure can be varied by changing the tournament size s . For large values of s, weak individuals have less chance being selected.
Since:
1.0
Version:
6.0
See Also:
  • Constructor Details

    • TournamentSelector

      public TournamentSelector(Comparator<? super Phenotype<G,C>> comparator, int sampleSize)
      Create a tournament selector with the give comparator and sample size. The sample size must be greater than one.
      Parameters:
      comparator - the comparator use for comparing two individuals during a tournament
      sampleSize - the number of individuals involved in one tournament
      Throws:
      IllegalArgumentException - if the sample size is smaller than two
      NullPointerException - if the given comparator is null
      Since:
      6.0
    • TournamentSelector

      public TournamentSelector(int sampleSize)
      Create a tournament selector with the give sample size. The sample size must be greater than one.
      Parameters:
      sampleSize - the number of individuals involved in one tournament
      Throws:
      IllegalArgumentException - if the sample size is smaller than two.
    • TournamentSelector

      Create a tournament selector with sample size two.
  • Method Details

    • sampleSize

      public int sampleSize()
      Return the sample size of the tournament selector.
      Returns:
      the sample size of the tournament selector
      Since:
      5.0
    • select

      public ISeq<Phenotype<G,C>> select(Seq<Phenotype<G,C>> population, int count, Optimize opt)
      Description copied from interface: Selector
      Select phenotypes from the Population.
      Specified by:
      select in interface Selector<G extends Gene<?,G>,C extends Comparable<? super C>>
      Parameters:
      population - The population to select from.
      count - The number of phenotypes to select.
      opt - Determines whether the individuals with higher fitness values or lower fitness values must be selected. This parameter determines whether the GA maximizes or minimizes the fitness function.
      Returns:
      The selected phenotypes (a new Population).
    • toString

      public String toString()
      Overrides:
      toString in class Object