• Main Page
  • Classes
  • Files
  • File List

D:/Radagast_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 = static_cast<StateP> (new State);
00023 
00024     state->setEvalOp(static_cast<EvaluateOpP> (new OneMaxEvalOp));
00025 
00026     state->initialize(argc, argv);
00027     state->run();
00028 
00029     return 0;
00030 }
00031 */
00032 
00033 
00034 // 2. primjer: GA minimizacija funkcije
00035 
00036 #include "examples/GAFunctionMin/FunctionMinEvalOp.h"
00037 int main(int argc, char **argv)
00038 {
00039 //  argc = 2;
00040 //  argv[1] = "./examples/GAFunctionMin/parametri.txt";
00041 
00042     // PSO algoritam:
00043     //argv[1] = "./examples/GAFunctionMin/parameters_PSO.txt";
00044 
00045     StateP state = static_cast<StateP> (new State);
00046 
00047     state->setEvalOp(static_cast<EvaluateOpP> (new FunctionMinEvalOp));
00048 
00049     state->initialize(argc, argv);
00050     state->run();
00051 
00052     return 0;
00053 }
00054 
00055 
00056 
00057 namespace Tree {
00058 
00059 // primjer tipa podataka
00060 struct my_type
00061 {
00062     double v;
00063     bool b;
00064 };
00065 
00066 // terminal za doticni tip
00067 class MyTerminal : public Primitives::Primitive
00068 {
00069 public:
00070     my_type value_;
00071 
00072     MyTerminal()
00073     {
00074         nArguments_ = 0;
00075     }
00076     void execute(void* result, Tree& tree)
00077     {
00078         my_type& res = *(my_type*)result;
00079         res = value_;
00080     }
00081     void setValue(void* value)
00082     {
00083         value_ = *(my_type*)value;
00084     }
00085     ~MyTerminal()
00086     {   }
00087 };
00088 
00089 // primjer funkcije za korisnicki tip podataka
00090 class MyFunc : public Primitives::Primitive
00091 {
00092 public:
00093     MyFunc()
00094     {
00095         nArguments_ = 2;
00096         name_ = "func";
00097     }
00098     void execute(void* result, Tree& tree)
00099     {
00100         my_type first, second;
00101         my_type& func = *(my_type*)result;
00102 
00103         getNextArgument(&first, tree);
00104         getNextArgument(&second, tree);
00105         
00106         func.b = first.b && second.b;
00107         func.v = first.v + second.v;
00108     }
00109     ~MyFunc()
00110     {   }
00111 };
00112 
00113 }
00114 
00115 
00116 // 3. primjer: GP simbolicka regresija
00117 /*
00118 #include "examples/GPSymbReg/SymbRegEvalOp.h"
00119 #include "examples/GPSymbReg/zbr.h"
00120 int main(int argc, char **argv)
00121 {
00122 //  argc = 2;
00123 //  argv[1] = "./examples/GPSymbReg/parametri.txt";
00124 
00125     StateP state = static_cast<StateP> (new State);
00126 
00127     state->setEvalOp(static_cast<EvaluateOpP> (new SymbRegEvalOp));
00128 
00129     // primjer: dodavanje korisnickog operatora
00130 //  MyOpP myOp = (MyOpP) (new MyOp);
00131 //  state->addOperator(myOp);
00132 
00133     // primjer: dodavanje korisnickog algoritma
00134 //  MyAlgP myAlg = (MyAlgP) (new MyAlg);
00135 //  state->addAlgorithm(myAlg);
00136 
00137     // primjer: dodavanje korisnickog genotipa
00138 //  MyGenotypeP myGenotype = (MyGenotypeP) (new MyGenotype);
00139 //  state->addGenotype(myGenotype);
00140 
00141     // primjer: dodavanje korisnicke funkcije za stablo
00142     TreeP tree = (TreeP) new Tree;
00143     PrimitiveP zbr = (PrimitiveP) new Ad;
00144     tree->addFunction(zbr);
00145 
00146 PrimitiveP myFunc = (PrimitiveP) new MyFunc;
00147 tree->addFunction(myFunc);
00148 
00149 PrimitiveP myTerm = (PrimitiveP) new MyTerminal;
00150 myTerm->setName("term");
00151 tree->addTerminal(myTerm);
00152 
00153 
00154     state->addGenotype(tree);
00155 
00156     //for(int i = 0; i < 100; i++) {
00157         state->initialize(argc, argv);
00158         state->run();
00159     //}
00160 
00161     //std::vector<IndividualP> vec = state->getPopulation()->hof_->getBest();
00162     //IndividualP ind = vec[0];
00163     //state->getAlgorithm()->evaluate(ind);
00164     //XMLNode out;
00165     //ind->write(out);
00166     //std::cout << out.createXMLString() << std::endl;
00167 
00168     return 0;
00169 }
00170 */
00171 
00172 
00173 //4. primjer: GA problem trgovackog putnika, 29 gradova
00174 /*
00175 #include "examples/GATSP/TSPEvalOp.h"
00176 int main(int argc, char **argv)
00177 {
00178     argc = 2;
00179     argv[1] = "./examples/GATSP/parameters.txt";
00180 
00181     StateP state = static_cast<StateP> (new State);
00182 
00183     state->setEvalOp(static_cast<EvaluateOpP> (new TSPEvalOp));
00184 
00185     state->initialize(argc, argv);
00186     state->run();
00187 
00188     return 0;
00189 }
00190 */
00191 
00192 //5. primjer: GA problem aproksimacije funkcije
00193 /*
00194 #include "examples/GAApprox/ApproxEvalOp.h"
00195 int main(int argc, char **argv)
00196 {
00197     argc = 2;
00198     argv[1] = "./examples/GAApprox/parameters.txt";
00199 
00200     StateP state = static_cast<StateP> (new State);
00201 
00202     state->setEvalOp(static_cast<EvaluateOpP> (new AproxEvalOp));
00203 
00204     state->initialize(argc, argv);
00205     state->run();
00206 
00207     return 0;
00208 }
00209 */
00210 
00211 //6. primjer: GP evolucija pravila rasporedjivanja
00212 /*
00213 #include "examples/GPScheduling/SchedulingEvalOp.h"
00214 int main(int argc, char **argv)
00215 {
00216     argc = 2;
00217     argv[1] = "./examples/GPScheduling/parameters.txt";
00218 
00219     StateP state = static_cast<StateP> (new State);
00220 
00221     state->setEvalOp(static_cast<EvaluateOpP> (new SchedulingEvalOp));
00222 
00223     state->initialize(argc, argv);
00224     state->run();
00225 
00226     return 0;
00227 }
00228 */

Generated on Wed Sep 1 2010 14:31:21 for ECF by  doxygen 1.7.1