ECF 1.5
FunctionMaxEvalOp.h
1#ifndef FUNCTIONMAXEVALOP_H_
2#define FUNCTIONMAXEVALOP_H_
3
4#include <cmath>
5#include "Individual.h"
6#include "EvaluateOp.h"
7#include "FitnessMax.h"
8
9class FunctionMaxEvalOp: public EvaluateOp {
10public:
11 FitnessP evaluate(IndividualP individual){
12
13 FitnessP fitness = static_cast<FitnessP> (new FitnessMax);
14
15 Binary* bin = (Binary*) individual->at(0).get();
16
17 fitness->value_ = 0;
18 float realTemp = 0;
19 //implementirana funkcija za koju se racunam maksimum je ujedno i fitness funkcija
20 //fitness = fitness - (realValue[i] - (i + 1))^2
21 for (uint i = 0; i < bin->variables.size(); i++){
22 realTemp = pow((bin->realValue.at(i) - (i + 1)), 2.);
23 fitness->value_ = fitness->value_ - realTemp;
24 }
25 printf ("Vrijednost fitness funkcije: %f\n", fitness->value_);
26
27 return fitness;
28 }
29};
30typedef boost::shared_ptr<FunctionMaxEvalOp> FunctionMaxEvalOpP;
31
32#endif /* FUNCTIONMAXEVALOP_H_ */
Evaluation base class.
Definition: EvaluateOp.h:17
Fitness for maximization problems.
Definition: FitnessMax.h:13
FitnessP evaluate(IndividualP individual)
Evaluate a single individual. Method must create and return a Fitness object.