Remove some not used namespace declarations.
[genetic.git] / include / 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 namespace genetic {
9 //     namespace selection {
10         /**
11          * Base Selection template class. It should be a base class for any
12          * custom selection functions.
13          */
14         template < typename _Chromosome >
15         class Selection {
16         public:
17             /**
18              * Type representing Fitness function
19              */
20             typedef Fitness<_Chromosome> GeneticFitness;
21
22             /**
23              * Value type returned by the Fitness function
24              */
25             typedef typename GeneticFitness::ValueType FitnessValueType;
26         protected:
27             /**
28              * Generation over which the Selection will be applied
29              */
30             Generation<_Chromosome> generation;
31
32             /**
33              * Fitness which will be used in selection
34              */
35             GeneticFitness& fitness;
36
37             /**
38              * Checks Fitness for the given Chromosome
39              *
40              * @param chromosome Chromosome for which the selection fitness is
41              *      checked.
42              * @return Value of the Fitness function
43              */
44             FitnessValueType checkChromosomeFitness(const _Chromosome& chromosome) {
45                 this->fitness.chromosome = chromosome;
46                 return fitness.calculate();
47             }
48
49             /**
50              * Selection calculations should be done here.
51              *
52              * @return new Generation of Chromosome's that passed the Selection
53              */
54             virtual Generation<_Chromosome> do_draw() = 0;
55
56         public:
57             /**
58              * Class constructor. Initializes required variables and constants
59              *
60              * @param _generation Generation over which the Selection will be
61              *      applied
62              * @param _fitness Fitness function to use in Selection
63              */
64             Selection(const Generation<_Chromosome>& _generation, GeneticFitness& _fitness) :
65                 generation(_generation), fitness(_fitness) {
66             }
67
68             /**
69              * Invokes Selection calculations
70              *
71              * @return new Generation of Chromosome's that passed the Selection
72              */
73             Generation<_Chromosome> draw() {
74                 return this->do_draw();
75             }
76         };
77 //     }
78 }
79
80 #endif /* __SELECTION_SELECTION_H */