Improve comments and documentation.
[genetic.git] / src / fitness / fitness.h
1 #ifndef __FITNESS_FITNESS_H
2 #define __FITNESS_FITNESS_H
3
4 #include "chromosome.h"
5
6 namespace genetic {
7     /**
8      * Base Fitness template class. It should be a base class for any custom
9      * fitness functions.
10      */
11     template < typename _Chromosome, typename _Value = double >
12     class Fitness {
13         template<typename> friend class Selection;
14     public:
15         /**
16          * Type representing Chromosome Gene
17          */
18         typedef typename _Chromosome::GeneType GeneType;
19
20         /**
21          * Value type returned by the Fitness function
22          */
23         typedef _Value ValueType;
24     protected:
25         /**
26          * Chromosome on which calculations are made
27          */
28         _Chromosome chromosome;
29
30         /**
31          * Calculations should be done here...
32          *
33          * @return Fitness value of the current Chromosome
34          */
35         virtual _Value do_calculate() = 0;
36
37     public:
38         /**
39          * Class constructor
40          */
41         Fitness() {}
42
43         /**
44          * Copy constructor
45          */
46         Fitness(_Chromosome& _chromosome)
47             : chromosome(_chromosome.get()) {
48         }
49
50         /**
51          * Invokes calculations
52          *
53          * @return Fitness value of the current Chromosome
54          */
55         _Value calculate() {
56             return this->do_calculate();
57         }
58     };
59 }
60
61 #endif /* __FITNESS_FITNESS_H */