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

D:/Projekt/ECF_trunk/ECF/main.cpp

00001 #include "ECF.h"
00002 
00003 // Za svaki primjer je potrebno:
00004 // a) definirati odgovarajuci EvaluateOp objekt koji se primjenjuje za evaluaciju jedinke
00005 // b) definirati genotip (po zelji i druge parametre) u konf fajlu
00006 //
00007 // Svaki primjer ima posebnu funkciju main() - otkomentirati
00008 
00009 
00010 // 0. primjer: kako ispitati fitnes jedinke (spremljene u ind.txt)
00011 
00012 
00013 
00014 // 1. primjer: GA OneMax problem
00015 /*
00016 #include "examples/GAonemax/OneMaxEvalOp.h"
00017 int main(int argc, char **argv)
00018 {
00019     argc = 2;   // hard coded za lakse isprobavanje :)
00020     argv[1] = "./examples/GAOneMax/parametri.txt";
00021 
00022     StateP state (new State);
00023 
00024     //state->setEvalOp(static_cast<EvaluateOpP> (new OneMaxEvalOp));
00025     state->setEvalOp(new OneMaxEvalOp);
00026 
00027     state->initialize(argc, argv);
00028     state->run();
00029 
00030     return 0;
00031 }
00032 */
00033 
00034 
00035 
00036 // 2. primjer: GA minimizacija funkcije
00037 /*
00038 #include "examples/GAFunctionMin/FunctionMinEvalOp.h"
00039 int main(int argc, char **argv)
00040 {
00041 //  argc = 2;
00042 //  argv[1] = "./examples/GAFunctionMin/parametri.txt";
00043 
00044     // PSO algoritam:
00045     //argv[1] = "./examples/GAFunctionMin/parameters_PSO.txt";
00046 
00047     StateP state = static_cast<StateP> (new State);
00048 
00049     state->setEvalOp(static_cast<EvaluateOpP> (new FunctionMinEvalOp));
00050 
00051     state->initialize(argc, argv);
00052     state->run();
00053 
00054     return 0;
00055 }
00056 */
00057 
00058 
00059 namespace Tree {
00060 
00061 // primjer tipa podataka
00062 struct my_type
00063 {
00064     double v;
00065     bool b;
00066 };
00067 
00068 // terminal za doticni tip
00069 class MyTerminal : public Primitives::Primitive
00070 {
00071 public:
00072     my_type value_;
00073 
00074     MyTerminal()
00075     {
00076         nArguments_ = 0;
00077     }
00078     void execute(void* result, Tree& tree)
00079     {
00080         my_type& res = *(my_type*)result;
00081         res = value_;
00082     }
00083     void setValue(void* value)
00084     {
00085         value_ = *(my_type*)value;
00086     }
00087     ~MyTerminal()
00088     {   }
00089 };
00090 
00091 // primjer funkcije za korisnicki tip podataka
00092 class MyFunc : public Primitives::Primitive
00093 {
00094 public:
00095     MyFunc()
00096     {
00097         nArguments_ = 2;
00098         name_ = "func";
00099     }
00100     void execute(void* result, Tree& tree)
00101     {
00102         my_type first, second;
00103         my_type& func = *(my_type*)result;
00104 
00105         getNextArgument(&first, tree);
00106         getNextArgument(&second, tree);
00107         
00108         func.b = first.b && second.b;
00109         func.v = first.v + second.v;
00110     }
00111     ~MyFunc()
00112     {   }
00113 };
00114 
00115 }
00116 
00117 
00118 
00119 // 3. primjer: GP simbolicka regresija
00120 
00121 #include "examples/GPSymbReg/SymbRegEvalOp.h"
00122 #include "examples/GPSymbReg/zbr.h"
00123 int main(int argc, char **argv)
00124 {
00125     argc = 2;
00126     argv[1] = "./examples/GPSymbReg/parametri.txt";
00127 
00128     StateP state = static_cast<StateP> (new State);
00129 
00130     state->setEvalOp(static_cast<EvaluateOpP> (new SymbRegEvalOp));
00131 
00132     // primjer: dodavanje korisnickog operatora
00133 //  MyOpP myOp = (MyOpP) (new MyOp);
00134 //  state->addOperator(myOp);
00135 
00136     // primjer: dodavanje korisnickog algoritma
00137 //  MyAlgP myAlg = (MyAlgP) (new MyAlg);
00138 //  state->addAlgorithm(myAlg);
00139 
00140     // primjer: dodavanje korisnickog genotipa
00141 //  MyGenotypeP myGenotype = (MyGenotypeP) (new MyGenotype);
00142 //  state->addGenotype(myGenotype);
00143 
00144     // primjer: dodavanje korisnicke funkcije za stablo
00145     TreeP tree = (TreeP) new Tree::Tree;
00146     Tree::PrimitiveP zbr = (Tree::PrimitiveP) new Tree::Ad;
00147     tree->addFunction(zbr);
00148 
00149 Tree::PrimitiveP myFunc = (Tree::PrimitiveP) new Tree::MyFunc;
00150 tree->addFunction(myFunc);
00151 
00152 Tree::PrimitiveP myTerm = (Tree::PrimitiveP) new Tree::MyTerminal;
00153 myTerm->setName("term");
00154 tree->addTerminal(myTerm);
00155 
00156 
00157     state->addGenotype(tree);
00158 
00159     //for(int i = 0; i < 100; i++) {
00160         state->initialize(argc, argv);
00161         state->run();
00162     //}
00163 
00164     //std::vector<IndividualP> vec = state->getPopulation()->hof_->getBest();
00165     //IndividualP ind = vec[0];
00166     //state->getAlgorithm()->evaluate(ind);
00167     //XMLNode out;
00168     //ind->write(out);
00169     //std::cout << out.createXMLString() << std::endl;
00170 
00171     return 0;
00172 }
00173 
00174 
00175 
00176 //4. primjer: GA problem trgovackog putnika, 29 gradova
00177 /*
00178 #include "examples/GATSP/TSPEvalOp.h"
00179 int main(int argc, char **argv)
00180 {
00181     argc = 2;
00182     argv[1] = "./examples/GATSP/parameters.txt";
00183 
00184     StateP state = static_cast<StateP> (new State);
00185 
00186     state->setEvalOp(static_cast<EvaluateOpP> (new TSPEvalOp));
00187 
00188     state->initialize(argc, argv);
00189     state->run();
00190 
00191     return 0;
00192 }
00193 */
00194 
00195 
00196 
00197 //5. primjer: GA problem aproksimacije funkcije
00198 /*
00199 #include "examples/GAApprox/ApproxEvalOp.h"
00200 int main(int argc, char **argv)
00201 {
00202     argc = 2;
00203     argv[1] = "./examples/GAApprox/parameters.txt";
00204 
00205 //  StateP state = static_cast<StateP> (new State);
00206     StateP state(new State);
00207 //  State* state = new State;
00208 
00209     state->setEvalOp(EvaluateOpP (new AproxEvalOp));
00210 
00211     state->initialize(argc, argv);
00212     state->run();
00213 
00214     return 0;
00215 }
00216 */
00217 
00218 
00219 
00220 //6. primjer: GP evolucija pravila rasporedjivanja
00221 /*
00222 #include "examples/GPScheduling/SchedulingEvalOp.h"
00223 int main(int argc, char **argv)
00224 {
00225     argc = 2;
00226     //argv[1] = "./examples/GPScheduling/parameters.txt";
00227     argv[1] = "./parameters.txt";
00228 
00229     StateP state = static_cast<StateP> (new State);
00230 
00231     state->setEvalOp(static_cast<EvaluateOpP> (new SchedulingEvalOp));
00232 
00233     state->initialize(argc, argv);
00234     state->run();
00235 
00236     XMLNode xInd = XMLNode::parseFile("./ind.txt", "Individual");
00237     IndividualP ind = (IndividualP) new Individual(state);
00238     ind->read(xInd);
00239     state->getAlgorithm()->evaluate(ind);
00240     std::cout << ind->toString();
00241 
00242     return 0;
00243 }
00244 */
00245 
00246 
00247 //7. primjer: XCS
00248 /*
00249 #include "examples/XCSmux/MuxEvalOp.h"
00250 #include "examples/XCSmaze/SingleObjMazeEnv.h"
00251 #include "examples/XCSmaze/SeqObjMazeEnv.h"
00252 #include "examples/XCSmaze/TwoObjMazeEnv.h"
00253 #include "examples/XCSmaze/ThreeObjMazeEnv.h"
00254 
00255 int main(int argc, char **argv)
00256 {
00257     argc = 2;
00258     StateP state = static_cast<StateP> (new State);
00259     MazeEnvP maze;
00260 
00261     //Multistep:
00262 
00263     //  - sigle-objective maze:
00264         //argv[1] = "examples/XCSmaze/single-obj params.txt";
00265         //maze = static_cast<MazeEnvP> (new SingleObjMazeEnv(state));
00266         //maze->setMazeFile("examples/XCSmaze/Environments/single-objective/Maze1.txt");
00267 
00268     //  - multi-objective maze:
00269         //argv[1] = "examples/XCSmaze/seq-obj params.txt";
00270         //maze = static_cast<MazeEnvP> (new SeqObjMazeEnv(state));
00271         //maze->setMazeFile("examples/XCSmaze/Environments/multi-objective/Maze1k.txt");
00272     
00273         argv[1] = "examples/XCSmaze/three-obj params.txt";
00274         maze = static_cast<MazeEnvP> (new ThreeObjMazeEnv(state,0));
00275         maze->setMazeFile("examples/XCSmaze/Environments/multi-objective/Maze1em.txt");
00276     
00277     maze->setResultsFile("examples/XCSmaze/Maze1k results.txt");
00278     state->setEvalOp(maze);
00279     
00280     //Singlestep:
00281 
00282     //  - 6-multiplexor problem:
00283     //  argv[1] = "./examples/XCSmux/parametri.txt";
00284     //  state->setEvalOp(static_cast<EvaluateOpP> (new MuxEvalOp(state)));
00285 
00286     state->initialize(argc, argv);
00287 
00288     state->run();
00289 
00290     int a;
00291     cin >> a;
00292     return 0;
00293 }
00294 */
00295 
00296 
00297 /*
00298 //8. primjer: Kartezijski GP - feedforward
00299 #include "examples/CGPFeedForward/FeedForwardEvalOp.h"
00300 using namespace cart;
00301 
00302 int main(int argc, char **argv)
00303 {
00304     argc = 2;
00305     argv[1] = "./examples/CGPFeedForward/parametri.txt";
00306 
00307     StateP state (new State);
00308 
00309     //izabrati koji tip
00310     //state->setEvalOp(new cart::FeedForwardEvalOpInt);
00311     state->setEvalOp(static_cast<EvaluateOpP> (new cart::FeedForwardEvalOpDouble));
00312     //state->setEvalOp(static_cast<EvaluateOpP> (new cart::CircuitEvalOpUint));
00313 
00314     state->initialize(argc, argv);
00315     state->run();
00316 
00317     return 0;
00318 }
00319 */

Generated on Thu Sep 8 2011 15:10:27 for ECF by  doxygen 1.7.1