Module io.jenetics.base
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 Summary
ConstructorDescriptionCreate a new TruncationSelector object.TruncationSelector
(int n) Create a newTruncationSelector
object, where the worst selected individual has rankn
. -
Method Summary
-
Constructor Details
-
TruncationSelector
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 Details
-
select
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 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
.
-
toString
-