8Cartesian::Cartesian(
void)
13Cartesian::~Cartesian(
void)
26 names << *((
string*) sptr.get());
30 if (name.length() == 0)
34 else if (name !=
"double" && name !=
"int" && name !=
"uint")
36 cerr <<
"Genoype initialization error:: Has to be one of types: double, int, uint" << endl;
46 name = *((
string*) sptr.get());
47 if (name.length() == 0)
49 cerr <<
"Genotype initialization error:: Number of input connections is undefined." << endl;
55 cerr <<
"Genotype initialization error:: Number of input connections can't be zero." << endl;
59 vector<string> functionset;
63 map<std::string, std::vector<uint> > args;
69 names << *((
string*) sptr.get());
75 char *c = (
char *)name.c_str();
76 for (
int i = 0; i < (int)name.length(); i++)
80 cerr <<
"Genoype initialization error:: Function " << name <<
" isn't implemented." << endl;
86 if (args[functionset.back()].empty())
89 vec.push_back(str2uint(name));
90 args[functionset.back()] = vec;
97 for (
int i = 0; i < args[functionset.back()].size(); i++)
99 if (arg == args[functionset.back()].at(i))
101 cerr <<
"Genotype initialization error:: Number of arguments " << arg;
102 cerr <<
" for function " << functionset.back() <<
" already taken." << endl;
106 args[functionset.back()].push_back(arg);
111 functionset.push_back(name);
115 if (functionset.size() == 0)
117 cerr <<
"Genotype initialization error:: Must be defined at least one function in function set." << endl;
122 for (
int i = 0; i < (int)functionset.size(); i++)
124 if (!args[functionset.at(i)].empty())
126 for (
int j = 0; j < args[functionset.at(i)].size(); j++)
128 if (args[functionset.at(i)].at(j) >
inputConns)
130 cerr <<
"Genoype initialization error:: Number of arguments for " << functionset.at(i);
131 cerr <<
" greater than number of input connections." << endl;
134 if (!
funcSet->addFunction(functionset.at(i), args[functionset.at(i)].at(j)))
142 if (!
funcSet->addFunction(functionset.at(i)))
157 names << *((
string*) sptr.get());
159 while (names >> name)
166 name = *((
string*) sptr.get());
172 cerr <<
"Genotype initialization error:: Number of inputs can't be zero." << endl;
177 name = *((
string*) sptr.get());
178 if (name.length() == 0)
180 cerr <<
"Genotype initialization error:: Number of outputs is undefined." << endl;
186 cerr <<
"Genotype initialization error:: Number of outputs can't be zero." << endl;
191 name = *((
string*) sptr.get());
192 if (name.length() == 0)
194 cerr <<
"Genotype initialization error:: Number of rows is undefined." << endl;
197 rows = str2uint(name);
200 cerr <<
"Genotype initialization error:: Number of rows can't be zero." << endl;
205 name = *((
string*) sptr.get());
206 if (name.length() == 0)
208 cerr <<
"Genotype initialization error:: Number of columns is undefined." << endl;
211 cols = str2uint(name);
214 cerr <<
"Genotype initialization error:: Number of columns can't be zero." << endl;
220 name = *((
string*) sptr.get());
222 if (name.length() == 0)
243 for(
int i = 0; i < (int) this->size(); i++) {
244 (*newObject)[i] = this->at(i);
251 vector<CrossoverOpP> crossops;
258 vector<MutationOpP> mutops;
283 xCart = XMLNode::createXMLTopNode(
"Cartesian");
285 sValue << this->size();
286 xCart.addAttribute(
"size", sValue.str().c_str());
291 sValue << this->at(i) <<
" ";
297 for (
int i = 0; i < (int)
outputs; i++)
302 xCart.addText(sValue.str().c_str());
305uint Cartesian::getGenomeSize()
314 for (
int i = 0; i < (int)(
rows *
cols); i++)
316 if ((i %
rows) == 0 && i != 0)
327 for (
int i = 0; i < (int)
outputs; i++)
339 return (uint)(
state_->getRandomizer()->getRandomInteger(0, emax - 1));
343 return (uint)(
state_->getRandomizer()->getRandomInteger(emin, emax - 1));
350 return (uint)(
state_->getRandomizer()->getRandomInteger(hmin, hmax - 1));
355 return (uint)(
state_->getRandomizer()->getRandomInteger(0,
numFunc - 1));
367 cout << this->at(i) <<
" ";
373 for (
int i = 0; i < (int)
outputs; i++)
voidP getParameterValue(StateP state, std::string name)
Read single parameter value from Registry.
bool registerParameter(StateP state, std::string name, voidP value, enum ECF::type T, std::string description="")
Register a single parameter.
std::string name_
genotype's name
Cartesian genotype: one point crossover operator.
uint numVars
number of variables
void registerParameters(StateP state)
voidP constantset
all possible constants
vector< MutationOpP > getMutationOp()
uint cols
number of columns
uint levelsBack
levels back parameter
void write(XMLNode &xCart)
uint numFunc
number of functions
uint randInputConn(uint currCol)
StateP state_
local copy of state
bool initialize(StateP state)
void read(XMLNode &xCart)
uint inputConns
number of input connections
uint inputs
number of primary inputs
void evaluate(voidP inputs, void *result, uint funcNum)
vector< CrossoverOpP > getCrossoverOp()
uint outputs
number of final outputs
FunctionSetP funcSet
function nodes
Cartesian genotype: one point mutation operator.