ECF 1.5
Fitness.h
1#ifndef Fitness_h
2#define Fitness_h
3
4class Individual;
5typedef boost::shared_ptr<Individual> IndividualP;
6class Fitness;
7typedef boost::shared_ptr<Fitness> FitnessP;
8
16{
17protected:
18 bool valid_;
19 double value_;
20
21 // regular pointer (http://www.boost.org/doc/libs/1_36_0/libs/smart_ptr/sp_techniques.html#from_this)
22 // initialized in Individual::initialize()
23 Individual* individual_;
24
25public:
26 uint cid;
27
28 Fitness()
29 {
30 valid_ = true;
31 cid = 0;
32 }
33
38 virtual bool isBetterThan(FitnessP) = 0;
39
40 virtual Fitness* copy() = 0;
41
43 bool isValid()
44 { return valid_; }
45
48 { valid_ = false; }
49
51 virtual void setValue(double value)
52 { value_ = value; }
53
55 virtual double getValue()
56 { return value_; }
57
59 virtual void write(XMLNode&) { }
60
62 std::string toString()
63 {
64 XMLNode xFit;
65 write(xFit);
66 char *s = xFit.createXMLString();
67 std::string out(s);
68 freeXMLString(s);
69 return out;
70 }
71
76 virtual void read(XMLNode& xFitness)
77 {
78 XMLCSTR val = xFitness.getAttributeValue();
79 if(val) {
80 value_ = xmltof(val);
81 valid_ = true;
82 }
83 else
84 valid_ = false;
85 }
86
87 virtual ~Fitness()
88 { }
89};
90typedef boost::shared_ptr<Fitness> FitnessP;
91
92#endif // Fitness_h
93
Fitness base class.
Definition: Fitness.h:16
virtual void read(XMLNode &xFitness)
Read single fitness value from XML node. If the value is undefined (e.g. when reading unevaluated ind...
Definition: Fitness.h:76
uint cid
coherence index, used in asynchronous parallel algoritmhs
Definition: Fitness.h:26
virtual void write(XMLNode &)
Write fitness object to XMLNode.
Definition: Fitness.h:59
void setInvalid()
Set fitness object to invalid state (called after any change of individual's genotype).
Definition: Fitness.h:47
virtual Fitness * copy()=0
object copy (for duplication of an individual)
bool valid_
is fitness value up-to-date
Definition: Fitness.h:18
std::string toString()
Output fitness XML format as std::string.
Definition: Fitness.h:62
double value_
actual fitness value
Definition: Fitness.h:19
virtual bool isBetterThan(FitnessP)=0
Mandatory comparison operator.
virtual double getValue()
Return fitness value.
Definition: Fitness.h:55
bool isValid()
Is fitness object up to date.
Definition: Fitness.h:43
virtual void setValue(double value)
Set fitness value.
Definition: Fitness.h:51
Individual class - inherits a vector of Genotype objects.
Definition: Individual.h:12