Finished Roulette Selection.
[genetic.git] / src / selection / selection.h
1 #ifndef __SELECTION_SELECTION_H
2 #define __SELECTION_SELECTION_H
3
4 #include "chromosome.h"
5 #include "generation.h"
6 #include "../fitness/fitness.h"
7
8 using namespace std;
9
10 namespace genetic {
11 //     namespace selection {
12         template < typename _Chromosome >
13         class Selection {
14         public:
15             typedef Fitness<_Chromosome> GeneticFitness;
16             typedef typename GeneticFitness::ValueType FitnessValueType;
17         protected:
18             Generation<_Chromosome> generation;
19             GeneticFitness& fitness;
20             
21             FitnessValueType checkChromosomeFitness(_Chromosome chromosome) {
22                 this->fitness.chromosome = chromosome;
23                 return fitness.calculate();
24             }
25
26             virtual Generation<_Chromosome> do_draw() = 0;
27
28         public:
29             Selection(Generation<_Chromosome> _generation, GeneticFitness& _fitness) :
30                 generation(_generation), fitness(_fitness) {
31             }
32
33             Generation<_Chromosome> draw() {
34                 return this->do_draw();
35             }
36         };
37 //     }
38 }
39
40 #endif /* __SELECTION_SELECTION_H */