ECF 1.5
Genotype.h
1#ifndef Genotype_h
2#define Genotype_h
3
4#include<string>
5
6// forward declarations of genotype operators
7class CrossoverOp;
8typedef boost::shared_ptr<CrossoverOp> CrossoverOpP;
9class MutationOp;
10typedef boost::shared_ptr<MutationOp> MutationOpP;
11
12// forward declaration of State class
13class State;
14typedef boost::shared_ptr<State> StateP;
15
36{
37protected:
38
39public:
40 Genotype()
41 { }
42 virtual ~Genotype()
43 { }
44
46 virtual bool initialize(StateP state) = 0;
47
49 virtual Genotype* copy() = 0;
50
52 virtual std::vector<CrossoverOpP> getCrossoverOp()
53 {
54 std::vector<CrossoverOpP> empty;
55 return empty;
56 }
57
59 virtual std::vector<MutationOpP> getMutationOp()
60 {
61 std::vector<MutationOpP> empty;
62 return empty;
63 }
64
66 virtual void registerParameters(StateP) {}
67
68 bool registerParameter(StateP state, std::string name, voidP value, enum ECF::type T, std::string description = "");
69
70 voidP getParameterValue(StateP state, std::string name);
71
72 bool setParameterValue(StateP state, std::string name, voidP value);
73
74 bool isParameterDefined(StateP state, std::string name);
75
77 virtual void read(XMLNode&) = 0;
78
80 virtual void write(XMLNode&) = 0;
81
82 virtual uint getGenomeSize()
83 { return 0; }
84
86 std::string getName()
87 { return name_; }
88
91 { return genotypeId_; }
92
94 void setGenotypeId(uint id)
95 { genotypeId_ = id; }
96
98 std::string toString()
99 {
100 XMLNode xGene;
101 write(xGene);
102 char *s = xGene.createXMLString();
103 std::string out(s);
104 freeXMLString(s);
105 return out;
106 }
107
108protected:
109 std::string name_;
111};
112typedef boost::shared_ptr<Genotype> GenotypeP;
113
114#endif // Genotype_h
115
CrossoverOp base class.
Definition: Crossover.h:19
Genotype base class.
Definition: Genotype.h:36
voidP getParameterValue(StateP state, std::string name)
Read single parameter value from Registry.
Definition: Genotype.cpp:10
virtual void registerParameters(StateP)
Register genotype's parameters (called before Genotype::initialize)
Definition: Genotype.h:66
std::string getName()
Return genotype's name (each genotype is uniquely identified with its name).
Definition: Genotype.h:86
uint getGenotypeId()
Return this genotype's index in individual structure.
Definition: Genotype.h:90
virtual std::vector< MutationOpP > getMutationOp()
Create and return a vector of mutation operators.
Definition: Genotype.h:59
virtual bool initialize(StateP state)=0
Initialize a genotype object (read parameters, perform sanity check, build data)
virtual std::vector< CrossoverOpP > getCrossoverOp()
Create and return a vector of crossover operators.
Definition: Genotype.h:52
bool registerParameter(StateP state, std::string name, voidP value, enum ECF::type T, std::string description="")
Register a single parameter.
Definition: Genotype.cpp:4
virtual void write(XMLNode &)=0
Write genotype data to XMLNode.
std::string name_
genotype's name
Definition: Genotype.h:109
bool isParameterDefined(StateP state, std::string name)
Check if parameter is defined in the configuration.
Definition: Genotype.cpp:22
uint genotypeId_
this genotype's unique index in individual structure
Definition: Genotype.h:110
void setGenotypeId(uint id)
Set genotype index in an individual.
Definition: Genotype.h:94
virtual Genotype * copy()=0
Create an identical copy of the genotype object.
std::string toString()
Output genotype to string.
Definition: Genotype.h:98
virtual void read(XMLNode &)=0
Read genotype data from XMLNode.
bool setParameterValue(StateP state, std::string name, voidP value)
Write single parameter value to Registry.
Definition: Genotype.cpp:16
MutationOp base class.
Definition: Mutation.h:17
State class - backbone of the framework.
Definition: State.h:39
type
Data types used for configuration file parameters.
Definition: Registry.h:16