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 it's strength in fast selecting individuals in large populations, but is not very often used in practice.- Since:
- 1.0
- Version:
- 5.0
- Author:
- Franz Wilhelmstötter
- See Also:
- Wikipedia: Truncation selection
-
-
Constructor Summary
Constructors Constructor Description TruncationSelector()
Create a new TruncationSelector object.TruncationSelector(int n)
Create a newTruncationSelector
object, where the worst selected individual has rankn
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.String
toString()
-
-
-
Constructor Detail
-
TruncationSelector
public TruncationSelector(int n)
Create a newTruncationSelector
object, where the worst selected individual has rankn
. This means, if you want to selectcount
individuals, the worst selected individual has rankn
. Ifcount > n
, the selected population will contain duplicate individuals.- Parameters:
n
- the worst rank of the selected individuals- Throws:
IllegalArgumentException
- ifn < 1
- Since:
- 3.8
-
TruncationSelector
public TruncationSelector()
Create a new TruncationSelector object.
-
-
Method Detail
-
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 the population size, the whole population is duplicated until the desired sample size is reached.- Specified by:
select
in interfaceSelector<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 thepopulation
oropt
isnull
.
-
-