ECF 1.7
Tree_c.h
1#ifndef Tree_c_h
2#define Tree_c_h
3#include "Node.h"
4#include "../Genotype.h"
5#include <vector>
6#define MAX_ARGS 10
7
8
9namespace Tree
10{
11
16
17class PrimitiveSet;
18typedef std::shared_ptr<PrimitiveSet> PrimitiveSetP;
19
28class Tree : public std::vector<NodeP>, public Genotype
29{
30protected:
31 uint growBuild(PrimitiveSetP primitiveSet, uint myDepth);
32 uint fullBuild(PrimitiveSetP primitiveSet, uint myDepth);
33 uint setSize(uint);
34 void setDepth(uint myDepth);
35 virtual void initializeFirst(Tree* hometree);
36
37 std::vector<PrimitiveP> userFunctions_; // programatically added functions
38 std::vector<PrimitiveP> userTerminals_; // programatically added terminals
39 StateP state_;
40
41public:
42 Tree();
43 ~Tree();
44 Tree* copy();
45
46 void growBuild(PrimitiveSetP primitiveSet);
47 void fullBuild(PrimitiveSetP primitiveSet);
48 void update();
49 void execute(void*);
50 void addNode(Node* node);
51 void addNode(NodeP node);
52 void setTerminalValue(std::string, void*);
53 void getTerminalValue(std::string, void*);
54 void write(XMLNode&);
55 void read(XMLNode&);
56 void registerParameters(StateP);
57 bool initialize (StateP state);
58
59 std::vector<MutationOpP> getMutationOp();
60 std::vector<CrossoverOpP> getCrossoverOp();
61
62 bool addFunction(PrimitiveP);
63 bool addTerminal(PrimitiveP);
64
65 uint getMaxDepth()
66 { return maxDepth_; }
67
68 uint getMinDepth()
69 { return minDepth_; }
70
71 uint getStartDepth()
72 { return startDepth_; }
73
74 PrimitiveSetP primitiveSet_;
75 uint iNode_;
77 uint maxDepth_;
78 uint minDepth_;
81};
82}
83typedef std::shared_ptr<Tree::Tree> TreeP;
84
85#endif
86
Node base class (Tree genotype).
Definition Node.h:20
Primitive set class: collects all Tree Primitives.
bool addFunction(PrimitiveP)
Add user defined function primitive. Must be called prior to initialization (no impact otherwise).
Definition Tree.cpp:80
uint startDepth_
start depth of the first node (0 by default)
Definition Tree_c.h:76
uint fullBuild(PrimitiveSetP primitiveSet, uint myDepth)
Build Tree using 'full' method.
Definition Tree.cpp:382
uint minDepth_
min allowed Tree depth
Definition Tree_c.h:78
void getTerminalValue(std::string, void *)
Retrieve a terminal's value.
Definition Tree.cpp:522
void setTerminalValue(std::string, void *)
Set a terminal's value.
Definition Tree.cpp:504
Tree * copy()
Create an identical copy of the genotype object.
Definition Tree.cpp:37
uint initMinDepth_
min allowed Tree depth at initialization (minDepth_ used if not defined)
Definition Tree_c.h:80
uint growBuild(PrimitiveSetP primitiveSet, uint myDepth)
Build Tree using 'grow' method.
Definition Tree.cpp:404
uint iNode_
current node index (when parsing the tree)
Definition Tree_c.h:75
bool addTerminal(PrimitiveP)
Add user defined terminal primitive. Must be called prior to initialization (no impact otherwise).
Definition Tree.cpp:91
std::vector< CrossoverOpP > getCrossoverOp()
Create and return a vector of crossover operators.
Definition Tree.cpp:49
void setDepth(uint myDepth)
Calculate depth of each node in the tree.
Definition Tree.cpp:468
std::vector< MutationOpP > getMutationOp()
Create and return a vector of mutation operators.
Definition Tree.cpp:61
void write(XMLNode &)
Write genotype data to XMLNode.
Definition Tree.cpp:535
uint initMaxDepth_
max allowed Tree depth at initialization (maxDepth_ used if not defined)
Definition Tree_c.h:79
void update()
Calculate depth and subtree sizes of each node in the tree.
Definition Tree.cpp:435
void registerParameters(StateP)
Register genotype's parameters (called before Genotype::initialize).
Definition Tree.cpp:98
uint setSize(uint)
Calculate subtree sizes of each node in the tree.
Definition Tree.cpp:451
void execute(void *)
Execute current tree.
Definition Tree.cpp:362
void read(XMLNode &)
Read genotype data from XMLNode.
Definition Tree.cpp:550
uint maxDepth_
max allowed Tree depth
Definition Tree_c.h:77
virtual void initializeFirst(Tree *hometree)
Performs the first Tree initialization (performed only once for each active Tree Genotype)....
Definition Tree.cpp:149
bool initialize(StateP state)
Initialize a genotype object (read parameters, perform sanity check, build data).
Definition Tree.cpp:115