ECF 1.5
infixTree.h
1#include "ECF/ECF.h"
2
3//
4// ispis Tree u infix formatu
5//
6uint showTree(string& output, Tree::Tree* tree, uint iNode = 0, uint prefix = 0)
7{
8 Tree::PrimitiveP prim = tree->at(iNode)->primitive_;
9 int arity = prim->getNumberOfArguments();
10
11 if(arity == 0) {
12 output += prim->getName();
13 }
14 else if(prim->getName() == "P2") {
15 output += "P2(";
16 iNode++;
17 iNode = showTree(output, tree, iNode, prefix);
18 output += ", ";
19 iNode++;
20 iNode = showTree(output, tree, iNode, prefix);
21 output += ")";
22 }
23 else if(prim->getName() == "ADD" ||
24 prim->getName() == "AND" ||
25 prim->getName() == "NAND" ||
26 prim->getName() == "AND2" ||
27 prim->getName() == "XOR" ||
28 prim->getName() == "XNOR" ||
29 prim->getName() == "NOR" ||
30 prim->getName() == "OR") {
31 output += "(";
32 iNode++;
33 iNode = showTree(output, tree, iNode, prefix);
34 output += " " + prim->getName() + " ";
35 iNode++;
36 iNode = showTree(output, tree, iNode, prefix);
37 output += ")";
38 }
39 else if(prim->getName() == "MUL") {
40 output += "(";
41 iNode++;
42 iNode = showTree(output, tree, iNode, prefix);
43 output += " * ";
44 iNode++;
45 iNode = showTree(output, tree, iNode, prefix);
46 output += ")";
47 }
48 else if(prim->getName() == "NOT") {
49 output += "~";
50 output += "(";
51 for(int child = 0; child < arity; child++) {
52 iNode++;
53 iNode = showTree(output, tree, iNode, prefix);
54 }
55 output += ")";
56 }
57 else if(prim->getName() == "IF") {
58 output += "IF(";
59 iNode++;
60 iNode = showTree(output, tree, iNode, prefix);
61 output += ", ";
62 iNode++;
63 iNode = showTree(output, tree, iNode, prefix);
64 output += ", ";
65 iNode++;
66 iNode = showTree(output, tree, iNode, prefix);
67 output += ")";
68 }
69 else if(arity == 2) {
70 output += "(";
71 iNode++;
72 iNode = showTree(output, tree, iNode, prefix);
73 output += " " + prim->getName() + " ";
74 iNode++;
75 iNode = showTree(output, tree, iNode, prefix);
76 output += ")";
77 }
78 else if(arity == 1) {
79 output += prim->getName();
80 output += "(";
81 for(int child = 0; child < arity; child++) {
82 iNode++;
83 iNode = showTree(output, tree, iNode, prefix);
84 }
85 output += ")";
86 }
87 return iNode;
88}
std::string getName()
Return genotype's name (each genotype is uniquely identified with its name).
Definition: Genotype.h:86
Tree class - implements genotype as a tree.
Definition: Tree_c.h:29