make_ea_moeo.h

00001 /*
00002 * <make_ea_moeo.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * Arnaud Liefooghe
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * data to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
00034 *
00035 */
00036 //-----------------------------------------------------------------------------
00037 
00038 #ifndef MAKE_EA_MOEO_H_
00039 #define MAKE_EA_MOEO_H_
00040 
00041 #include <stdlib.h>
00042 #include <eoContinue.h>
00043 #include <eoEvalFunc.h>
00044 #include <eoGeneralBreeder.h>
00045 #include <eoGenOp.h>
00046 #include <utils/eoParser.h>
00047 #include <utils/eoState.h>
00048 
00049 #include <algo/moeoEA.h>
00050 #include <algo/moeoEasyEA.h>
00051 #include <archive/moeoArchive.h>
00052 #include <comparator/moeoAggregativeComparator.h>
00053 #include <comparator/moeoComparator.h>
00054 #include <comparator/moeoDiversityThenFitnessComparator.h>
00055 #include <comparator/moeoFitnessThenDiversityComparator.h>
00056 #include <diversity/moeoDiversityAssignment.h>
00057 #include <diversity/moeoDummyDiversityAssignment.h>
00058 #include <diversity/moeoFrontByFrontCrowdingDiversityAssignment.h>
00059 #include <diversity/moeoFrontByFrontSharingDiversityAssignment.h>
00060 #include <fitness/moeoDummyFitnessAssignment.h>
00061 #include <fitness/moeoExpBinaryIndicatorBasedFitnessAssignment.h>
00062 #include <fitness/moeoFastNonDominatedSortingFitnessAssignment.h>
00063 #include <fitness/moeoFitnessAssignment.h>
00064 #include <metric/moeoAdditiveEpsilonBinaryMetric.h>
00065 #include <metric/moeoHypervolumeBinaryMetric.h>
00066 #include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
00067 #include <replacement/moeoElitistReplacement.h>
00068 #include <replacement/moeoEnvironmentalReplacement.h>
00069 #include <replacement/moeoGenerationalReplacement.h>
00070 #include <replacement/moeoReplacement.h>
00071 #include <selection/moeoDetTournamentSelect.h>
00072 #include <selection/moeoRandomSelect.h>
00073 #include <selection/moeoStochTournamentSelect.h>
00074 #include <selection/moeoSelectOne.h>
00075 #include <selection/moeoSelectors.h>
00076 
00077 
00087 template < class MOEOT >
00088 moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalFunc < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoGenOp < MOEOT > & _op, moeoArchive < MOEOT > & _archive)
00089 {
00090 
00091   /* the objective vector type */
00092   typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00093 
00094 
00095   /* the fitness assignment strategy */
00096   std::string & fitnessParam = _parser.createParam(std::string("FastNonDominatedSorting"), "fitness",
00097                                "Fitness assignment scheme: Dummy, FastNonDominatedSorting or IndicatorBased", 'F',
00098                                "Evolution Engine").value();
00099   std::string & indicatorParam = _parser.createParam(std::string("Epsilon"), "indicator",
00100                                  "Binary indicator for IndicatorBased: Epsilon, Hypervolume", 'i',
00101                                  "Evolution Engine").value();
00102   double rho = _parser.createParam(1.1, "rho", "reference point for the hypervolume indicator", '\0',
00103                                    "Evolution Engine").value();
00104   double kappa = _parser.createParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", 'k',
00105                                      "Evolution Engine").value();
00106   moeoFitnessAssignment < MOEOT > * fitnessAssignment;
00107   if (fitnessParam == std::string("Dummy"))
00108     {
00109       fitnessAssignment = new moeoDummyFitnessAssignment < MOEOT> ();
00110     }
00111   else if (fitnessParam == std::string("FastNonDominatedSorting"))
00112     {
00113       fitnessAssignment = new moeoFastNonDominatedSortingFitnessAssignment < MOEOT> ();
00114     }
00115   else if (fitnessParam == std::string("IndicatorBased"))
00116     {
00117       // metric
00118       moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric;
00119       if (indicatorParam == std::string("Epsilon"))
00120         {
00121           metric = new moeoAdditiveEpsilonBinaryMetric < ObjectiveVector >;
00122         }
00123       else if (indicatorParam == std::string("Hypervolume"))
00124         {
00125           metric = new moeoHypervolumeBinaryMetric < ObjectiveVector > (rho);
00126         }
00127       else
00128         {
00129           std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam;
00130           throw std::runtime_error(stmp.c_str());
00131         }
00132       fitnessAssignment = new moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT > (*metric, kappa);
00133     }
00134   else
00135     {
00136       std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam;
00137       throw std::runtime_error(stmp.c_str());
00138     }
00139   _state.storeFunctor(fitnessAssignment);
00140 
00141 
00142   /* the diversity assignment strategy */
00143   eoValueParam<eoParamParamType> & diversityParam = _parser.createParam(eoParamParamType("Dummy"), "diversity",
00144       "Diversity assignment scheme: Dummy, Sharing(nicheSize) or Crowding", 'D', "Evolution Engine");
00145   eoParamParamType & diversityParamValue = diversityParam.value();
00146   moeoDiversityAssignment < MOEOT > * diversityAssignment;
00147   if (diversityParamValue.first == std::string("Dummy"))
00148     {
00149       diversityAssignment = new moeoDummyDiversityAssignment < MOEOT> ();
00150     }
00151   else if (diversityParamValue.first == std::string("Sharing"))
00152     {
00153       double nicheSize;
00154       if (!diversityParamValue.second.size())   // no parameter added
00155         {
00156           std::cerr << "WARNING, no niche size given for Sharing, using 0.5" << std::endl;
00157           nicheSize = 0.5;
00158           diversityParamValue.second.push_back(std::string("0.5"));
00159         }
00160       else
00161         {
00162           nicheSize = atoi(diversityParamValue.second[0].c_str());
00163         }
00164       diversityAssignment = new moeoFrontByFrontSharingDiversityAssignment < MOEOT> (nicheSize);
00165     }
00166   else if (diversityParamValue.first == std::string("Crowding"))
00167     {
00168       diversityAssignment = new moeoFrontByFrontCrowdingDiversityAssignment < MOEOT> ();
00169     }
00170   else
00171     {
00172       std::string stmp = std::string("Invalid diversity assignment strategy: ") + diversityParamValue.first;
00173       throw std::runtime_error(stmp.c_str());
00174     }
00175   _state.storeFunctor(diversityAssignment);
00176 
00177 
00178   /* the comparator strategy */
00179   std::string & comparatorParam = _parser.createParam(std::string("FitnessThenDiversity"), "comparator",
00180                                   "Comparator scheme: FitnessThenDiversity, DiversityThenFitness or Aggregative", 'c', "Evolution Engine").value();
00181   moeoComparator < MOEOT > * comparator;
00182   if (comparatorParam == std::string("FitnessThenDiversity"))
00183     {
00184       comparator = new moeoFitnessThenDiversityComparator < MOEOT> ();
00185     }
00186   else if (comparatorParam == std::string("DiversityThenFitness"))
00187     {
00188       comparator = new moeoDiversityThenFitnessComparator < MOEOT> ();
00189     }
00190   else if (comparatorParam == std::string("Aggregative"))
00191     {
00192       comparator = new moeoAggregativeComparator < MOEOT> ();
00193     }
00194   else
00195     {
00196       std::string stmp = std::string("Invalid comparator strategy: ") + comparatorParam;
00197       throw std::runtime_error(stmp.c_str());
00198     }
00199   _state.storeFunctor(comparator);
00200 
00201 
00202   /* the selection strategy */
00203   eoValueParam < eoParamParamType > & selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection",
00204       "Selection scheme: DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine");
00205   eoParamParamType & ppSelect = selectionParam.value();
00206   moeoSelectOne < MOEOT > * select;
00207   if (ppSelect.first == std::string("DetTour"))
00208     {
00209       unsigned int tSize;
00210       if (!ppSelect.second.size()) // no parameter added
00211         {
00212           std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl;
00213           tSize = 2;
00214           // put back 2 in parameter for consistency (and status file)
00215           ppSelect.second.push_back(std::string("2"));
00216         }
00217       else // parameter passed by user as DetTour(T)
00218         {
00219           tSize = atoi(ppSelect.second[0].c_str());
00220         }
00221       select = new moeoDetTournamentSelect < MOEOT > (*comparator, tSize);
00222     }
00223   else if (ppSelect.first == std::string("StochTour"))
00224     {
00225       double tRate;
00226       if (!ppSelect.second.size()) // no parameter added
00227         {
00228           std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl;
00229           tRate = 1;
00230           // put back 1 in parameter for consistency (and status file)
00231           ppSelect.second.push_back(std::string("1"));
00232         }
00233       else // parameter passed by user as StochTour(T)
00234         {
00235           tRate = atof(ppSelect.second[0].c_str());
00236         }
00237       select = new moeoStochTournamentSelect < MOEOT > (*comparator, tRate);
00238     }
00239   /*
00240   else if (ppSelect.first == string("Roulette"))
00241   {
00242       // TO DO !
00243       // ...
00244   }
00245   */
00246   else if (ppSelect.first == std::string("Random"))
00247     {
00248       select = new moeoRandomSelect <MOEOT > ();
00249     }
00250   else
00251     {
00252       std::string stmp = std::string("Invalid selection strategy: ") + ppSelect.first;
00253       throw std::runtime_error(stmp.c_str());
00254     }
00255   _state.storeFunctor(select);
00256 
00257 
00258   /* the replacement strategy */
00259   std::string & replacementParam = _parser.createParam(std::string("Elitist"), "replacement",
00260                                    "Replacement scheme: Elitist, Environmental or Generational", 'R', "Evolution Engine").value();
00261   moeoReplacement < MOEOT > * replace;
00262   if (replacementParam == std::string("Elitist"))
00263     {
00264       replace = new moeoElitistReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator);
00265     }
00266   else if (replacementParam == std::string("Environmental"))
00267     {
00268       replace = new moeoEnvironmentalReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator);
00269     }
00270   else if (replacementParam == std::string("Generational"))
00271     {
00272       replace = new moeoGenerationalReplacement < MOEOT> ();
00273     }
00274   else
00275     {
00276       std::string stmp = std::string("Invalid replacement strategy: ") + replacementParam;
00277       throw std::runtime_error(stmp.c_str());
00278     }
00279   _state.storeFunctor(replace);
00280 
00281 
00282   /* the number of offspring  */
00283   eoValueParam < eoHowMany > & offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring",
00284       "Number of offspring (percentage or absolute)", 'O', "Evolution Engine");
00285 
00286 
00287   // the general breeder
00288   eoGeneralBreeder < MOEOT > * breed = new eoGeneralBreeder < MOEOT > (*select, _op, offspringRateParam.value());
00289   _state.storeFunctor(breed);
00290   // the eoEasyEA
00291   moeoEA < MOEOT > * algo = new moeoEasyEA < MOEOT > (_continue, _eval, *breed, *replace, *fitnessAssignment, *diversityAssignment);
00292   _state.storeFunctor(algo);
00293   return *algo;
00294 
00295 }
00296 
00297 #endif /*MAKE_EA_MOEO_H_*/

Generated on Thu Mar 13 15:54:07 2008 for ParadisEO-MOEO-MultiObjectiveEvolvingObjects by  doxygen 1.4.7