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