Bigger values for testing results.
[genetic.git] / include / fitness / fitness.h
1 #ifndef __FITNESS_FITNESS_H
2 #define __FITNESS_FITNESS_H
3
4 #include <map>
5 #include <string>
6
7 #include "chromosome.h"
8
9 namespace genetic {
10     /**
11      * Base Fitness template class. It should be a base class for any custom
12      * fitness functions.
13      */
14     template < typename _Chromosome, typename _Value = double >
15     class Fitness {
16         template<typename> friend class Selection;
17     public:
18         /**
19          * Type representing Chromosome Gene
20          */
21         typedef typename _Chromosome::GeneType GeneType;
22
23         /**
24          * Value type returned by the Fitness function
25          */
26         typedef _Value ValueType;
27     protected:
28         /**
29          * Chromosome on which calculations are made
30          */
31         _Chromosome chromosome;
32
33         /**
34          * Calculations should be done here...
35          *
36          * @return Fitness value of the current Chromosome
37          */
38         virtual _Value do_calculate() = 0;
39
40     public:
41         /**
42          * Class constructor
43          */
44         Fitness() {}
45
46         /**
47          * Copy constructor
48          */
49         Fitness(_Chromosome& _chromosome)
50             : chromosome(_chromosome) {
51         }
52
53         /**
54          * Invokes calculations
55          *
56          * @return Fitness value of the current Chromosome
57          */
58         _Value calculate() {
59             return this->do_calculate();
60         }
61
62         /**
63          * Method used to pass additional arguments needed by the function to
64          * run correctly.
65          */
66         virtual void parseArguments(std::map<string, string>) { }
67
68         /**
69          * Method used to get additional arguments needed by the function to
70          * run correctly
71          *
72          * @return map containing additional arguments, empty if do not use any
73          */
74         virtual std::map<string, string> getArguments() {
75             return std::map<string, string>();
76         }
77     };
78 }
79
80 #endif /* __FITNESS_FITNESS_H */