SelectionAlgorithm |
Selection is the stage of a genetic algorithm in which individual genomes are chosen from a population for later breeding (recombination or crossover).
SelectionAlgorithmT is an abstract class that derives basic selection techniques for picking the individuals from the population based on randomness and/or fitness.
This topic contains the following sections:
Each selection algorithm implementation involves the following methods:
Method | Description | Performance |
---|---|---|
new generation | Sets the population and its fitness arrays and the amount of individuals involved in selection. Algorithm should return individuals from range [0, selectionAmount-1]. | |
select | After that the Select method is called. It selects one individual: NewGeneration(T, Double, Int32) There is also a method that calls the above described method twice by default and selects two parents for crossover: |
Uniform selection chooses each individual with equal probability.
The following constructor is used to initialize an instance of UniformSelectionT algorithm:
UniformSelectionT(RandomGenerator)
Method | Description | Performance |
---|---|---|
new generation | This method is called by genetic algorithm one time per generation before selection occurs. | |
select | This method is called each time genetic algorithm needs a parent for crossover. |
Roulette selection procedure is implemented as follows:
The fitness function is scaled for each individual
The area of the section of the wheel corresponding to an individual is proportional to the individual's scaled fitness.
The algorithm uses a random number to select one of the sections with a probability equal to its area.
The following constructor is used to initialize an instance of RouletteSelectionT algorithm:
RouletteSelectionT(RandomGenerator)
Method | Description | Performance |
---|---|---|
new generation | This method is called by genetic algorithm one time per generation before selection occurs. | |
select | This method is called each time genetic algorithm needs a parent for crossover. |
Stochastic Uniform selection procedure is implemented as follows:
The fitness function is scaled for each individual
Each parent corresponds to a section of the line of length proportional to its scaled value.
A random step size is chosen.
The algorithm moves along the line in steps of equal size. At each step, the algorithm allocates a parent from the section it lands on.
The following constructor is used to initialize an instance of StochasticUniformSelectionT algorithm:
StochasticUniformSelectionT(RandomGenerator)
Method | Description | Performance |
---|---|---|
new generation | This method is called by genetic algorithm one time per generation before selection occurs. | |
select | This method is called each time genetic algorithm needs a parent for crossover. |
Tournament selection procedure is implemented as follows:
A number of individuals equal to size of tournament is chosen at random.
The best individual out of that set is chosen to be a parent.
The following constructor is used to initialize an instance of TournamentSelectionT algorithm:
TournamentSelectionT(RandomGenerator, Int32, Int32)
Method | Description | Performance |
---|---|---|
new generation | This method is called by genetic algorithm one time per generation before selection occurs. | |
select | This method is called each time genetic algorithm needs a parent for crossover. |
This section presents an example that shows how to create a custom selection algorithm for the genetic algorithm. The created customSelection chooses the best individual out of the set using tournament selection.
1// Initialize random generator which is used during selection process. 2RandomGenerator r = new RandomGenerator(RandomGeneratorType.MCG31); 3 4// Initialize new selection algorithm class instance. 5SelectionAlgorithm<RastriginFunction> customSelection = new TournamentSelection<RastriginFunction>(r, 10, 10); 6 7ga.SelectionAlgorithm = customSelection;