ECF 1.5
main.cpp
1#include <ecf/ECF.h>
2#include "EvalOp.h"
3#include "Primitives.cpp"
4#include "WriteTT.h"
5#include <iostream>
6#include <fstream>
7#include <string.h>
8
9
10/*
11
12This project evolves Boolean functions as GP trees (Tree genotype)
13
14*/
15
16
17//
18// glavni program
19//
20int main(int argc, char **argv)
21{
22 StateP state (new State);
23
24 // crate evaluation operator
25 // a) ordinary GP Boolean evaluator
26 EvalOp* e = new EvalOp;
27
28 state->setEvalOp(e);
29
30 // create tree genotype
31 TreeP tree (new Tree::Tree);
32
33 // create new functions and add them to function set
34 Tree::PrimitiveP ifl (new If);
35 tree->addFunction(ifl);
36 Tree::PrimitiveP orp (new Or);
37 tree->addFunction(orp);
38 Tree::PrimitiveP andp (new And);
39 tree->addFunction(andp);
40 Tree::PrimitiveP notp (new Not);
41 tree->addFunction(notp);
42 Tree::PrimitiveP xorp (new Xor);
43 tree->addFunction(xorp);
44 Tree::PrimitiveP and2p (new And2);
45 tree->addFunction(and2p);
46 Tree::PrimitiveP xnorp (new XNor);
47 tree->addFunction(xnorp);
48
49
50 // custom type terminals
51 for(uint i = 0; i < 20; i++) {
52 Tree::PrimitiveP myTerm = (Tree::PrimitiveP) new BoolV;
53 std::string name = "v" + uint2str(i);
54 myTerm->setName(name);
55 tree->addTerminal(myTerm);
56 }
57
58 // custom type functions (for Boolean constructions)
59 for(uint i = 0; i < 20; i++) {
60 Tree::PrimitiveP myTerm = (Tree::PrimitiveP) new BoolV;
61 std::string name = "f" + uint2str(i);
62 myTerm->setName(name);
63 tree->addTerminal(myTerm);
64 }
65
66 // register genotype with our primitives
67 state->addGenotype(tree);
68
69 WriteTT *b = new WriteTT;
70 state->addOperator((OperatorP) b);
71
72
73 // initialize and start evaluation
74 if(!state->initialize(argc, argv))
75 return 1;
76
77
78 // read and evaluate individual from file in 3rd agrument
79 if(argc == 3) {
80 XMLNode xInd = XMLNode::parseFile(argv[2], "Individual");
81 IndividualP ind = (IndividualP) new Individual(state);
82 ind->read(xInd);
83
84 evaluateVerbose = true;
85 state->getAlgorithm()->evalOp_->evaluate(ind);
86 cout << ind->toString();
87
88 return 0;
89 }
90
91 state->run();
92
93 return 0;
94}
Definition: EvalOp.h:6
Individual class - inherits a vector of Genotype objects.
Definition: Individual.h:12
void read(XMLNode &)
read individual from XML node
Definition: Individual.cpp:103
State class - backbone of the framework.
Definition: State.h:39
Tree class - implements genotype as a tree.
Definition: Tree_c.h:29