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 #ifndef _eoEasyEA_h
00026 #define _eoEasyEA_h
00027
00028
00029
00030 #include <apply.h>
00031 #include <eoAlgo.h>
00032 #include <eoPopAlgo.h>
00033 #include <eoPopEvalFunc.h>
00034 #include <eoContinue.h>
00035 #include <eoSelect.h>
00036 #include <eoTransform.h>
00037 #include <eoBreed.h>
00038 #include <eoMergeReduce.h>
00039 #include <eoReplacement.h>
00040
00041
00042
00043 template <class EOT> class eoIslandsEasyEA ;
00044
00045 template <class EOT> class eoDistEvalEasyEA ;
00046
00063 template<class EOT> class eoEasyEA: public eoAlgo<EOT>
00064 {
00065 public:
00066
00068 eoEasyEA(
00069 eoContinue<EOT>& _continuator,
00070 eoEvalFunc<EOT>& _eval,
00071 eoBreed<EOT>& _breed,
00072 eoReplacement<EOT>& _replace
00073 ) : continuator(_continuator),
00074 eval (_eval),
00075 loopEval(_eval),
00076 popEval(loopEval),
00077 selectTransform(dummySelect, dummyTransform),
00078 breed(_breed),
00079 mergeReduce(dummyMerge, dummyReduce),
00080 replace(_replace)
00081 {}
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00102 eoEasyEA(
00103 eoContinue<EOT>& _continuator,
00104 eoPopEvalFunc<EOT>& _eval,
00105 eoBreed<EOT>& _breed,
00106 eoReplacement<EOT>& _replace
00107 ) : continuator(_continuator),
00108 eval (dummyEval),
00109 loopEval(dummyEval),
00110 popEval(_eval),
00111 selectTransform(dummySelect, dummyTransform),
00112 breed(_breed),
00113 mergeReduce(dummyMerge, dummyReduce),
00114 replace(_replace)
00115 {}
00116
00117
00119 eoEasyEA(
00120 eoContinue<EOT>& _continuator,
00121 eoPopEvalFunc<EOT>& _eval,
00122 eoSelect<EOT>& _select,
00123 eoTransform<EOT>& _transform,
00124 eoReplacement<EOT>& _replace
00125 ) : continuator(_continuator),
00126 eval (dummyEval),
00127 loopEval(dummyEval),
00128 popEval(_eval),
00129 selectTransform(_select, _transform),
00130 breed(selectTransform),
00131 mergeReduce(dummyMerge, dummyReduce),
00132 replace(_replace)
00133 {}
00134
00136 eoEasyEA(
00137 eoContinue<EOT>& _continuator,
00138 eoEvalFunc<EOT>& _eval,
00139 eoBreed<EOT>& _breed,
00140 eoMerge<EOT>& _merge,
00141 eoReduce<EOT>& _reduce
00142 ) : continuator(_continuator),
00143 eval (_eval),
00144 loopEval(_eval),
00145 popEval(loopEval),
00146 selectTransform(dummySelect, dummyTransform),
00147 breed(_breed),
00148 mergeReduce(_merge, _reduce),
00149 replace(mergeReduce)
00150 {}
00151
00153 eoEasyEA(
00154 eoContinue<EOT>& _continuator,
00155 eoEvalFunc<EOT>& _eval,
00156 eoSelect<EOT>& _select,
00157 eoTransform<EOT>& _transform,
00158 eoReplacement<EOT>& _replace
00159 ) : continuator(_continuator),
00160 eval (_eval),
00161 loopEval(_eval),
00162 popEval(loopEval),
00163 selectTransform(_select, _transform),
00164 breed(selectTransform),
00165 mergeReduce(dummyMerge, dummyReduce),
00166 replace(_replace)
00167 {}
00168
00170 eoEasyEA(
00171 eoContinue<EOT>& _continuator,
00172 eoEvalFunc<EOT>& _eval,
00173 eoSelect<EOT>& _select,
00174 eoTransform<EOT>& _transform,
00175 eoMerge<EOT>& _merge,
00176 eoReduce<EOT>& _reduce
00177 ) : continuator(_continuator),
00178 eval (_eval),
00179 loopEval(_eval),
00180 popEval(loopEval),
00181 selectTransform(_select, _transform),
00182 breed(selectTransform),
00183 mergeReduce(_merge, _reduce),
00184 replace(mergeReduce)
00185 {}
00186
00187
00188
00189
00191 virtual void operator()(eoPop<EOT>& _pop)
00192 {
00193 eoPop<EOT> offspring, empty_pop;
00194
00195 popEval(empty_pop, _pop);
00196
00197 do
00198 {
00199 try
00200 {
00201 unsigned pSize = _pop.size();
00202 offspring.clear();
00203
00204 breed(_pop, offspring);
00205
00206 popEval(_pop, offspring);
00207
00208 replace(_pop, offspring);
00209
00210 if (pSize > _pop.size())
00211 throw std::runtime_error("Population shrinking!");
00212 else if (pSize < _pop.size())
00213 throw std::runtime_error("Population growing!");
00214
00215 }
00216 catch (std::exception& e)
00217 {
00218 std::string s = e.what();
00219 s.append( " in eoEasyEA");
00220 throw std::runtime_error( s );
00221 }
00222 }
00223 while ( continuator( _pop ) );
00224 }
00225
00226 protected :
00227
00228
00229
00230 class eoDummySelect : public eoSelect<EOT>
00231 {
00232 public :
00233 void operator()(const eoPop<EOT>&, eoPop<EOT>&)
00234 {}
00235 }
00236 dummySelect;
00237
00238 class eoDummyTransform : public eoTransform<EOT>
00239 {
00240 public :
00241 void operator()(eoPop<EOT>&)
00242 {}
00243 }
00244 dummyTransform;
00245
00246 class eoDummyEval : public eoEvalFunc<EOT>
00247 {
00248 public:
00249 void operator()(EOT &)
00250 {}
00251 }
00252 dummyEval;
00253
00254 eoContinue<EOT>& continuator;
00255
00256 eoEvalFunc <EOT> & eval ;
00257 eoPopLoopEval<EOT> loopEval;
00258
00259 eoPopEvalFunc<EOT>& popEval;
00260
00261 eoSelectTransform<EOT> selectTransform;
00262 eoBreed<EOT>& breed;
00263
00264
00265
00266 eoNoElitism<EOT> dummyMerge;
00267 eoTruncate<EOT> dummyReduce;
00268
00269 eoMergeReduce<EOT> mergeReduce;
00270 eoReplacement<EOT>& replace;
00271
00272
00273 friend class eoIslandsEasyEA <EOT> ;
00274 friend class eoDistEvalEasyEA <EOT> ;
00275 };
00276
00277
00278
00279 #endif
00280