00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _eoCombinedOp_H
00025 #define _eoCombinedOp_H
00026
00027 #include <eoObject.h>
00028 #include <eoPrintable.h>
00029 #include <eoFunctor.h>
00030 #include <eoOp.h>
00031 #include <utils/eoRNG.h>
00048
00049
00050
00051
00057 template <class EOT>
00058 class eoPropCombinedMonOp: public eoMonOp<EOT>
00059 {
00060 public:
00062 eoPropCombinedMonOp(eoMonOp<EOT> & _first, const double _rate)
00063 {
00064 ops.push_back(&_first);
00065 rates.push_back(_rate);
00066 }
00067
00068 virtual std::string className() const { return "eoPropCombinedMonOp"; }
00069
00070 virtual void add(eoMonOp<EOT> & _op, const double _rate, bool _verbose=false)
00071 {
00072 ops.push_back(&_op);
00073 rates.push_back(_rate);
00074
00075 if (_verbose)
00076 printOn(std::cout);
00077 }
00078
00079
00080 virtual void printOn(std::ostream & _os)
00081 {
00082 double total = 0;
00083 unsigned i;
00084 for (i=0; i<ops.size(); i++)
00085 total += rates[i];
00086 _os << "In " << className() << "\n" ;
00087 for (i=0; i<ops.size(); i++)
00088 _os << ops[i]->className() << " with rate " << 100*rates[i]/total << " %\n";
00089 }
00090
00091 virtual bool operator()(EOT & _indi)
00092 {
00093 unsigned what = rng.roulette_wheel(rates);
00094 return (*ops[what])(_indi);
00095 }
00096 protected:
00097 std::vector<eoMonOp<EOT>*> ops;
00098 std::vector<double> rates;
00099 };
00100
00104
00108 template <class EOT>
00109 class eoPropCombinedBinOp: public eoBinOp<EOT>
00110 {
00111 public:
00113 eoPropCombinedBinOp(eoBinOp<EOT> & _first, const double _rate)
00114 {
00115 ops.push_back(&_first);
00116 rates.push_back(_rate);
00117 }
00118
00119 virtual std::string className() const { return "eoPropCombinedBinOp"; }
00120
00121 virtual void add(eoBinOp<EOT> & _op, const double _rate, bool _verbose=false)
00122 {
00123 ops.push_back(&_op);
00124 rates.push_back(_rate);
00125
00126 if (_verbose)
00127 {
00128 double total = 0;
00129 unsigned i;
00130 for (i=0; i<ops.size(); i++)
00131 total += rates[i];
00132 std::cout << "In " << className() << "\n" ;
00133 for (i=0; i<ops.size(); i++)
00134 std::cout << ops[i]->className() << " with rate " << 100*rates[i]/total << " %\n";
00135 }
00136 }
00137
00138 virtual void operator()(EOT & _indi1, const EOT & _indi2)
00139 {
00140 unsigned what = rng.roulette_wheel(rates);
00141 return (*ops[what])(_indi1, _indi2);
00142 }
00143 private:
00144 std::vector<eoBinOp<EOT>*> ops;
00145 std::vector<double> rates;
00146 };
00147
00148
00152
00162 template <class EOT>
00163 class eoPropCombinedQuadOp: public eoQuadOp<EOT>
00164 {
00165 public:
00167 eoPropCombinedQuadOp(eoQuadOp<EOT> & _first, const double _rate)
00168 {
00169 ops.push_back(&_first);
00170 rates.push_back(_rate);
00171 }
00172
00173 virtual std::string className() const { return "eoPropCombinedQuadOp"; }
00174
00175
00176 virtual void add(eoQuadOp<EOT> & _op, const double _rate, bool _verbose=false)
00177 {
00178 ops.push_back(&_op);
00179 rates.push_back(_rate);
00180
00181 if (_verbose)
00182 printOn(std::cout);
00183 }
00184
00185
00186 virtual void printOn(std::ostream & _os)
00187 {
00188 double total = 0;
00189 unsigned i;
00190 for (i=0; i<ops.size(); i++)
00191 total += rates[i];
00192 _os << "In " << className() << "\n" ;
00193 for (i=0; i<ops.size(); i++)
00194 _os << ops[i]->className() << " with rate " << 100*rates[i]/total << " %\n";
00195 }
00196
00197 virtual bool operator()(EOT & _indi1, EOT & _indi2)
00198 {
00199 unsigned what = rng.roulette_wheel(rates);
00200 return (*ops[what])(_indi1, _indi2);
00201 }
00202 private:
00203 std::vector<eoQuadOp<EOT>*> ops;
00204 std::vector<double> rates;
00205 };
00206
00207
00208
00209 #endif
00210