diff --git a/eo/src/eoReduce.h b/eo/src/eoReduce.h index 715a412c..a653f8ef 100644 --- a/eo/src/eoReduce.h +++ b/eo/src/eoReduce.h @@ -60,6 +60,22 @@ template class eoTruncate : public eoReduce } }; +/** random truncation */ +template class eoRandomReduce : public eoReduce +{ + void operator()(eoPop& _newgen, unsigned _newsize) + { + if (_newgen.size() == _newsize) + return; + if (_newgen.size() < _newsize) + throw std::logic_error("eoRandomReduce: Cannot truncate to a larger size!\n"); + + // shuffle the population, then trucate + _newgen.shuffle(); + _newgen.resize(_newsize); + } +}; + /** EP truncation method (some global stochastic tournament + sort) Softer selective pressure than pure truncate