6bool Evaluator::initialize()
10 values = std::vector<double>(MAX_SUBTREES,0);
11 valueFlags = std::vector<bool>(MAX_SUBTREES,
false);
16void Evaluator::initFunctionNames()
19 termNames.push_back(
"x1");
20 termNames.push_back(
"x2");
23 funcNames.push_back(
"+");
24 funcNames.push_back(
"-");
25 funcNames.push_back(
"*");
26 funcNames.push_back(
"/");
27 funcNames.push_back(
"sin");
28 funcNames.push_back(
"cos");
32double Evaluator::executeParsedExpression(uint sample, uint iTree)
35 if (iSample != sample){
36 valueFlags = std::vector<bool>(MAX_SUBTREES,
false);
45double Evaluator::execute()
49 switch(parsedExpression[iExpression][position])
52 return execute() + execute();
55 return execute() - execute();
58 return execute() * execute();
61 double d1 = execute();
62 double d2 = execute();
63 if(fabs(d2) < 0.00000001)
70 return sin(execute());
73 return cos(execute());
76 if( parsedExpression[iExpression][position] >= SUBTREES){
78 uint iExpression_ = iExpression;
79 uint iSample_ = iSample;
80 int position_ = position;
82 uint subtree = parsedExpression[iExpression][position] - SUBTREES + 1;
85 if (valueFlags[subtree - 1]){
86 returnValue = values[subtree - 1];
90 returnValue = values[subtree - 1] = executeParsedExpression(iSample, subtree);
91 valueFlags[subtree - 1] =
true;
94 iExpression = iExpression_;
99 else return data[iSample][parsedExpression[iExpression][position] - TERMINALS];