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 = double>
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 for (unsigned int i = 0; i < this->chromosome.size(); i++) {
38 _fenotype = _fenotype + this->chromosome[i].get() * ratio;
45 * Calculates fenotype of the current Chromosome
47 _Value calculateFenotype() {
48 const unsigned int power2N = 1 << this->chromosome.size();
49 return span_start + (span_end - span_start) * this->fenotype() / power2N;
53 * Calculates fitness value of the current Chromosome
55 _Value do_calculate() {
56 _Value fenotype = this->calculateFenotype();
57 return (exp(fenotype) * sin(3.1415 * fenotype) + 1) / fenotype;
61 * Class constructor. Initializes class with required values.
63 * @param _chromosome Chromosome, for which value will be calculated
65 WSTI(_Chromosome& _chromosome)
66 : Fitness<_Chromosome>(_chromosome) {
70 * Class constructor. Initializes class with required values.
72 * @param start begining of the Fitness function domain
73 * @param end end of the Fitness function domain
75 WSTI(float start, float end)
76 : span_start(start), span_end(end) {
80 * Class constructor. Initializes class with required values.
82 * @param _chromosome Chromosome, for which value will be calculated
83 * @param start begining of the Fitness function domain
84 * @param end end of the Fitness function domain
86 WSTI(_Chromosome& _chromosome, float start, float end)
87 : Fitness<_Chromosome>(_chromosome), span_start(start), span_end(end) {
91 * Method used to pass additional arguments needed by the function to
93 * Required map keys are:
94 * - _span_start_ - with value equal to begining of the Fitness function domain
95 * - _span_end_ - with value equal to end of the Fitness function domain
96 * Their values should be floats.
98 * @param args map containing span_start and span_end as a keys and
99 * their values (_double_) passed as strings
101 virtual void parseArguments(std::map<string, string> args) {
102 std::map<string, string>::iterator it;
103 for (it = args.begin(); it != args.end(); it++) {
104 if (it->first == "span_start") {
105 this->span_start = std::stod(it->second);
107 else if (it->first == "span_end") {
108 this->span_end = std::stod(it->second);
114 * Method used to get additional arguments needed by the function to
117 * @return map containing span_start and span_end as a map keys, with
118 * their values passed as string
120 std::map<string, string> getArguments() {
121 std::map<string, string> fit_args;
122 fit_args.insert(std::pair<string, string>("span_start", std::to_string(span_start)));
123 fit_args.insert(std::pair<string, string>("span_end", std::to_string(span_end)));
129 #endif /* __FITNESS_WSTI_H */