make_algo_MOEO.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // make_algo_MOEO.h
00005 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
00006 /*
00007     This library...
00008 
00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
00010  */
00011 //-----------------------------------------------------------------------------
00012 
00013 #ifndef _make_algo_MOEO_h
00014 #define _make_algo_MOEO_h
00015 
00016 // the parser and parameter includes
00017 #include "utils/eoParser.h"
00018 #include "utils/eoState.h"
00019 // selections
00020 #include "eoNDSorting.h"
00021 #include "old/moeoIBEA.h"
00022 #include "old/moeoBinaryQualityIndicator.h"
00023 #include "eoParetoRanking.h"
00024 #include "moeoParetoSharing.h"
00025 #include "eoSelectFromWorth.h"
00026 #include "moeoSelectOneFromPopAndArch.h"
00027 // replacements
00028 #include "eoReplacement.h"
00029 #include "moeoReplacement.h"
00030 // breeders
00031 #include "eoGeneralBreeder.h"
00032 // the algorithm
00033 #include "eoEasyEA.h"
00034 
00035 /*
00036  * This function builds the algorithm (i.e. selection and replacement) from existing continue (or checkpoint) and operators
00037  * It uses a parser (to get user parameters) and a state (to store the memory)
00038  *
00039  * NB: this function is almost cut-and-pasted from EO/make_algo_pareto.h and integrates MOEO features
00040  */
00041 template < class EOT >
00042   eoAlgo < EOT > &do_make_algo_MOEO (eoParser & _parser, eoState & _state,
00043                                      eoEvalFunc < EOT > &_eval,
00044                                      eoContinue < EOT > &_continue,
00045                                      eoGenOp < EOT > &_op,
00046                                      moeoArchive < EOT > &_arch)
00047 {
00048 
00049   // the fitness of an EOT object
00050   typedef typename EOT::Fitness EOFitness;
00051 
00052 
00053 
00054 
00055 
00056   /* the selection criteria */
00057   string & selStr = _parser.createParam (string ("NSGA-II"), "selCrit",
00058                                          "Multi-objective selection criterion: NSGA, NSGA-II, IBEA, ParetoRanking, ParetoSharing",
00059                                          'S', "Evolution Engine").value ();
00060   double nicheSize = _parser.createParam (1.0, "nicheSize",
00061                                           "Size of niche for NSGA-I or ParetoSharing",
00062                                           'n',
00063                                           "Evolution Engine").value ();
00064   double kappa =
00065     _parser.createParam (0.05, "kappa", "Scaling factor kappa for IBEA", 'k',
00066                          "Evolution Engine").value ();
00067   string & indStr =
00068     _parser.createParam (string ("Epsilon"), "indicator",
00069                          "Binary quality indicator for IBEA : Epsilon, Hypervolume",
00070                          'I', "Evolution Engine").value ();
00071   double rho = _parser.createParam (1.1, "rho",
00072                                     "reference point for the hypervolume calculation (must not be smaller than 1)",
00073                                     'r', "Evolution Engine").value ();
00074   // the eoPerf2Worth object
00075   eoPerf2Worth < EOT, double >*p2w;
00076   if ((selStr == string ("NSGA")) || (selStr == string ("NSGA-I")))     // NSGA-I
00077     p2w = new eoNDSorting_I < EOT > (nicheSize);
00078   else if (selStr == string ("NSGA-II"))        // NSGA-II
00079     p2w = new eoNDSorting_II < EOT > ();
00080   else if (selStr == string ("IBEA"))
00081     {                           // IBEA
00082       // the binary quality indicator
00083       moeoBinaryQualityIndicator < EOFitness > *I;
00084       if (indStr == string ("Epsilon"))
00085         I = new moeoAdditiveBinaryEpsilonIndicator < EOFitness >;
00086       else if (indStr == string ("Hypervolume"))
00087         I = new moeoBinaryHypervolumeIndicator < EOFitness > (rho);
00088       else
00089         {
00090           string stmp =
00091             string ("Invalid binary quality indicator (for IBEA): ") + indStr;
00092           throw std::runtime_error (stmp.c_str ());
00093         }
00094       p2w = new moeoIBEASorting < EOT > (I, kappa);
00095     }
00096   else if (selStr == string ("ParetoRanking"))
00097     {                           // Pareto Ranking
00098       eoDominanceMap < EOT > &dominance =
00099         _state.storeFunctor (new eoDominanceMap < EOT >);
00100       p2w = new eoParetoRanking < EOT > (dominance);
00101     }
00102   else if (selStr == string ("ParetoSharing"))
00103     {                           // Pareto Sharing    
00104       p2w = new moeoParetoSharing < EOT > (nicheSize);
00105     }
00106   else
00107     {
00108       string stmp = string ("Invalid Pareto selection criterion: ") + selStr;
00109       throw std::runtime_error (stmp.c_str ());
00110     }
00111   // store  
00112   _state.storeFunctor (p2w);
00113 
00114 
00115 
00116 
00117 
00118   /* the selector */
00119   eoValueParam < eoParamParamType > &selectionParam =
00120     _parser.createParam (eoParamParamType ("DetTour(2)"), "selection",
00121                          "Selection: Roulette, DetTour(T), StochTour(t) or Random",
00122                          's', "Evolution Engine");
00123   eoParamParamType & ppSelect = selectionParam.value ();        // pair< string , vector<string> >
00124   // the select object
00125   eoSelectOne < EOT > *select;
00126   if (ppSelect.first == string ("DetTour"))
00127     {                           // DetTour
00128       unsigned detSize;
00129       if (!ppSelect.second.size ())
00130         {                       // no parameter added       
00131           cerr << "WARNING, no parameter passed to DetTour, using 2" << endl;
00132           detSize = 2;
00133           // put back 2 in parameter for consistency (and status file)
00134           ppSelect.second.push_back (string ("2"));
00135         }
00136       else                      // parameter passed by user as DetTour(T)
00137         detSize = atoi (ppSelect.second[0].c_str ());
00138       select = new eoDetTournamentWorthSelect < EOT > (*p2w, detSize);
00139     }
00140   else if (ppSelect.first == string ("StochTour"))
00141     {                           // StochTour
00142       double p;
00143       if (!ppSelect.second.size ())
00144         {                       // no parameter added       
00145           cerr << "WARNING, no parameter passed to StochTour, using 1" <<
00146             endl;
00147           p = 1;
00148           // put back p in parameter for consistency (and status file)
00149           ppSelect.second.push_back (string ("1"));
00150         }
00151       else                      // parameter passed by user as DetTour(T)
00152         p = atof (ppSelect.second[0].c_str ());
00153       select = new eoStochTournamentWorthSelect < EOT > (*p2w, p);
00154     }
00155   else if (ppSelect.first == string ("Roulette"))
00156     {                           // Roulette
00157       select = new eoRouletteWorthSelect < EOT > (*p2w);
00158     }
00159   else if (ppSelect.first == string ("Random"))
00160     {                           // Random
00161       select = new eoRandomSelect < EOT >;
00162     }
00163   else
00164     {
00165       string stmp = string ("Invalid selection: ") + ppSelect.first;
00166       throw std::runtime_error (stmp.c_str ());
00167     }
00168   // store  
00169   _state.storeFunctor (select);
00170 
00171 
00172 
00173 
00174 
00175   /* elitism */
00176   bool useElitism = _parser.createParam (false, "elitism",
00177                                          "Use elitism in the selection process (individuals from the archive are randomly selected)",
00178                                          'E', "Evolution Engine").value ();
00179   double ratioFromPop = _parser.createParam (0.8, "ratio",
00180                                              "Ratio from the population for elitism (must not be greater than 1)",
00181                                              '\0',
00182                                              "Evolution Engine").value ();
00183   if (useElitism)
00184     {
00185       eoSelectOne < EOT > *selectPop = select;
00186       select =
00187         new moeoSelectOneFromPopAndArch < EOT > (*selectPop, _arch,
00188                                                  ratioFromPop);
00189       // store  
00190       _state.storeFunctor (select);
00191     }
00192 
00193 
00194 
00195 
00196 
00197   /* the number of offspring  */
00198   eoValueParam < eoHowMany > &offspringRateParam =
00199     _parser.createParam (eoHowMany (1.0), "nbOffspring",
00200                          "Nb of offspring (percentage or absolute)", 'O',
00201                          "Evolution Engine");
00202 
00203 
00204 
00205 
00206 
00207   /* the replacement */
00208   string & repStr =
00209     _parser.createParam (string ("Plus"), "replacement",
00210                          "Replacement: Plus, DistinctPlus or Generational",
00211                          'R', "Evolution Engine").value ();
00212   eoReplacement < EOT > *replace;
00213   if (repStr == string ("Plus"))        // Plus
00214     {
00215       replace = new moeoElitistReplacement < EOT, double >(*p2w);
00216     }
00217   else if (repStr == string ("DistinctPlus"))   // DistinctPlus
00218     {
00219       replace = new moeoDisctinctElitistReplacement < EOT, double >(*p2w);
00220     }
00221   else if (repStr == string ("Generational"))   // Generational
00222     {
00223       replace = new eoGenerationalReplacement < EOT >;
00224     }
00225   else
00226     {
00227       string stmp = string ("Invalid replacement: ") + repStr;
00228       throw std::runtime_error (stmp.c_str ());
00229     }
00230   // store
00231   _state.storeFunctor (replace);
00232 
00233 
00234 
00235 
00236 
00237   // the general breeder
00238   eoGeneralBreeder < EOT > *breed =
00239     new eoGeneralBreeder < EOT > (*select, _op, offspringRateParam.value ());
00240   _state.storeFunctor (breed);
00241 
00242   // the eoEasyEA
00243   eoAlgo < EOT > *algo =
00244     new eoEasyEA < EOT > (_continue, _eval, *breed, *replace);
00245   _state.storeFunctor (algo);
00246   // that's it!
00247   return *algo;
00248 }
00249 
00250 #endif

Generated on Mon Jan 15 14:19:18 2007 for ParadisEO-MOEO by  doxygen 1.5.1