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 #ifndef eoGeneralBreeder_h
00027 #define eoGeneralBreeder_h
00028
00029
00030
00031
00032
00033
00034
00035 #include <eoOp.h>
00036 #include <eoGenOp.h>
00037 #include <eoPopulator.h>
00038 #include <eoSelectOne.h>
00039 #include <eoBreed.h>
00040 #include <utils/eoHowMany.h>
00041
00045 template<class EOT>
00046 class eoGeneralBreeder: public eoBreed<EOT>
00047 {
00048 public:
00056 eoGeneralBreeder(
00057 eoSelectOne<EOT>& _select,
00058 eoGenOp<EOT>& _op,
00059 double _rate=1.0,
00060 bool _interpret_as_rate = true) :
00061 select( _select ), op(_op), howMany(_rate, _interpret_as_rate) {}
00062
00069 eoGeneralBreeder(
00070 eoSelectOne<EOT>& _select,
00071 eoGenOp<EOT>& _op,
00072 eoHowMany _howMany ) :
00073 select( _select ), op(_op), howMany(_howMany) {}
00074
00080 void operator()(const eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
00081 {
00082 unsigned target = howMany(_parents.size());
00083
00084 _offspring.clear();
00085 eoSelectivePopulator<EOT> it(_parents, _offspring, select);
00086
00087 while (_offspring.size() < target)
00088 {
00089 op(it);
00090 ++it;
00091 }
00092
00093 _offspring.resize(target);
00094 }
00095
00097 virtual std::string className() const { return "eoGeneralBreeder"; }
00098
00099 private:
00100 eoSelectOne<EOT>& select;
00101 eoGenOp<EOT>& op;
00102 eoHowMany howMany;
00103 };
00104
00105 #endif
00106