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 #include <moeoArchive.h>
00024 #include <moeoComparator.h>
00025 #include <moeoCrowdingDistanceDiversityAssignment.h>
00026 #include <moeoDetTournamentSelect.h>
00027 #include <moeoDiversityAssignment.h>
00028 #include <moeoEA.h>
00029 #include <moeoEasyEA.h>
00030 #include <moeoElitistReplacement.h>
00031 #include <moeoEnvironmentalReplacement.h>
00032 #include <moeoFastNonDominatedSortingFitnessAssignment.h>
00033 #include <moeoFitnessAssignment.h>
00034 #include <moeoGenerationalReplacement.h>
00035 #include <moeoIndicatorBasedFitnessAssignment.h>
00036 #include <moeoRandomSelect.h>
00037 #include <moeoReplacement.h>
00038 #include <moeoRouletteSelect.h>
00039 #include <moeoSelectOne.h>
00040 #include <moeoStochTournamentSelect.h>
00041 #include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
00042 
00052 template < class MOEOT >
00053 moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalFunc < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoGenOp < MOEOT > & _op, moeoArchive < MOEOT > & _archive)
00054 {
00055 
00056     /* the objective vector type */
00057     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00058 
00059 
00060     /* the fitness assignment strategy */
00061     string & fitnessParam = _parser.createParam(string("FastNonDominatedSorting"), "fitness",
00062                             "Fitness assignment scheme: Dummy, FastNonDominatedSorting or IndicatorBased", 'F',
00063                             "Evolution Engine").value();
00064     string & indicatorParam = _parser.createParam(string("Epsilon"), "indicator",
00065                               "Binary indicator for IndicatorBased: Epsilon, Hypervolume", 'i',
00066                               "Evolution Engine").value();
00067     double rho = _parser.createParam(1.1, "rho", "reference point for the hypervolume indicator", 'r',
00068                                      "Evolution Engine").value();
00069     double kappa = _parser.createParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", 'k',
00070                                        "Evolution Engine").value();
00071     moeoFitnessAssignment < MOEOT > * fitnessAssignment;
00072     if (fitnessParam == string("Dummy"))
00073     {
00074         fitnessAssignment = new moeoDummyFitnessAssignment < MOEOT> ();
00075     }
00076     else if (fitnessParam == string("FastNonDominatedSorting"))
00077     {
00078         fitnessAssignment = new moeoFastNonDominatedSortingFitnessAssignment < MOEOT> ();
00079     }
00080     else if (fitnessParam == string("IndicatorBased"))
00081     {
00082         // metric
00083         moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric;
00084         if (indicatorParam == string("Epsilon"))
00085         {
00086             metric = new moeoAdditiveEpsilonBinaryMetric < ObjectiveVector >;
00087         }
00088         else if (indicatorParam == string("Hypervolume"))
00089         {
00090             metric = new moeoHypervolumeBinaryMetric < ObjectiveVector > (rho);
00091         }
00092         else
00093         {
00094             string stmp = string("Invalid binary quality indicator: ") + indicatorParam;
00095             throw std::runtime_error(stmp.c_str());
00096         }
00097         fitnessAssignment = new moeoIndicatorBasedFitnessAssignment < MOEOT> (metric, kappa);
00098     }
00099     else
00100     {
00101         string stmp = string("Invalid fitness assignment strategy: ") + fitnessParam;
00102         throw std::runtime_error(stmp.c_str());
00103     }
00104     _state.storeFunctor(fitnessAssignment);
00105 
00106 
00107     /* the diversity assignment strategy */
00108     string & diversityParam = _parser.createParam(string("Dummy"), "diversity",
00109                               "Diversity assignment scheme: Dummy or CrowdingDistance", 'D', "Evolution Engine").value();
00110     moeoDiversityAssignment < MOEOT > * diversityAssignment;
00111     if (diversityParam == string("CrowdingDistance"))
00112     {
00113         diversityAssignment = new moeoCrowdingDistanceDiversityAssignment < MOEOT> ();
00114     }
00115     else if (diversityParam == string("Dummy"))
00116     {
00117         diversityAssignment = new moeoDummyDiversityAssignment < MOEOT> ();
00118     }
00119     else
00120     {
00121         string stmp = string("Invalid diversity assignment strategy: ") + diversityParam;
00122         throw std::runtime_error(stmp.c_str());
00123     }
00124     _state.storeFunctor(diversityAssignment);
00125 
00126 
00127     /* the comparator strategy */
00128     string & comparatorParam = _parser.createParam(string("FitnessThenDiversity"), "comparator",
00129                                "Comparator scheme: FitnessThenDiversity or DiversityThenFitness", 'C', "Evolution Engine").value();
00130     moeoComparator < MOEOT > * comparator;
00131     if (comparatorParam == string("FitnessThenDiversity"))
00132     {
00133         comparator = new moeoFitnessThenDiversityComparator < MOEOT> ();
00134     }
00135     else if (comparatorParam == string("DiversityThenFitness"))
00136     {
00137         comparator = new moeoDiversityThenFitnessComparator < MOEOT> ();
00138     }
00139     else
00140     {
00141         string stmp = string("Invalid comparator strategy: ") + comparatorParam;
00142         throw std::runtime_error(stmp.c_str());
00143     }
00144     _state.storeFunctor(comparator);
00145 
00146 
00147     /* the selection strategy */
00148     eoValueParam < eoParamParamType > & selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection",
00149             "Selection scheme: DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine");
00150     eoParamParamType & ppSelect = selectionParam.value();
00151     moeoSelectOne < MOEOT > * select;
00152     if (ppSelect.first == string("DetTour"))
00153     {
00154         unsigned tSize;
00155         if (!ppSelect.second.size()) // no parameter added
00156         {
00157             cerr << "WARNING, no parameter passed to DetTour, using 2" << endl;
00158             tSize = 2;
00159             // put back 2 in parameter for consistency (and status file)
00160             ppSelect.second.push_back(string("2"));
00161         }
00162         else // parameter passed by user as DetTour(T)
00163         {
00164             tSize = atoi(ppSelect.second[0].c_str());
00165         }
00166         select = new moeoDetTournamentSelect < MOEOT > (*comparator, tSize);
00167     }
00168     else if (ppSelect.first == string("StochTour"))
00169     {
00170         double tRate;
00171         if (!ppSelect.second.size()) // no parameter added
00172         {
00173             cerr << "WARNING, no parameter passed to StochTour, using 1" << endl;
00174             tRate = 1;
00175             // put back 1 in parameter for consistency (and status file)
00176             ppSelect.second.push_back(string("1"));
00177         }
00178         else // parameter passed by user as StochTour(T)
00179         {
00180             tRate = atof(ppSelect.second[0].c_str());
00181         }
00182         select = new moeoStochTournamentSelect < MOEOT > (*comparator, tRate);
00183     }
00184     else if (ppSelect.first == string("Roulette"))
00185     {
00186         // TO DO !
00187         // ...
00188     }
00189     else if (ppSelect.first == string("Random"))
00190     {
00191         select = new moeoRandomSelect <MOEOT > ();
00192     }
00193     else
00194     {
00195         string stmp = string("Invalid selection strategy: ") + ppSelect.first;
00196         throw std::runtime_error(stmp.c_str());
00197     }
00198     _state.storeFunctor(select);
00199 
00200 
00201     /* the replacement strategy */
00202     string & replacementParam = _parser.createParam(string("Elitist"), "replacement",
00203                                 "Replacement scheme: Elitist, Environmental or Generational", 'R', "Evolution Engine").value();
00204     moeoReplacement < MOEOT > * replace;
00205     if (replacementParam == string("Elitist"))
00206     {
00207         replace = new moeoElitistReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator);
00208     }
00209     else if (replacementParam == string("Environmental"))
00210     {
00211         replace = new moeoEnvironmentalReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator);
00212     }
00213     else if (replacementParam == string("Generational"))
00214     {
00215         replace = new moeoGenerationalReplacement < MOEOT> ();
00216     }
00217     else
00218     {
00219         string stmp = string("Invalid replacement strategy: ") + replacementParam;
00220         throw std::runtime_error(stmp.c_str());
00221     }
00222     _state.storeFunctor(replace);
00223 
00224 
00225     /* the number of offspring  */
00226     eoValueParam < eoHowMany > & offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring",
00227             "Number of offspring (percentage or absolute)", 'O', "Evolution Engine");
00228 
00229 
00230     // the general breeder
00231     eoGeneralBreeder < MOEOT > * breed = new eoGeneralBreeder < MOEOT > (*select, _op, offspringRateParam.value());
00232     _state.storeFunctor(breed);
00233     // the eoEasyEA
00234     moeoEA < MOEOT > * algo = new moeoEasyEA < MOEOT > (_continue, _eval, *breed, *replace, *fitnessAssignment, *diversityAssignment);
00235     _state.storeFunctor(algo);
00236     return *algo;
00237 
00238 }
00239 
00240 #endif /*MAKE_EA_MOEO_H_*/

Generated on Tue Apr 17 16:53:20 2007 for ParadisEO-MOEO by  doxygen 1.5.1