EvolvingObjects
|
00001 00023 //----------------------------------------------------------------------------- 00024 00025 #ifndef _eoSelectPerc_h 00026 #define _eoSelectPerc_h 00027 00028 00029 //----------------------------------------------------------------------------- 00030 #include <eoSelect.h> 00031 #include <eoSelectOne.h> 00032 #include <math.h> 00033 //----------------------------------------------------------------------------- 00034 00043 template<class EOT> 00044 class eoSelectPerc : public eoSelect<EOT> 00045 { 00046 public: 00048 eoSelectPerc(eoSelectOne<EOT>& _select, float _rate = 1.0) 00049 : select(_select), rate(_rate) {} 00050 00057 virtual void operator()(const eoPop<EOT>& _source, eoPop<EOT>& _dest) 00058 { 00059 size_t target = static_cast<size_t>(floor(rate * _source.size())); 00060 00061 _dest.resize(target); 00062 00063 select.setup(_source); 00064 00065 for (size_t i = 0; i < _dest.size(); ++i) 00066 _dest[i] = select(_source); 00067 } 00068 00069 private : 00070 eoSelectOne<EOT>& select; 00071 float rate; 00072 }; 00073 00074 #endif