ECF 1.5
main_interactive.cpp
1#include <ecf/ECF.h>
2#include "AntEvalOp.h"
3#include "Prog2.h"
4#include "Prog3.h"
5#include "TurnLeft.h"
6#include "IfFoodAhead.h"
7#include "TurnRight.h"
8#include "MoveAhead.h"
9#include <iostream>
10#include <fstream>
11#include <string.h>
12
13
14int main(int argc, char **argv)
15{
16 StateP state (new State);
17
18 // crate evaluation operator
19 state->setEvalOp(new AntEvalOp);
20
21 // create tree genotype
22 TreeP tree (new Tree::Tree);
23
24 // create new functions and add them to function set
25 Tree::PrimitiveP ifa (new IfFoodAhead);
26 tree->addFunction(ifa);
27 Tree::PrimitiveP prog2 (new Prog2);
28 tree->addFunction(prog2);
29 Tree::PrimitiveP prog3 (new Prog3);
30 tree->addFunction(prog3);
31 Tree::PrimitiveP tl (new TurnLeft);
32 tree->addTerminal(tl);
33 Tree::PrimitiveP tr (new TurnRight);
34 tree->addTerminal(tr);
35 Tree::PrimitiveP mv (new MoveAhead);
36 tree->addTerminal(mv);
37
38 // register genotype with our primitives
39 state->addGenotype(tree);
40
41 // initialize
42 if(!state->initialize(argc, argv))
43 return 1;
44
45 // read individual from 'best.txt'
46 XMLNode xInd = XMLNode::parseFile("./best.txt", "Individual");
47 IndividualP ind = (IndividualP) new Individual(state);
48 ind->read(xInd);
49 std::cout << ind->toString();
50
51 std::cout << "\nBest ant's performance on test trail(s):" << std::endl;
52 AntEvalOp* evalOp = new AntEvalOp;
55
56 // substitute test trails for learning trails (defined in config file):
57 state->getRegistry()->modifyEntry("learning_trails", state->getRegistry()->getEntry("test_trails"));
58 evalOp->initialize(state);
59 evalOp->evaluate(ind);
60
61 return 0;
62}
Artificial ant evaluation class (and environment simulator)
Definition: AntEvalOp.h:51
bool initialize(StateP)
Initialize the simulator, read environments from input file.
Definition: AntEvalOp.cpp:45
static bool step
show the ant's movement interactive step by step (no effect if trace is false!)
Definition: AntEvalOp.h:86
static bool trace
trace the ant's movement in the simulator (for visual output)
Definition: AntEvalOp.h:85
FitnessP evaluate(IndividualP individual)
Evaluation function, simulates ant movement and counts the eaten food.
Definition: AntEvalOp.cpp:98
GP function, checks if the food is ahead.
Definition: IfFoodAhead.h:11
Individual class - inherits a vector of Genotype objects.
Definition: Individual.h:12
void read(XMLNode &)
read individual from XML node
Definition: Individual.cpp:103
GP terminal, moves the ant one square ahead.
Definition: MoveAhead.h:9
GP function, executes 2 subtrees in sequence.
Definition: Prog2.h:7
GP function, executes 3 subtrees in sequence.
Definition: Prog3.h:7
State class - backbone of the framework.
Definition: State.h:39
Tree class - implements genotype as a tree.
Definition: Tree_c.h:29
GP terminal, turns the ant left.
Definition: TurnLeft.h:9
GP terminal, turns the ant right.
Definition: TurnRight.h:9