00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _make_algo_MOEO_h
00014 #define _make_algo_MOEO_h
00015
00016
00017 #include "utils/eoParser.h"
00018 #include "utils/eoState.h"
00019
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
00028 #include "eoReplacement.h"
00029 #include "moeoReplacement.h"
00030
00031 #include "eoGeneralBreeder.h"
00032
00033 #include "eoEasyEA.h"
00034
00035
00036
00037
00038
00039
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
00050 typedef typename EOT::Fitness EOFitness;
00051
00052
00053
00054
00055
00056
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
00075 eoPerf2Worth < EOT, double >*p2w;
00076 if ((selStr == string ("NSGA")) || (selStr == string ("NSGA-I")))
00077 p2w = new eoNDSorting_I < EOT > (nicheSize);
00078 else if (selStr == string ("NSGA-II"))
00079 p2w = new eoNDSorting_II < EOT > ();
00080 else if (selStr == string ("IBEA"))
00081 {
00082
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 {
00098 eoDominanceMap < EOT > &dominance =
00099 _state.storeFunctor (new eoDominanceMap < EOT >);
00100 p2w = new eoParetoRanking < EOT > (dominance);
00101 }
00102 else if (selStr == string ("ParetoSharing"))
00103 {
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
00112 _state.storeFunctor (p2w);
00113
00114
00115
00116
00117
00118
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 ();
00124
00125 eoSelectOne < EOT > *select;
00126 if (ppSelect.first == string ("DetTour"))
00127 {
00128 unsigned detSize;
00129 if (!ppSelect.second.size ())
00130 {
00131 cerr << "WARNING, no parameter passed to DetTour, using 2" << endl;
00132 detSize = 2;
00133
00134 ppSelect.second.push_back (string ("2"));
00135 }
00136 else
00137 detSize = atoi (ppSelect.second[0].c_str ());
00138 select = new eoDetTournamentWorthSelect < EOT > (*p2w, detSize);
00139 }
00140 else if (ppSelect.first == string ("StochTour"))
00141 {
00142 double p;
00143 if (!ppSelect.second.size ())
00144 {
00145 cerr << "WARNING, no parameter passed to StochTour, using 1" <<
00146 endl;
00147 p = 1;
00148
00149 ppSelect.second.push_back (string ("1"));
00150 }
00151 else
00152 p = atof (ppSelect.second[0].c_str ());
00153 select = new eoStochTournamentWorthSelect < EOT > (*p2w, p);
00154 }
00155 else if (ppSelect.first == string ("Roulette"))
00156 {
00157 select = new eoRouletteWorthSelect < EOT > (*p2w);
00158 }
00159 else if (ppSelect.first == string ("Random"))
00160 {
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
00169 _state.storeFunctor (select);
00170
00171
00172
00173
00174
00175
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
00190 _state.storeFunctor (select);
00191 }
00192
00193
00194
00195
00196
00197
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
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"))
00214 {
00215 replace = new moeoElitistReplacement < EOT, double >(*p2w);
00216 }
00217 else if (repStr == string ("DistinctPlus"))
00218 {
00219 replace = new moeoDisctinctElitistReplacement < EOT, double >(*p2w);
00220 }
00221 else if (repStr == string ("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
00231 _state.storeFunctor (replace);
00232
00233
00234
00235
00236
00237
00238 eoGeneralBreeder < EOT > *breed =
00239 new eoGeneralBreeder < EOT > (*select, _op, offspringRateParam.value ());
00240 _state.storeFunctor (breed);
00241
00242
00243 eoAlgo < EOT > *algo =
00244 new eoEasyEA < EOT > (_continue, _eval, *breed, *replace);
00245 _state.storeFunctor (algo);
00246
00247 return *algo;
00248 }
00249
00250 #endif