t-eoESOps.cpp

00001 // Program to test several EO-ES features
00002 
00003 #ifdef _MSC_VER
00004 #pragma warning(disable:4786)
00005 #endif 
00006 
00007 #include <string>
00008 #include <iostream>
00009 #include <iterator>
00010 
00011 using namespace std;
00012 
00013 // general
00014 #include <utils/eoParser.h>            // though contained in all others!
00015 // evolution specific
00016 #include <eoEvalFuncPtr.h>
00017 //#include <eoSequentialOpHolder.h>
00018 //#include <eoFullEA.h>
00019 // representation specific
00020 
00021 #include <es/eoESFullChrom.h>            // though contained in following
00022 //#include <eoESReco.h>
00023 #include <es/eoESFullMut.h>
00024 //#include <eoESRandomize.h>
00025 // this fitness
00026 #include "real_value.h"         // the sphere fitness
00027 
00028 // Now the main 
00030 typedef eoESFullChrom<float> Ind;
00031   
00032 main(int argc, char *argv[]) {
00033   unsigned mu, lambda;
00034   bool comma;
00035 
00036   // Create the command-line parser
00037   Parser parser( argc, argv, "Basic EA for vector<float> with adaptive mutations");
00038 
00039   //reproducible random seed - thanks, Maarten
00040   InitRandom(parser);
00041 
00042   // a first Ind, reading its parameters from the parser
00043   // will be used later to inialize the whole population
00044   Ind FirstEO(parser);
00045 
00046   // Evaluation
00047   // here we should call some  parser-based constructor, 
00048   // as many evaluation function need parameters
00049   // and also have some preliminary stuffs to do
00050   eoEvalFuncPtr<Ind> eval(  real_value );
00051 
00052  // recombination and mutation operators, reading their parameters from the parser
00053   eoESMutate<float> MyMut(parser, 
00054                           FirstEO.StdDevLength(), FirstEO.size(), 
00055                           FirstEO.CorCffLength() );
00056 
00057   std::cout << "First EO " << FirstEO << std::endl;
00058   MyMut(FirstEO);
00059   std::cout << "First EO mutated" << FirstEO << std::endl;
00060 
00061   /*
00062   // Evolution and population parameters
00063   eoScheme<Ind> the_scheme(parser);
00064 
00065   // recombination and mutation operators, reading their parameters from the parser
00066   eoESReco<float> MyReco(parser, FirstEO);
00067   eoESMutate<float> MyMut(parser, FirstEO);
00068 
00069   // termination conditions read by the parser
00070   eoTermVector<Ind> the_terms(parser);
00071   
00072   // Initialization of the population
00073   // shoudl be called using the parser, in case you want to read from file(s)
00074   eoESRandomize<float> randomize;       // an eoESInd randomnizer
00075   eoPop<Ind> pop(the_scheme.PopSize(), FirstEO, randomize); 
00076   // eval(pop);    // shoudl we call it from inside the constructor???
00077 
00078   // ALL parmeters have been read: write them out
00079   //  Writing the parameters on arv[0].status 
00080   // but of course this can be modified - see the example parser.cpp
00081   parser.outputParam();
00082   // except the help parameter???
00083   if( parser.getBool("-h" , "--help" , "Shows this help")) {
00084     parser.printHelp();
00085     exit(1);
00086   }
00087 
00088   unsigned i, iind;
00089 
00090 
00091     std::cout << "Initial population: \n" << std::endl;
00092     for (i = 0; i < pop.size(); ++i) {
00093       eval(pop[i]);
00094       std::cout << pop[i].fitness() << "\t" << pop[i] << std::endl;
00095     }
00096 
00097   // the Operators
00098   eoSequentialOpHolder <Ind> seqholder;
00099   //  seqholder.addOp(MyReco, 1.0);
00100   seqholder.addOp(MyMut, 1.0);
00101 
00102   // One generation
00103   eoEvolStep<Ind> evol_scheme(the_scheme, seqholder, eval);
00104   
00105   // the algorithm: 
00106   eoFullEA<Ind> ea(evol_scheme, the_terms);
00107 
00108   ea(pop);
00109   
00110     std::cout << "Final population: \n" << std::endl;
00111   for (i = 0; i < pop.size(); ++i)
00112     std::cout << pop[i].fitness() << "\t" << pop[i] << std::endl;
00113   return 0;
00114   */
00115 }
00116 

Generated on Thu Oct 19 05:06:43 2006 for EO by  doxygen 1.3.9.1