Class TruncationSelection
- java.lang.Object
-
- org.uncommons.watchmaker.framework.selection.TruncationSelection
-
- All Implemented Interfaces:
SelectionStrategy<Object>
public class TruncationSelection extends Object implements SelectionStrategy<Object>
Implements selection of n candidates from a population by simply selecting the n candidates with the highest fitness scores (the rest are discarded). A candidate is never selected more than once.
-
-
Constructor Summary
Constructors Constructor Description TruncationSelection(double selectionRatio)
TruncationSelection(NumberGenerator<Double> selectionRatio)
Creates a truncation selection strategy that is controlled by the variable selection ratio provided by the specifiedNumberGenerator
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <S> List<S>
select(List<EvaluatedCandidate<S>> population, boolean naturalFitnessScores, int selectionSize, Random rng)
Selects the fittest candidates.String
toString()
-
-
-
Constructor Detail
-
TruncationSelection
public TruncationSelection(NumberGenerator<Double> selectionRatio)
Creates a truncation selection strategy that is controlled by the variable selection ratio provided by the specifiedNumberGenerator
.- Parameters:
selectionRatio
- A number generator that produces values in the range 0 < r < 1. These values are used to determine the proportion of the population that is retained in any given selection.
-
TruncationSelection
public TruncationSelection(double selectionRatio)
- Parameters:
selectionRatio
- The proportion of the highest ranked candidates to select from the population. The value must be positive and less than 1.
-
-
Method Detail
-
select
public <S> List<S> select(List<EvaluatedCandidate<S>> population, boolean naturalFitnessScores, int selectionSize, Random rng)
Selects the fittest candidates. If the selectionRatio results in fewer selected candidates than required, then these candidates are selected multiple times to make up the shortfall.- Specified by:
select
in interfaceSelectionStrategy<Object>
- Type Parameters:
S
- The type of evolved entity that is being selected.- Parameters:
population
- The population of evolved and evaluated candidates from which to select.naturalFitnessScores
- Whether higher fitness values represent fitter individuals or not.selectionSize
- The number of candidates to select from the evolved population.rng
- A source of randomness (not used by this selection implementation since truncation selection is deterministic).- Returns:
- The selected candidates.
-
-