ECF 1.5
main - Copy.cpp
1#include <ecf/ECF.h>
2#include "SymbRegEvalOp.h"
3
4#include <string>
5uint showTree(Tree::Tree* tree, std::string& output, uint iNode = 0, uint prefix = 0)
6{
7 Tree::PrimitiveP prim = tree->at(iNode)->primitive_;
8 int arity = prim->getNumberOfArguments();
9
10 if(arity == 0) {
11 cout << prim->getName();
12 }
13 else if(prim->getName() == "pow") {
14 cout << "pow(";
15 iNode++;
16 iNode = showTree(tree, output, iNode, prefix);
17 cout << ",";
18 iNode++;
19 iNode = showTree(tree, output, iNode, prefix);
20 cout << ")";
21 }
22 else if(arity == 2) {
23 cout << "(";
24 iNode++;
25 iNode = showTree(tree, output, iNode, prefix);
26 cout << prim->getName();
27 iNode++;
28 iNode = showTree(tree, output, iNode, prefix);
29 cout << ")";
30 }
31 else {
32 cout << prim->getName();
33 cout << "(";
34 for(int child = 0; child < arity; child++) {
35 iNode++;
36 iNode = showTree(tree, output, iNode, prefix);
37 }
38 cout << ")";
39 }
40 return iNode;
41}
42
43
44int main(int argc, char **argv)
45{
46 StateP state (new State);
47
48 // set the evaluation operator
49 state->setEvalOp(new SymbRegEvalOp);
50
51 state->initialize(argc, argv);
52 state->run();
53
54 // after the evolution: show best tree
55 std::vector<IndividualP> hof = state->getHoF()->getBest();
56 IndividualP ind = hof[0];
57 std::cout << ind->toString();
58 Tree::Tree* tree = (Tree::Tree*) ind->getGenotype().get();
59 std::string out;
60 showTree(tree, out);
61 cout << out << endl;
62
63 return 0;
64}
std::string getName()
Return genotype's name (each genotype is uniquely identified with its name).
Definition: Genotype.h:86
State class - backbone of the framework.
Definition: State.h:39
Symbolic regression evaluation operator (using AP genotype).
Definition: SymbRegEvalOp.h:29
Tree class - implements genotype as a tree.
Definition: Tree_c.h:29