1#include "GPSymbRegEvalOp.h"
4#include <ecf/tree/Tree.h>
5#include "IAConstTerminal.h"
13 boundsCalculated =
false;
25 hometree->primitiveSet_ = (PrimitiveSetP) (
new PrimitiveSet);
26 hometree->primitiveSet_->initialize(state_);
27 this->primitiveSet_ = hometree->primitiveSet_;
30 for(
int i = 0; i < (int) userFunctions_.size(); i++) {
31 primitiveSet_->mAllPrimitives_[userFunctions_[i]->getName()] = userFunctions_[i];
32 primitiveSet_->mAllPrimitives_[userFunctions_[i]->getName()]->initialize(state_);
37 std::stringstream names;
39 names << *((std::string*) sptr.get());
40 while(names >> name) {
41 if(!primitiveSet_->addFunction(name)) {
42 ECF_LOG_ERROR(state_,
"Error: unknown function in function set (\'" + name +
"\')!");
46 if(primitiveSet_->getFunctionSetSize() == 0) {
47 ECF_LOG_ERROR(state_,
"Tree genotype: empty function set!");
52 Primitives::terminal_type currentType = Primitives::Double;
56 std::stringstream tNames;
58 tNames << *((std::string*) sptr.get());
63 typeIter = primitiveSet_->mTypeNames_.find(name);
64 if(typeIter != primitiveSet_->mTypeNames_.end()) {
65 currentType = typeIter->second;
71 for(; iTerminal < userTerminals_.size(); iTerminal++)
72 if(userTerminals_[iTerminal]->
getName() == name)
74 if(iTerminal < userTerminals_.size()) {
75 userTerminals_[iTerminal]->initialize(state_);
76 primitiveSet_->addTerminal(userTerminals_[iTerminal]);
83 if(name[0] ==
'[' || name[0] ==
'{') {
85 std::string ercValues =
"";
88 PrimitiveP erc = (PrimitiveP) (
new IAERCD);
89 ercValues = DBL_PREFIX;
91 while(name[name.size() - 1] !=
']' && name[name.size() - 1] !=
'}') {
92 ercValues +=
" " + name;
95 ercValues +=
" " + name;
98 erc->setName(ercValues);
99 erc->initialize(state_);
100 primitiveSet_->addTerminal(erc);
111 std::istringstream ss(name);
114 case Primitives::Double:
117 if(ss.fail() ==
false)
118 terminal->setValue(&dblValue);
120 case Primitives::Int:
123 if(ss.fail() ==
false)
124 terminal->setValue(&intValue);
126 case Primitives::Bool:
131 else if(name ==
"false")
133 if(ss.fail() ==
false || name ==
"true" || name ==
"false") {
138 terminal->setValue(&boolValue);
141 case Primitives::Char:
144 if(ss.fail() ==
false)
145 terminal->setValue(&charValue);
147 case Primitives::String:
148 std::string stringValue;
150 if(ss.fail() ==
false)
151 terminal->setValue(&stringValue);
154 terminal->setName(name);
155 primitiveSet_->addTerminal(terminal);
159 if(primitiveSet_->getTerminalSetSize() == 0) {
160 ECF_LOG_ERROR(state_,
"Tree: Empty terminal set!");
166 hometree->maxDepth_ = *((uint*) sptr.get());
168 hometree->minDepth_ = *((uint*) sptr.get());
169 if(hometree->maxDepth_ < hometree->minDepth_ || hometree->maxDepth_ < 1) {
170 ECF_LOG_ERROR(state_,
"Tree genotype: invalid values for max and min tree depth!");
174 hometree->initMaxDepth_ = hometree->maxDepth_;
177 hometree->initMaxDepth_ = *((uint*) sptr.get());
179 hometree->initMinDepth_ = hometree->minDepth_;
182 hometree->initMinDepth_ = *((uint*) sptr.get());
184 if(hometree->initMaxDepth_ < hometree->initMinDepth_ || hometree->initMaxDepth_ < 1) {
185 ECF_LOG_ERROR(state_,
"Tree genotype: invalid values for initial max and min tree depth!");
188 if(hometree->initMaxDepth_ > hometree->maxDepth_) {
189 ECF_LOG_ERROR(state_,
"Tree genotype: initial max depth cannot be greater than evolution max depth!");
voidP getParameterValue(StateP state, std::string name)
Read single parameter value from Registry.
std::string getName()
Return genotype's name (each genotype is uniquely identified with its name).
std::string name_
genotype's name
bool isParameterDefined(StateP state, std::string name)
Check if parameter is defined in the configuration.
IATree * copy()
Create an identical copy of the genotype object.
void initializeFirst(Tree *hometree)
Performs the first Tree initialization (performed only once for each active Tree Genotype)....
Primitive set class: collects all Tree Primitives.
Tree class - implements genotype as a tree.
uint startDepth_
start depth of the first node (0 by default)