ECF 1.5
Primitive.h
1#ifndef Primitive_h
2#define Primitive_h
3
4
5namespace Tree {
6
7#define DBL_PREFIX "D_"
8#define INT_PREFIX "I_"
9#define BOOL_PREFIX "B_"
10#define CHR_PREFIX "C_"
11#define STR_PREFIX "S_"
12
13class Tree;
14namespace Primitives {
15
16
23enum terminal_type
24{ Double, Int, Bool, Char, String };
25
26class Primitive;
27typedef boost::shared_ptr<Primitive> PrimitiveP;
28
37{
38public:
39 Primitive();
40 virtual ~Primitive();
41
47 virtual void execute(void* result, Tree& tree) = 0;
48 virtual bool initialize(StateP state);
49 virtual void setValue(void* value);
50 virtual void getValue(void* value);
51 virtual PrimitiveP copyWithNode(PrimitiveP);
52 virtual PrimitiveP assignToNode(PrimitiveP);
53 void getNextArgument(void* result, Tree& tree);
54 void skipNextArgument(Tree& tree);
56 void setName(std::string name);
57 std::string getName();
58 std::string getComplementName();
59
60 StateP state_;
61
62protected:
63 std::string name_;
64 int nArguments_;
65 std::string complementName_;
66};
67
68}
69typedef boost::shared_ptr<Primitives::Primitive> PrimitiveP;
70}
71
72#endif
Base primitive class (Tree genotype).
Definition: Primitive.h:37
virtual PrimitiveP copyWithNode(PrimitiveP)
Copy primitive (when copying a node, e.g. in crossover). The default behaviour just returns the same ...
Definition: Primitive.cpp:60
virtual void execute(void *result, Tree &tree)=0
Execute the primitive.
std::string getName()
Get primitive's name.
Definition: Primitive.cpp:109
int getNumberOfArguments()
Return primitive's number of arguments.
Definition: Primitive.cpp:91
void skipNextArgument(Tree &tree)
Skip next child subtree (doesn't execute the subtree).
Definition: Primitive.cpp:82
std::string getComplementName()
Get complement's name.
Definition: Primitive.cpp:118
void getNextArgument(void *result, Tree &tree)
Execute next child node's primitive (execute next subtree).
Definition: Primitive.cpp:71
virtual bool initialize(StateP state)
Initialize the primitive (default just sets the StateP pointer).
Definition: Primitive.cpp:23
void setName(std::string name)
Set primitive's name.
Definition: Primitive.cpp:100
virtual PrimitiveP assignToNode(PrimitiveP)
Assign primitive to node (when building a tree). The default behaviour just returns the same pointer ...
Definition: Primitive.cpp:36
Tree class - implements genotype as a tree.
Definition: Tree_c.h:29