00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _make_general_replacement_h
00028 #define _make_general_replacement_h
00029
00030 #include <utils/eoData.h>
00031
00032
00033 #include <eoReduceMergeReduce.h>
00034
00035
00036 #include <utils/eoParser.h>
00037 #include <utils/eoState.h>
00038
00039
00043 template <class EOT>
00044 eoReduce<EOT> & decode_reduce(eoParamParamType & _ppReduce, eoState & _state)
00045 {
00046 unsigned int detSize;
00047 eoReduce<EOT> * ptReduce;
00048
00049
00050 if ( (_ppReduce.first == std::string("Deterministic")) ||
00051 (_ppReduce.first == std::string("Sequential"))
00052 )
00053 {
00054 ptReduce = new eoTruncate<EOT>;
00055 }
00056
00057 else if (_ppReduce.first == std::string("EP"))
00058 {
00059 if (!_ppReduce.second.size())
00060 {
00061 std::cerr << "WARNING, no parameter passed to EP, using 6" << std::endl;
00062 detSize = 6;
00063
00064 _ppReduce.second.push_back(std::string("6"));
00065 }
00066 else
00067 detSize = atoi(_ppReduce.second[0].c_str());
00068 ptReduce = new eoEPReduce<EOT>(detSize);
00069 }
00070
00071 else if (_ppReduce.first == std::string("DetTour"))
00072 {
00073 if (!_ppReduce.second.size())
00074 {
00075 std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl;
00076 detSize = 2;
00077
00078 _ppReduce.second.push_back(std::string("2"));
00079 }
00080 else
00081 detSize = atoi(_ppReduce.second[0].c_str());
00082 ptReduce = new eoDetTournamentTruncate<EOT>(detSize);
00083 }
00084 else if (_ppReduce.first == std::string("StochTour"))
00085 {
00086 double p;
00087 if (!_ppReduce.second.size())
00088 {
00089 std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl;
00090 p = 1;
00091
00092 _ppReduce.second.push_back(std::string("1"));
00093 }
00094 else
00095 {
00096 p = atof(_ppReduce.second[0].c_str());
00097 if ( (p<=0.5) || (p>1) )
00098 throw std::runtime_error("Stochastic tournament size should be in [0.5,1]");
00099 }
00100
00101 ptReduce = new eoStochTournamentTruncate<EOT>(p);
00102 }
00103 else if ( (_ppReduce.first == std::string("Uniform")) ||
00104 (_ppReduce.first == std::string("Random"))
00105 )
00106 {
00107 ptReduce = new eoRandomReduce<EOT>;
00108 }
00109 else
00110 {
00111 throw std::runtime_error("Unknown reducer: " + _ppReduce.first);
00112 }
00113
00114 _state.storeFunctor(ptReduce);
00115 return (*ptReduce);
00116 }
00117
00134 template <class EOT>
00135 eoReplacement<EOT> & make_general_replacement(
00136 eoParser& _parser, eoState& _state,
00137 eoHowMany _elite = eoHowMany(0),
00138 bool _strongElitism = false,
00139 eoHowMany _surviveParents = eoHowMany(0.0),
00140 eoParamParamType & _reduceParentType = eoParamParamType("Deterministic"),
00141 eoHowMany _surviveOffspring = eoHowMany(1.0),
00142 eoParamParamType & _reduceOffspringType = eoParamParamType("Deterministic"),
00143 eoParamParamType & _reduceFinalType = eoParamParamType("Deterministic")
00144 )
00145 {
00147
00149
00150
00151 eoHowMany elite = _parser.createParam(_elite, "elite", "Nb of elite parents (percentage or absolute)", '\0', "Evolution Engine / Replacement").value();
00152
00153 bool strongElitism = _parser.createParam(_strongElitism,"eliteType", "Strong (true) or weak (false) elitism (set elite to 0 for none)", '\0', "Evolution Engine / Replacement").value();
00154
00155
00156 eoHowMany surviveParents = _parser.createParam(_surviveParents, "surviveParents", "Nb of surviving parents (percentage or absolute)", '\0', "Evolution Engine / Replacement").value();
00157
00158 eoParamParamType & reduceParentType = _parser.createParam(_reduceParentType, "reduceParents", "Parents reducer: Deterministic, EP(T), DetTour(T), StochTour(t), Uniform", '\0', "Evolution Engine / Replacement").value();
00159
00160 eoReduce<EOT> & reduceParent = decode_reduce<EOT>(reduceParentType, _state);
00161
00162
00163 eoHowMany surviveOffspring = _parser.createParam(_surviveOffspring, "surviveOffspring", "Nb of surviving offspring (percentage or absolute)", '\0', "Evolution Engine / Replacement").value();
00164
00165 eoParamParamType & reduceOffspringType = _parser.createParam(_reduceOffspringType, "reduceOffspring", "Offspring reducer: Deterministic, EP(T), DetTour(T), StochTour(t), Uniform", '\0', "Evolution Engine / Replacement").value();
00166
00167 eoReduce<EOT> & reduceOffspring = decode_reduce<EOT>(reduceOffspringType, _state);
00168
00169 eoParamParamType & reduceFinalType = _parser.createParam(_reduceFinalType, "reduceFinal", "Final reducer: Deterministic, EP(T), DetTour(T), StochTour(t), Uniform", '\0', "Evolution Engine / Replacement").value();
00170
00171 eoReduce<EOT> & reduceFinal = decode_reduce<EOT>(reduceFinalType, _state);
00172
00173
00174 eoReduceMergeReduce<EOT> *ptReplace = new eoReduceMergeReduce<EOT>(elite, strongElitism, surviveParents, reduceParent, surviveOffspring, reduceOffspring, reduceFinal);
00175 _state.storeFunctor(ptReplace);
00176
00177
00178 return *ptReplace;
00179 }
00180
00181 #endif