• 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(new State);
00206 
00207     state->setEvalOp(EvaluateOpP (new AproxEvalOp));
00208 
00209     state->initialize(argc, argv);
00210     state->run();
00211 
00212     return 0;
00213 }
00214 */
00215 
00216 
00217 
00218 //6. primjer: GP evolucija pravila rasporedjivanja
00219 /*
00220 #include "examples/GPScheduling/SchedulingEvalOp.h"
00221 int main(int argc, char **argv)
00222 {
00223     argc = 2;
00224     //argv[1] = "./examples/GPScheduling/parameters.txt";
00225     argv[1] = "./parameters.txt";
00226 
00227     StateP state = static_cast<StateP> (new State);
00228 
00229     state->setEvalOp(static_cast<EvaluateOpP> (new SchedulingEvalOp));
00230 
00231     state->initialize(argc, argv);
00232     state->run();
00233 
00234     XMLNode xInd = XMLNode::parseFile("./ind.txt", "Individual");
00235     IndividualP ind = (IndividualP) new Individual(state);
00236     ind->read(xInd);
00237     state->getAlgorithm()->evaluate(ind);
00238     std::cout << ind->toString();
00239 
00240     return 0;
00241 }
00242 */
00243 
00244 
00245 //7. primjer: XCS
00246 /*
00247 #include "examples/XCSmux/MuxEvalOp.h"
00248 #include "examples/XCSmaze/SingleObjMazeEnv.h"
00249 #include "examples/XCSmaze/SeqObjMazeEnv.h"
00250 #include "examples/XCSmaze/TwoObjMazeEnv.h"
00251 #include "examples/XCSmaze/ThreeObjMazeEnv.h"
00252 
00253 int main(int argc, char **argv)
00254 {
00255     argc = 2;
00256     StateP state = static_cast<StateP> (new State);
00257     MazeEnvP maze;
00258 
00259     //Multistep:
00260 
00261     //  - sigle-objective maze:
00262         //argv[1] = "examples/XCSmaze/single-obj params.txt";
00263         //maze = static_cast<MazeEnvP> (new SingleObjMazeEnv(state));
00264         //maze->setMazeFile("examples/XCSmaze/Environments/single-objective/Maze1.txt");
00265 
00266     //  - multi-objective maze:
00267         //argv[1] = "examples/XCSmaze/seq-obj params.txt";
00268         //maze = static_cast<MazeEnvP> (new SeqObjMazeEnv(state));
00269         //maze->setMazeFile("examples/XCSmaze/Environments/multi-objective/Maze1k.txt");
00270     
00271         argv[1] = "examples/XCSmaze/three-obj params.txt";
00272         maze = static_cast<MazeEnvP> (new ThreeObjMazeEnv(state,0));
00273         maze->setMazeFile("examples/XCSmaze/Environments/multi-objective/Maze1em.txt");
00274     
00275     maze->setResultsFile("examples/XCSmaze/Maze1k results.txt");
00276     state->setEvalOp(maze);
00277     
00278     //Singlestep:
00279 
00280     //  - 6-multiplexor problem:
00281     //  argv[1] = "./examples/XCSmux/parametri.txt";
00282     //  state->setEvalOp(static_cast<EvaluateOpP> (new MuxEvalOp(state)));
00283 
00284     state->initialize(argc, argv);
00285 
00286     state->run();
00287 
00288     int a;
00289     cin >> a;
00290     return 0;
00291 }
00292 */
00293 
00294 
00295 
00296 //8. primjer: Kartezijski GP - feedforward
00297 /*
00298 #include "examples/CGPFeedForward/FeedForwardEvalOp.h"
00299 using namespace cart;
00300 
00301 int main(int argc, char **argv)
00302 {
00303     argc = 2;
00304     argv[1] = "./examples/CGPFeedForward/parametri.txt";
00305 
00306     StateP state (new State);
00307 
00308     //izabrati koji tip
00309     //state->setEvalOp(new cart::FeedForwardEvalOpInt);
00310     state->setEvalOp(static_cast<EvaluateOpP> (new cart::FeedForwardEvalOpDouble));
00311     //state->setEvalOp(static_cast<EvaluateOpP> (new cart::CircuitEvalOpUint));
00312 
00313     state->initialize(argc, argv);
00314     state->run();
00315 
00316     return 0;
00317 }
00318 */

Generated on Thu Oct 6 2011 13:41:00 for ECF by  doxygen 1.7.1