T
- The class of chromosomes to work with.public abstract class Selector<T extends Chromosome> extends Operator<T>
The actual selector is implemented by subclassing this abstract class and providing the select(Population)
and
Selector#preSelect(Population)
method implementations: the former is required to select individuals from
the specified Population
; the latter is required to set up the selector state when a new selection begins.
A maxIllegalRate
is specified to obtain a population with a max number of illegal individuals selected.
When this threshould is reached, the new illegal selected individuals are not added at the output population, and the
selection process is repeated.
At the start selection time the output population has already the individuals; the individuals selected from the input population have not to be added at the output population: each output population individual is set as the one selected by the input population.
The output population size will be equal to the input population one; automatically new individuals are added or old ones are deleted to make the sizes equal.
A Selector.Statistics
is associated to each selector operator.
Individual
,
Population
Modifier and Type | Class and Description |
---|---|
class |
Selector.Statistics
A statistics object holding the number of selection performed and the time spent to execute them.
|
Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_MAX_ILLEGAL_RATE
The default percentage of allowed illegal individuals
|
random, statistics
biggerIsBetter, fitness, ga
Constructor and Description |
---|
Selector()
Constructs a new Selector operator.
|
Selector(int n)
Constructs a new Selector operator, specifying the number of individuals to select.
|
Modifier and Type | Method and Description |
---|---|
double |
getMaxIllegalRate()
Returns the max number of illegal individuals this selector operator can select.
|
int |
getSelectionRate()
Returns the number of individuals selected by this operator.
|
void |
init(GeneticAlgorithm<T> ga)
Initializes this stage according to the genetic algorithm
that uses it
|
protected void |
preSelect(Population<T> pop,
Population.Filter filter)
Sets up the selection state according a population's state.
|
void |
process(Population<T> in,
Population<T> out)
Sets the individuals in the output population like the selected ones
|
protected abstract Individual<T> |
select(java.util.List<Individual<T>> pop)
Selects an individual in the filtered population
|
Individual<T> |
select(Population<T> pop)
Selects an individual in the population
|
void |
setMaxIllegalRate(double rate)
Sets the max number of illegal individuals this selector operator can select.
|
void |
setSelectionRate(int n)
Sets the number of individuals being selected by this operator.
|
getStatistics, updateStatistics
dispose, getFitness, isBiggerBetter, isFitnessChanged, setBiggerIsBetter, setBiggerIsBetter, setFitness, setFitness
public static final double DEFAULT_MAX_ILLEGAL_RATE
public Selector()
public Selector(int n)
n
- the number of individuals to selectpublic final double getMaxIllegalRate()
public void setMaxIllegalRate(double rate)
rate
- the max illegal ratepublic final int getSelectionRate()
public void setSelectionRate(int n)
n
- the number of individuals being selected.public void init(GeneticAlgorithm<T> ga)
AbstractStage
init
in class AbstractStage<T extends Chromosome>
ga
- the Genetic Algorithm in wchic this stage runpublic final void process(Population<T> in, Population<T> out) throws StageException
process
in class AbstractStage<T extends Chromosome>
in
- the input populationout
- the output populationStageException
protected void preSelect(Population<T> pop, Population.Filter filter)
pop
- the population to process by the stagefilter
- protected abstract Individual<T> select(java.util.List<Individual<T>> pop)
pop
- from which to choose an individual.public final Individual<T> select(Population<T> pop)
pop
-