13 std::vector<int> domain;
14 std::vector<int> codomain;
23 ifstream input(
"list.txt");
32 codomain.push_back(y);
61 for(uint i = 0; i < nSamples; i++) {
72 value += abs(codomain[i] - key);
74 fitness->setValue(value);
95 int& division = *(
int*)result;
100 division = abs(second) > 0.000000001 ? first / second : 1;
118 int& arg = *(
int*)result;
122 arg = (int) sqrt(1. * arg);
145 int& modulo = *(
int*)result;
151 modulo = first % second;
160uint showTree(
Tree::Tree* tree, uint iNode = 0, uint prefix = 0)
162 Tree::PrimitiveP prim = tree->at(iNode)->primitive_;
163 int arity = prim->getNumberOfArguments();
168 else if(prim->getName() ==
"pow") {
171 iNode = showTree(tree, iNode, prefix);
174 iNode = showTree(tree, iNode, prefix);
177 else if(arity == 2) {
180 iNode = showTree(tree, iNode, prefix);
181 cout << prim->getName();
183 iNode = showTree(tree, iNode, prefix);
187 cout << prim->getName();
189 for(
int child = 0; child < arity; child++) {
191 iNode = showTree(tree, iNode, prefix);
204int main(
int argc,
char **argv)
206 StateP state (
new State);
217 Tree::PrimitiveP div (
new DivInt);
223 Tree::PrimitiveP sqrt (
new Sqrt);
225 Tree::PrimitiveP mod (
new Mod);
229 state->addGenotype(tree);
231 state->initialize(argc, argv);
void execute(void *result, Tree::Tree &tree)
Execute the primitive.
Fitness for minimization problems.
std::string getName()
Return genotype's name (each genotype is uniquely identified with its name).
void execute(void *result, Tree::Tree &tree)
Execute the primitive.
FitnessP evaluate(IndividualP individual)
Evaluate a single individual. Method must create and return a Fitness object.
bool initialize(StateP)
Initialize the evaluator. Called before first evaluation occurs.
void execute(void *result, Tree::Tree &tree)
Execute the primitive.
State class - backbone of the framework.
Add function primitive (Tree genotype)
Div function primitive (Tree genotype)
Mul function primitive (Tree genotype)
Base primitive class (Tree genotype).
void getNextArgument(void *result, Tree &tree)
Execute next child node's primitive (execute next subtree).
Sub function primitive (Tree genotype)
Tree class - implements genotype as a tree.
bool addFunction(PrimitiveP)
Add user defined function primitive. Must be called prior to initialization (no impact otherwise).
void setTerminalValue(std::string, void *)
Set a terminal's value.
void execute(void *)
Execute current tree.