13extern bool evaluateVerbose;
19uint EvalOp::showTree(
string& output,
Tree::Tree* tree, uint iNode, uint prefix)
21 Tree::PrimitiveP prim = tree->at(iNode)->primitive_;
22 int arity = prim->getNumberOfArguments();
27 else if(prim->getName() ==
"P2") {
30 iNode = showTree(output, tree, iNode, prefix);
33 iNode = showTree(output, tree, iNode, prefix);
36 else if(prim->getName() ==
"IF") {
39 iNode = showTree(output, tree, iNode, prefix);
42 iNode = showTree(output, tree, iNode, prefix);
45 iNode = showTree(output, tree, iNode, prefix);
48 else if(prim->getName() ==
"ADD" ||
49 prim->getName() ==
"AND" ||
50 prim->getName() ==
"AND2" ||
51 prim->getName() ==
"XOR" ||
52 prim->getName() ==
"XNOR" ||
53 prim->getName() ==
"OR") {
56 iNode = showTree(output, tree, iNode, prefix);
57 output +=
" " + prim->getName() +
" ";
59 iNode = showTree(output, tree, iNode, prefix);
62 else if(prim->getName() ==
"MUL") {
65 iNode = showTree(output, tree, iNode, prefix);
68 iNode = showTree(output, tree, iNode, prefix);
71 else if(prim->getName() ==
"NOT") {
74 for(
int child = 0; child < arity; child++) {
76 iNode = showTree(output, tree, iNode, prefix);
83 iNode = showTree(output, tree, iNode, prefix);
84 output +=
" " + prim->getName() +
" ";
86 iNode = showTree(output, tree, iNode, prefix);
90 output += prim->getName();
92 for(
int child = 0; child < arity; child++) {
94 iNode = showTree(output, tree, iNode, prefix);
105 state->getRegistry()->registerEntry(
"variables", (voidP) (
new uint(1)), ECF::UINT);
106 state->getRegistry()->registerEntry(
"variant", (voidP) (
new int(1)), ECF::INT);
107 state->getRegistry()->registerEntry(
"nelinearnost", (voidP) (
new int(0)), ECF::INT);
118 voidP sptr = state->getRegistry()->getEntry(
"variables");
119 nVariables = *((uint*)sptr.get());
121 sptr = state->getRegistry()->getEntry(
"variant");
122 varijanta = *((
int*)sptr.get());
124 sptr = state->getRegistry()->getEntry(
"nelinearnost");
125 targetNl = *((
int*)sptr.get());
129 for(uint var = 0; var < nVariables; var++)
130 inputNames.push_back(
"v" + uint2str(var));
133 inputMap.resize(nVariables);
134 bool t =
true, f =
false, val;
135 uint tries = (uint) pow(2., (
int) nVariables);
137 results.resize(tries);
139 anfPos.resize(tries);
141 for(uint count = 0; count < tries; count++) {
143 for(uint var = 0; var < nVariables; var++) {
149 inputMap[var].push_back(val);
155 for (uint var = 0; var < (nVariables); var++) {
177 uint tries = (uint) tt.size();
178 for(uint i = 0; i < tries; i++) {
185 fitness->setValue(0);
187 if(evaluateVerbose) {
188 ECF_LOG(state_, 1,
"Truth table:");
190 for(uint i = 0; i < tt.size(); i++)
194 showTree(output, tree);
195 ss <<
"infix: " << output;
196 ECF_LOG(state_, 1, ss.str());
199 ofstream out(
"funkcije.txt", ios_base::app);
200 for (uint i = 0; i < tt.size(); i++)
void registerParameters(StateP)
Register evaluator parameters. Called before EvaluateOp::initialize method.
FitnessP evaluate(IndividualP individual)
Evaluate a single individual. Method must create and return a Fitness object.
bool initialize(StateP)
Initialize the evaluator. Called before first evaluation occurs.
Fitness for maximization problems.
std::string getName()
Return genotype's name (each genotype is uniquely identified with its name).
Tree class - implements genotype as a tree.
void setTerminalValue(std::string, void *)
Set a terminal's value.
void execute(void *)
Execute current tree.