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 eoOneToOneBreeder_h
00027 #define eoOneToOneBreeder_h
00028
00029
00030
00031 #include <eoOp.h>
00032 #include <eoGenOp.h>
00033 #include <eoPopulator.h>
00034 #include <eoSelectOne.h>
00035 #include <eoSequentialSelect.h>
00036 #include <eoBreed.h>
00037 #include <eoEvalFunc.h>
00038 #include <eoPopulator.h>
00039 #include <utils/eoHowMany.h>
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 template<class EOT>
00052 class eoOneToOneBreeder: public eoBreed<EOT>
00053 {
00054 public:
00062 eoOneToOneBreeder(
00063 eoGenOp<EOT>& _op,
00064 eoEvalFunc<EOT> & _eval,
00065 double _pReplace = 1.0,
00066 eoHowMany _howMany = eoHowMany(1.0) ) :
00067 op(_op), eval(_eval), select( false ),
00068 pReplace(_pReplace), howMany(_howMany) {}
00069
00070
00078 void operator()(const eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
00079 {
00080 unsigned target = howMany(_parents.size());
00081
00082 _offspring.clear();
00083 eoSelectivePopulator<EOT> popit(_parents, _offspring, select);
00084
00085 for (unsigned iParent=0; iParent<target; iParent++)
00086 {
00087 unsigned pos = popit.tellp();
00088 EOT theParent = *popit;
00089
00090
00091 op(popit);
00092
00093
00094 EOT & leOffspring = *popit;
00095
00096
00097 unsigned posEnd = popit.tellp();
00098 if (posEnd != pos)
00099 throw std::runtime_error("Operator can only generate a SINGLE offspring in eoOneToOneBreeder");
00100
00101
00102 eval(leOffspring);
00103 if (theParent > leOffspring)
00104 if (rng.uniform() < pReplace)
00105 leOffspring = theParent;
00106
00107 ++popit;
00108 }
00109 }
00110
00112 virtual std::string className() const { return "eoOneToOneBreeder"; }
00113
00114 private:
00115 eoGenOp<EOT>& op;
00116 eoEvalFunc<EOT> & eval;
00117 eoSequentialSelect<EOT> select;
00118 double pReplace;
00119 eoHowMany howMany;
00120 };
00121
00122 #endif
00123