1 #ifndef __FITNESS_WSTI_H
2 #define __FITNESS_WSTI_H
14 * Just an example Fitness function based on WSTI version.
16 template <typename _Chromosome, typename _Value = float>
17 class WSTI : public Fitness<_Chromosome, _Value> {
20 * Value of the begining of the Fitness function domain.
21 * By default it is equal to 0.
26 * Value of the end of the Fitness function domain.
27 * By default it is equal to 0.
32 * Calculates fenotype of the current Chromosome
37 unsigned int chromosomeSize = this->chromosome.size();
39 for (unsigned int i = 0; i < chromosomeSize; i++) {
40 _fenotype = _fenotype + this->chromosome[i].get() * ratio;
47 * Calculates fenotype of the current Chromosome
49 _Value calculateFenotype() {
50 const unsigned int power2N = 1 << this->chromosome.size();
51 return span_start + (span_end - span_start) * this->fenotype() / power2N;
55 * Calculates fitness value of the current Chromosome
57 _Value do_calculate() {
58 _Value fenotype = this->calculateFenotype();
59 return (exp(fenotype) * sin(3.1415 * fenotype) + 1) / fenotype;
63 * Class constructor. Initializes class with required values.
65 * @param _chromosome Chromosome, for which value will be calculated
67 WSTI(_Chromosome& _chromosome)
68 : Fitness<_Chromosome>(_chromosome) {
72 * Class constructor. Initializes class with required values.
74 * @param start begining of the Fitness function domain
75 * @param end end of the Fitness function domain
77 WSTI(float start, float end)
78 : span_start(start), span_end(end) {
82 * Class constructor. Initializes class with required values.
84 * @param _chromosome Chromosome, for which value will be calculated
85 * @param start begining of the Fitness function domain
86 * @param end end of the Fitness function domain
88 WSTI(_Chromosome& _chromosome, float start, float end)
89 : Fitness<_Chromosome>(_chromosome), span_start(start), span_end(end) {
93 * Method used to pass additional arguments needed by the function to
95 * Required map keys are:
96 * - _span_start_ - with value equal to begining of the Fitness function domain
97 * - _span_end_ - with value equal to end of the Fitness function domain
98 * Their values should be floats.
100 * @param args map containing span_start and span_end as a keys and
101 * their values (_double_) passed as strings
103 virtual void parseArguments(std::map<string, string> args) {
104 std::map<string, string>::iterator it;
105 for (it = args.begin(); it != args.end(); it++) {
106 if (it->first == "span_start") {
107 this->span_start = std::stod(it->second);
109 else if (it->first == "span_end") {
110 this->span_end = std::stod(it->second);
116 * Method used to get additional arguments needed by the function to
119 * @return map containing span_start and span_end as a map keys, with
120 * their values passed as string
122 std::map<string, string> getArguments() {
123 std::map<string, string> fit_args;
124 fit_args.insert(std::pair<string, string>("span_start", std::to_string(span_start)));
125 fit_args.insert(std::pair<string, string>("span_end", std::to_string(span_end)));
131 #endif /* __FITNESS_WSTI_H */