From ce031f10a3a371f3687009ebfc3dc779d0e66900 Mon Sep 17 00:00:00 2001 From: evomarc Date: Fri, 26 Jan 2001 04:06:09 +0000 Subject: [PATCH] Added eoRandomReduce --- eo/src/eoReduce.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/eo/src/eoReduce.h b/eo/src/eoReduce.h index 715a412c0..a653f8ef2 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