Module io.jenetics.base
Package io.jenetics
Class EliteSelector<G extends Gene<?,G>,C extends Comparable<? super C>>
java.lang.Object
io.jenetics.EliteSelector<G,C>
- All Implemented Interfaces:
Selector<G,
C>
public class EliteSelector<G extends Gene<?,G>,C extends Comparable<? super C>>
extends Object
implements Selector<G,C>
The
EliteSelector
copies a small proportion of the fittest candidates,
without changes, into the next generation. This may have a dramatic impact on
performance by ensuring that the GA doesn't waste time re-discovering
previously refused partial solutions. Individuals that are preserved through
elitism remain eligible for selection as parents of the next generation.
Elitism is also related to memory: remember the best solution found so far.
A problem with elitism is that it may cause the GA to converge to a local
optimum, so pure elitism is a race to the nearest local optimum.
final Selector<DoubleGene, Double> selector = new EliteSelector<>(
// Number of the best individuals preserved for the next generation: elites
3,
// Selector used for selecting rest of population.
new RouletteWheelSelector<>()
);
- Since:
- 4.0
- Version:
- 5.0
-
Constructor Summary
ConstructorDescriptionCreate a new elite selector with elite count 1, and the selector for selecting the rest of the population is initialized withTournamentSelector<>(3)
EliteSelector
(int eliteCount) Create a new elite selector with the desired number of elites to be selected.EliteSelector
(int eliteCount, Selector<G, C> nonEliteSelector) Create a new elite selector with the desired number of elites to be selected, and the selector used for selecting the rest of the population.EliteSelector
(Selector<G, C> nonEliteSelector) Create a new elite selector with selector used for selecting the rest of the population. -
Method Summary
-
Constructor Details
-
EliteSelector
Create a new elite selector with the desired number of elites to be selected, and the selector used for selecting the rest of the population.- Parameters:
eliteCount
- the desired number of elite individuals to be selectednonEliteSelector
- the selector used for selecting the rest of the population- Throws:
IllegalArgumentException
- ifeliteCount < 1
NullPointerException
- if thenonEliteSelector
isnull
-
EliteSelector
Create a new elite selector with the desired number of elites to be selected. The selector for selecting the rest of the population is initialized withTournamentSelector<>(3)
.- Parameters:
eliteCount
- the desired number of elite individuals to be selected- Throws:
IllegalArgumentException
- ifeliteCount < 1
- See Also:
-
EliteSelector
Create a new elite selector with selector used for selecting the rest of the population. The elite count is set to 1.- Parameters:
nonEliteSelector
- the selector used for selecting the rest of the population- Throws:
NullPointerException
- if thenonEliteSelector
isnull
- See Also:
-
EliteSelector
public EliteSelector()Create a new elite selector with elite count 1, and the selector for selecting the rest of the population is initialized withTournamentSelector<>(3)
-
-
Method Details
-
select
Description copied from interface:Selector
Select phenotypes from the Population.- 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).
-
toString
-