Package io.jenetics

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

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

public final class TruncationSelector<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements Selector<G,C>
In truncation selection, individuals are sorted according to their fitness. Only the n best individuals are selected. The truncation selection is a very basic selection algorithm. It has its strength in fast selecting individuals in large populations, but is seldom used in practice.
Since:
1.0
Version:
5.0
See Also:
  • Constructor Details

    • TruncationSelector

      public TruncationSelector(int n)
      Create a new TruncationSelector object, where the worst selected individual has rank n. This means, if you want to select count individuals, the worst selected individual has rank n. If count > n, the selected population will contain duplicate individuals.
      Parameters:
      n - the worst rank of the selected individuals
      Throws:
      IllegalArgumentException - if n < 1
      Since:
      3.8
    • TruncationSelector

      Create a new TruncationSelector object.
  • Method Details

    • select

      public ISeq<Phenotype<G,C>> select(Seq<Phenotype<G,C>> population, int count, Optimize opt)
      This method sorts the population in descending order while calculating the selection probabilities. If the selection size is greater the population size, the whole population is duplicated until the desired sample size is reached.
      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).
      Throws:
      NullPointerException - if the population or opt is null.
    • toString

      public String toString()
      Overrides:
      toString in class Object