//----------------------------------------------------------------------------- // eoInclusion.h //----------------------------------------------------------------------------- #ifndef eoInclusion_h #define eoInclusion_h //----------------------------------------------------------------------------- #include // EO includes #include #include /***************************************************************************** * eoInclusion: A replacement algorithm. * * Creates a new population by selecting the best individuals from the * * breeders and original populations * *****************************************************************************/ template class eoInclusion: public eoMerge { public: /// (Default) Constructor. eoInclusion(const float& _rate = 1.0): eoMerge( _rate ) {} /// Ctor from istream eoInclusion( istream& _is): eoBinPopOp( _is ) {}; /// Dtor virtual ~eoInclusion() {}; /** * Creates a new population based on breeders and original populations. * @param breeders The population of breeders. * @param pop The original population. */ void operator()(eoPop& breeders, eoPop& pop) { unsigned target = min(static_cast(rint(pop.size() * rate())), pop.size() + breeders.size()); copy(breeders.begin(), breeders.end(), back_insert_iterator >(pop)); partial_sort(pop.begin(), pop.begin() + target, pop.end(), greater()); pop.erase(pop.begin() + target, pop.end()); } /** @name Methods from eoObject */ //@{ /** readFrom and printOn inherited from eoMerge */ /** Inherited from eoObject. Returns the class name. @see eoObject */ virtual string className() const {return "eoMerge";}; //@} }; //----------------------------------------------------------------------------- #endif eoInclusion_h