From 3a409a789e55f997c3489c4c30dc796cb6881760 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Wed, 23 Mar 2011 17:34:35 +0100 Subject: [PATCH] * eoEasyEA: moved offspring into attributes space in order to avoid memory reallocation when we restart --- eo/src/eoEasyEA.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/eo/src/eoEasyEA.h b/eo/src/eoEasyEA.h index 4fc6d6e79..c058c2338 100644 --- a/eo/src/eoEasyEA.h +++ b/eo/src/eoEasyEA.h @@ -81,6 +81,25 @@ template class eoEasyEA: public eoAlgo replace(_replace) {} + /** Ctor taking a breed and merge, an overload of ctor to define an offspring size */ + eoEasyEA( + eoContinue& _continuator, + eoEvalFunc& _eval, + eoBreed& _breed, + eoReplacement& _replace, + unsigned _offspringSize + ) : continuator(_continuator), + eval (_eval), + loopEval(_eval), + popEval(loopEval), + selectTransform(dummySelect, dummyTransform), + breed(_breed), + mergeReduce(dummyMerge, dummyReduce), + replace(_replace) + { + offspring.reserve(_offspringSize); // This line avoids an incremental resize of offsprings. + } + /* eoEasyEA(eoContinue & _continuator, eoPopEvalFunc & _pop_eval, @@ -191,7 +210,7 @@ template class eoEasyEA: public eoAlgo /// Apply a few generation of evolution to the population. virtual void operator()(eoPop& _pop) { - eoPop offspring, empty_pop; + eoPop empty_pop; popEval(empty_pop, _pop); // A first eval of pop. @@ -270,6 +289,8 @@ template class eoEasyEA: public eoAlgo eoMergeReduce mergeReduce; eoReplacement& replace; + eoPop offspring; + // Friend classes friend class eoIslandsEasyEA ; friend class eoDistEvalEasyEA ;