1 #ifndef __SELECTION_SELECTION_H
2 #define __SELECTION_SELECTION_H
4 #include "chromosome.h"
5 #include "generation.h"
6 #include "../fitness/fitness.h"
9 // namespace selection {
11 * Base Selection template class. It should be a base class for any
12 * custom selection functions.
14 template < typename _Chromosome >
18 * Type representing Fitness function
20 typedef Fitness<_Chromosome> GeneticFitness;
23 * Value type returned by the Fitness function
25 typedef typename GeneticFitness::ValueType FitnessValueType;
28 * Generation over which the Selection will be applied
30 Generation<_Chromosome> generation;
33 * Fitness which will be used in selection
35 GeneticFitness& fitness;
38 * Checks Fitness for the given Chromosome
40 * @param chromosome Chromosome for which the selection fitness is
42 * @return Value of the Fitness function
44 FitnessValueType checkChromosomeFitness(const _Chromosome& chromosome) {
45 this->fitness.chromosome = chromosome;
46 return fitness.calculate();
50 * Selection calculations should be done here.
52 * @return new Generation of Chromosome's that passed the Selection
54 virtual Generation<_Chromosome> do_draw() = 0;
58 * Class constructor. Initializes required variables and constants
60 * @param _generation Generation over which the Selection will be
62 * @param _fitness Fitness function to use in Selection
64 Selection(const Generation<_Chromosome>& _generation, GeneticFitness& _fitness) :
65 generation(_generation), fitness(_fitness) {
69 * Invokes Selection calculations
71 * @return new Generation of Chromosome's that passed the Selection
73 Generation<_Chromosome> draw() {
74 return this->do_draw();
80 #endif /* __SELECTION_SELECTION_H */