• Main Page
  • Modules
  • Classes
  • Files
  • File List

D:/Projekt/ECF_trunk/examples/GPNN/main.cpp

00001 #include <ecf/ECF.h>
00002 #include "EvalOp.h"
00003 #include "IfBetter.h"
00004 #include "Sqrt.h"
00005 #include "Iflte.h"
00006 
00007 
00008 const int MAXITER = 10;
00009 class Loop : public Tree::Primitives::Primitive
00010 {
00011 public:
00012     int times_;
00013     double loopResults[MAXITER];
00014 
00015     Loop()
00016     {
00017         nArguments_ = 1;
00018         name_ = "loop";
00019     }
00020 
00021 
00026     bool initialize(StateP state)
00027     {
00028         state_ = state;
00029         times_ = state->getRandomizer()->getRandomInteger(4);
00030         name_ = "loop" + uint2str(times_);
00031 
00032         return true;
00033     }
00034 
00035 
00036     void execute(void *result, Tree::Tree& tree)
00037     {
00038         // debug:
00039         std::string st = tree.toString();
00040 
00041         // if at the top, no looping
00042         if(tree.iNode_ == 0){
00043             double& arg = *(double*)result;
00044             getNextArgument(&arg, tree);
00045             return;
00046         }
00047 
00048         // perform loop body
00049         uint iNode = tree.iNode_;
00050         for(uint iter = 0; iter < times_; iter++) {
00051             tree.iNode_ = iNode;    // point to my subtree
00052             double state = 0.5;
00053             tree.setTerminalValue("state", &state);
00054             double& arg = *(double*)result;
00055             getNextArgument(&arg, tree);
00056             loopResults[iter] = arg;
00057         }
00058 
00059         // find parent function
00060         iNode = tree.iNode_ - 1;
00061         while(iNode + tree[iNode]->size_ <= tree.iNode_)
00062             iNode--;
00063 
00064         std::string funcName = tree[iNode]->primitive_->getName();
00065         if(funcName == "+")
00066         {   }
00067 
00068 
00069     }
00070 
00071 
00072     Tree::PrimitiveP copyWithNode(Tree::PrimitiveP primitive)
00073     {
00074         return (Tree::PrimitiveP) new Loop(*this);
00075     }
00076 
00077 
00082     Tree::PrimitiveP assignToNode(Tree::PrimitiveP primitive)
00083     {
00084         Loop *loop = new Loop(*this);
00085         loop->initialize(state_);
00086 
00087         return (Tree::PrimitiveP) loop;
00088     }
00089 
00090 };
00091 
00092 
00093 
00094 
00095 int main(int argc, char **argv)
00096 {
00097     StateP state (new State);
00098 
00099     // set the evaluation operator
00100     state->setEvalOp(new EvalOp);
00101 
00102     // create tree genotype
00103     TreeP tree (new Tree::Tree);
00104     
00105     // create new functions and add them to function set 
00106     Tree::PrimitiveP ifb (new IfBetter);
00107     tree->addFunction(ifb);
00108     Tree::PrimitiveP iflte (new IfLTE);
00109     tree->addFunction(iflte);
00110     Tree::PrimitiveP sqrt (new Sqrt);
00111     tree->addFunction(sqrt);
00112     Tree::PrimitiveP loop (new Loop);
00113     tree->addFunction(loop);
00114 
00115     // register genotype with our primitives
00116     state->addGenotype(tree);
00117 
00118     state->initialize(argc, argv);
00119     state->run();
00120 
00121     return 0;
00122 }

Generated on Fri Jul 5 2013 09:34:23 for ECF by  doxygen 1.7.1