//----------------------------------------------------------------------------- // eoBreeder.h //----------------------------------------------------------------------------- #ifndef eoGopBreeder_h #define eoGopBreeder_h //----------------------------------------------------------------------------- /***************************************************************************** * eoBreeder: transforms a population using genetic operators. * * For every operator there is a rated to be applyed. * *****************************************************************************/ #include "eoPopOps.h" #include "eoGOpSelector.h" #include "eoIndiSelector.h" #include "eoBackInserter.h" template class eoGOpBreeder: public eoMonPopOp { public: /// Default constructor. eoGOpBreeder( eoGOpSelector& _opSel, eoPopIndiSelector& _selector) : opSel( _opSel ), selector(_selector) {} /// Destructor. virtual ~eoGOpBreeder() {} /** * Enlarges the population. * @param pop The population to be transformed. */ void operator()(eoPop& _pop) { unsigned size = _pop.size(); for (unsigned i = 0; i < size; i++) { // and the one liner opSel.selectOp()(selector.bind(_pop,size).bias(i), inserter.bind(_pop)); } } /// The class name. string className() const { return "eoGOpBreeder"; } private: eoGOpSelector& opSel; eoPopIndiSelector& selector; // the inserter can be local as there's no point in changing it from the outside eoBackInserter inserter; }; #endif eoBreeder_h