- Main Page
- Classes
- Files

- Search for |

# make_ea_moeo.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // make_ea_moeo.h
    00005 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
    00006 /*
    00007     This library...
    00008
    00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
    00010  */
    00011 //-----------------------------------------------------------------------------
    00012
    00013 #ifndef MAKE_EA_MOEO_H_
    00014 #define MAKE_EA_MOEO_H_
    00015
    00016 #include <stdlib.h>
    00017 #include <eoContinue.h>
    00018 #include <eoEvalFunc.h>
    00019 #include <eoGeneralBreeder.h>
    00020 #include <eoGenOp.h>
    00021 #include <utils/eoParser.h>
    00022 #include <utils/eoState.h>
    00023
    00024 #include <algo/moeoEA.h>
    00025 #include <algo/moeoEasyEA.h>
    00026 #include <archive/moeoArchive.h>
    00027 #include <comparator/moeoAggregativeComparator.h>
    00028 #include <comparator/moeoComparator.h>
    00029 #include <comparator/moeoDiversityThenFitnessComparator.h>
    00030 #include <comparator/moeoFitnessThenDiversityComparator.h>
    00031 #include <diversity/moeoDiversityAssignment.h>
    00032 #include <diversity/moeoDummyDiversityAssignment.h>
    00033 #include <diversity/moeoFrontByFrontCrowdingDiversityAssignment.h>
    00034 #include <diversity/moeoFrontByFrontSharingDiversityAssignment.h>
    00035 #include <fitness/moeoDummyFitnessAssignment.h>
    00036 #include <fitness/moeoExpBinaryIndicatorBasedFitnessAssignment.h>
    00037 #include <fitness/moeoFastNonDominatedSortingFitnessAssignment.h>
    00038 #include <fitness/moeoFitnessAssignment.h>
    00039 #include <metric/moeoAdditiveEpsilonBinaryMetric.h>
    00040 #include <metric/moeoHypervolumeBinaryMetric.h>
    00041 #include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
    00042 #include <replacement/moeoElitistReplacement.h>
    00043 #include <replacement/moeoEnvironmentalReplacement.h>
    00044 #include <replacement/moeoGenerationalReplacement.h>
    00045 #include <replacement/moeoReplacement.h>
    00046 #include <selection/moeoDetTournamentSelect.h>
    00047 #include <selection/moeoRandomSelect.h>
    00048 #include <selection/moeoStochTournamentSelect.h>
    00049 #include <selection/moeoSelectOne.h>
    00050 #include <selection/moeoSelectors.h>
    00051
    00052
    00062 template < class MOEOT >
    00063 moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalFunc < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoGenOp < MOEOT > & _op, moeoArchive < MOEOT > & _archive)
    00064 {
    00065
    00066     /* the objective vector type */
    00067     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
    00068
    00069
    00070     /* the fitness assignment strategy */
    00071     std::string & fitnessParam = _parser.createParam(std::string("FastNonDominatedSorting"), "fitness",
    00072                             "Fitness assignment scheme: Dummy, FastNonDominatedSorting or IndicatorBased", 'F',
    00073                             "Evolution Engine").value();
    00074     std::string & indicatorParam = _parser.createParam(std::string("Epsilon"), "indicator",
    00075                               "Binary indicator for IndicatorBased: Epsilon, Hypervolume", 'i',
    00076                               "Evolution Engine").value();
    00077     double rho = _parser.createParam(1.1, "rho", "reference point for the hypervolume indicator", 'r',
    00078                                      "Evolution Engine").value();
    00079     double kappa = _parser.createParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", 'k',
    00080                                        "Evolution Engine").value();
    00081     moeoFitnessAssignment < MOEOT > * fitnessAssignment;
    00082     if (fitnessParam == std::string("Dummy"))
    00083     {
    00084         fitnessAssignment = new moeoDummyFitnessAssignment < MOEOT> ();
    00085     }
    00086     else if (fitnessParam == std::string("FastNonDominatedSorting"))
    00087     {
    00088         fitnessAssignment = new moeoFastNonDominatedSortingFitnessAssignment < MOEOT> ();
    00089     }
    00090     else if (fitnessParam == std::string("IndicatorBased"))
    00091     {
    00092         // metric
    00093         moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric;
    00094         if (indicatorParam == std::string("Epsilon"))
    00095         {
    00096             metric = new moeoAdditiveEpsilonBinaryMetric < ObjectiveVector >;
    00097         }
    00098         else if (indicatorParam == std::string("Hypervolume"))
    00099         {
    00100             metric = new moeoHypervolumeBinaryMetric < ObjectiveVector > (rho);
    00101         }
    00102         else
    00103         {
    00104             std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam;
    00105             throw std::runtime_error(stmp.c_str());
    00106         }
    00107         fitnessAssignment = new moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT > (*metric, kappa);
    00108     }
    00109     else
    00110     {
    00111         std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam;
    00112         throw std::runtime_error(stmp.c_str());
    00113     }
    00114     _state.storeFunctor(fitnessAssignment);
    00115
    00116
    00117     /* the diversity assignment strategy */
    00118     eoValueParam<eoParamParamType> & diversityParam = _parser.createParam(eoParamParamType("Dummy"), "diversity",
    00119             "Diversity assignment scheme: Dummy, Sharing(nicheSize) or Crowding", 'D', "Evolution Engine");
    00120     eoParamParamType & diversityParamValue = diversityParam.value();
    00121     moeoDiversityAssignment < MOEOT > * diversityAssignment;
    00122     if (diversityParamValue.first == std::string("Dummy"))
    00123     {
    00124         diversityAssignment = new moeoDummyDiversityAssignment < MOEOT> ();
    00125     }
    00126     else if (diversityParamValue.first == std::string("Sharing"))
    00127     {
    00128         double nicheSize;
    00129         if (!diversityParamValue.second.size())   // no parameter added
    00130         {
    00131             std::cerr << "WARNING, no niche size given for Sharing, using 0.5" << std::endl;
    00132             nicheSize = 0.5;
    00133             diversityParamValue.second.push_back(std::string("0.5"));
    00134         }
    00135         else
    00136         {
    00137             nicheSize = atoi(diversityParamValue.second[0].c_str());
    00138         }
    00139         diversityAssignment = new moeoFrontByFrontSharingDiversityAssignment < MOEOT> (nicheSize);
    00140     }
    00141     else if (diversityParamValue.first == std::string("Crowding"))
    00142     {
    00143         diversityAssignment = new moeoFrontByFrontCrowdingDiversityAssignment < MOEOT> ();
    00144     }
    00145     else
    00146     {
    00147         std::string stmp = std::string("Invalid diversity assignment strategy: ") + diversityParamValue.first;
    00148         throw std::runtime_error(stmp.c_str());
    00149     }
    00150     _state.storeFunctor(diversityAssignment);
    00151
    00152
    00153     /* the comparator strategy */
    00154     std::string & comparatorParam = _parser.createParam(std::string("FitnessThenDiversity"), "comparator",
    00155                                "Comparator scheme: FitnessThenDiversity, DiversityThenFitness or Aggregative", 'C', "Evolution Engine").value();
    00156     moeoComparator < MOEOT > * comparator;
    00157     if (comparatorParam == std::string("FitnessThenDiversity"))
    00158     {
    00159         comparator = new moeoFitnessThenDiversityComparator < MOEOT> ();
    00160     }
    00161     else if (comparatorParam == std::string("DiversityThenFitness"))
    00162     {
    00163         comparator = new moeoDiversityThenFitnessComparator < MOEOT> ();
    00164     }
    00165     else if (comparatorParam == std::string("Aggregative"))
    00166     {
    00167         comparator = new moeoAggregativeComparator < MOEOT> ();
    00168     }
    00169     else
    00170     {
    00171         std::string stmp = std::string("Invalid comparator strategy: ") + comparatorParam;
    00172         throw std::runtime_error(stmp.c_str());
    00173     }
    00174     _state.storeFunctor(comparator);
    00175
    00176
    00177     /* the selection strategy */
    00178     eoValueParam < eoParamParamType > & selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection",
    00179             "Selection scheme: DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine");
    00180     eoParamParamType & ppSelect = selectionParam.value();
    00181     moeoSelectOne < MOEOT > * select;
    00182     if (ppSelect.first == std::string("DetTour"))
    00183     {
    00184         unsigned int tSize;
    00185         if (!ppSelect.second.size()) // no parameter added
    00186         {
    00187             std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl;
    00188             tSize = 2;
    00189             // put back 2 in parameter for consistency (and status file)
    00190             ppSelect.second.push_back(std::string("2"));
    00191         }
    00192         else // parameter passed by user as DetTour(T)
    00193         {
    00194             tSize = atoi(ppSelect.second[0].c_str());
    00195         }
    00196         select = new moeoDetTournamentSelect < MOEOT > (*comparator, tSize);
    00197     }
    00198     else if (ppSelect.first == std::string("StochTour"))
    00199     {
    00200         double tRate;
    00201         if (!ppSelect.second.size()) // no parameter added
    00202         {
    00203             std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl;
    00204             tRate = 1;
    00205             // put back 1 in parameter for consistency (and status file)
    00206             ppSelect.second.push_back(std::string("1"));
    00207         }
    00208         else // parameter passed by user as StochTour(T)
    00209         {
    00210             tRate = atof(ppSelect.second[0].c_str());
    00211         }
    00212         select = new moeoStochTournamentSelect < MOEOT > (*comparator, tRate);
    00213     }
    00214     /*
    00215     else if (ppSelect.first == string("Roulette"))
    00216     {
    00217         // TO DO !
    00218         // ...
    00219     }
    00220     */
    00221     else if (ppSelect.first == std::string("Random"))
    00222     {
    00223         select = new moeoRandomSelect <MOEOT > ();
    00224     }
    00225     else
    00226     {
    00227         std::string stmp = std::string("Invalid selection strategy: ") + ppSelect.first;
    00228         throw std::runtime_error(stmp.c_str());
    00229     }
    00230     _state.storeFunctor(select);
    00231
    00232
    00233     /* the replacement strategy */
    00234     std::string & replacementParam = _parser.createParam(std::string("Elitist"), "replacement",
    00235                                 "Replacement scheme: Elitist, Environmental or Generational", 'R', "Evolution Engine").value();
    00236     moeoReplacement < MOEOT > * replace;
    00237     if (replacementParam == std::string("Elitist"))
    00238     {
    00239         replace = new moeoElitistReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator);
    00240     }
    00241     else if (replacementParam == std::string("Environmental"))
    00242     {
    00243         replace = new moeoEnvironmentalReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator);
    00244     }
    00245     else if (replacementParam == std::string("Generational"))
    00246     {
    00247         replace = new moeoGenerationalReplacement < MOEOT> ();
    00248     }
    00249     else
    00250     {
    00251         std::string stmp = std::string("Invalid replacement strategy: ") + replacementParam;
    00252         throw std::runtime_error(stmp.c_str());
    00253     }
    00254     _state.storeFunctor(replace);
    00255
    00256
    00257     /* the number of offspring  */
    00258     eoValueParam < eoHowMany > & offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring",
    00259             "Number of offspring (percentage or absolute)", 'O', "Evolution Engine");
    00260
    00261
    00262     // the general breeder
    00263     eoGeneralBreeder < MOEOT > * breed = new eoGeneralBreeder < MOEOT > (*select, _op, offspringRateParam.value());
    00264     _state.storeFunctor(breed);
    00265     // the eoEasyEA
    00266     moeoEA < MOEOT > * algo = new moeoEasyEA < MOEOT > (_continue, _eval, *breed, *replace, *fitnessAssignment, *diversityAssignment);
    00267     _state.storeFunctor(algo);
    00268     return *algo;
    00269
    00270 }
    00271
    00272 #endif /*MAKE_EA_MOEO_H_*/