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 public:
00065
00067 eoEasyEA(
00068 eoContinue<EOT>& _continuator,
00069 eoEvalFunc<EOT>& _eval,
00070 eoBreed<EOT>& _breed,
00071 eoReplacement<EOT>& _replace
00072 ) : continuator(_continuator),
00073 eval (_eval),
00074 loopEval(_eval),
00075 popEval(loopEval),
00076 selectTransform(dummySelect, dummyTransform),
00077 breed(_breed),
00078 mergeReduce(dummyMerge, dummyReduce),
00079 replace(_replace)
00080 {}
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00101 eoEasyEA(
00102 eoContinue<EOT>& _continuator,
00103 eoPopEvalFunc<EOT>& _eval,
00104 eoBreed<EOT>& _breed,
00105 eoReplacement<EOT>& _replace
00106 ) : continuator(_continuator),
00107 eval (dummyEval),
00108 loopEval(dummyEval),
00109 popEval(_eval),
00110 selectTransform(dummySelect, dummyTransform),
00111 breed(_breed),
00112 mergeReduce(dummyMerge, dummyReduce),
00113 replace(_replace)
00114 {}
00115
00117 eoEasyEA(
00118 eoContinue<EOT>& _continuator,
00119 eoEvalFunc<EOT>& _eval,
00120 eoBreed<EOT>& _breed,
00121 eoMerge<EOT>& _merge,
00122 eoReduce<EOT>& _reduce
00123 ) : continuator(_continuator),
00124 eval (_eval),
00125 loopEval(_eval),
00126 popEval(loopEval),
00127 selectTransform(dummySelect, dummyTransform),
00128 breed(_breed),
00129 mergeReduce(_merge, _reduce),
00130 replace(mergeReduce)
00131 {}
00132
00134 eoEasyEA(
00135 eoContinue<EOT>& _continuator,
00136 eoEvalFunc<EOT>& _eval,
00137 eoSelect<EOT>& _select,
00138 eoTransform<EOT>& _transform,
00139 eoReplacement<EOT>& _replace
00140 ) : continuator(_continuator),
00141 eval (_eval),
00142 loopEval(_eval),
00143 popEval(loopEval),
00144 selectTransform(_select, _transform),
00145 breed(selectTransform),
00146 mergeReduce(dummyMerge, dummyReduce),
00147 replace(_replace)
00148 {}
00149
00151 eoEasyEA(
00152 eoContinue<EOT>& _continuator,
00153 eoEvalFunc<EOT>& _eval,
00154 eoSelect<EOT>& _select,
00155 eoTransform<EOT>& _transform,
00156 eoMerge<EOT>& _merge,
00157 eoReduce<EOT>& _reduce
00158 ) : continuator(_continuator),
00159 eval (_eval),
00160 loopEval(_eval),
00161 popEval(loopEval),
00162 selectTransform(_select, _transform),
00163 breed(selectTransform),
00164 mergeReduce(_merge, _reduce),
00165 replace(mergeReduce)
00166 {}
00167
00168
00169
00170
00172 virtual void operator()(eoPop<EOT>& _pop)
00173 {
00174 eoPop<EOT> offspring, empty_pop;
00175 popEval(empty_pop, _pop);
00176 do
00177 {
00178 try
00179 {
00180 unsigned pSize = _pop.size();
00181 offspring.clear();
00182
00183 breed(_pop, offspring);
00184
00185 popEval(_pop, offspring);
00186
00187 replace(_pop, offspring);
00188
00189 if (pSize > _pop.size())
00190 throw std::runtime_error("Population shrinking!");
00191 else if (pSize < _pop.size())
00192 throw std::runtime_error("Population growing!");
00193
00194 }
00195 catch (std::exception& e)
00196 {
00197 std::string s = e.what();
00198 s.append( " in eoEasyEA");
00199 throw std::runtime_error( s );
00200 }
00201 } while ( continuator( _pop ) );
00202 }
00203
00204 protected :
00205
00206
00207
00208 class eoDummySelect : public eoSelect<EOT>
00209 { public : void operator()(const eoPop<EOT>&, eoPop<EOT>&) {} } dummySelect;
00210
00211 class eoDummyTransform : public eoTransform<EOT>
00212 { public : void operator()(eoPop<EOT>&) {} } dummyTransform;
00213
00214 class eoDummyEval : public eoEvalFunc<EOT>
00215 {public: void operator()(EOT &) {} } dummyEval;
00216
00217 eoContinue<EOT>& continuator;
00218
00219 eoEvalFunc <EOT> & eval ;
00220 eoPopLoopEval<EOT> loopEval;
00221
00222 eoPopEvalFunc<EOT>& popEval;
00223
00224 eoSelectTransform<EOT> selectTransform;
00225 eoBreed<EOT>& breed;
00226
00227
00228
00229 eoNoElitism<EOT> dummyMerge;
00230 eoTruncate<EOT> dummyReduce;
00231
00232 eoMergeReduce<EOT> mergeReduce;
00233 eoReplacement<EOT>& replace;
00234
00235
00236 friend class eoIslandsEasyEA <EOT> ;
00237 friend class eoDistEvalEasyEA <EOT> ;
00238 };
00239
00240
00241
00242 #endif
00243