diff --git a/eo/src/eo b/eo/src/eo index b87ca57f1..8cebd23a0 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -78,7 +78,6 @@ #include #include #include -#include // Continuators - all include eoContinue.h #include @@ -103,7 +102,6 @@ #include // Embedding truncation selection #include -#include // the batch selection - from an eoSelectOne #include @@ -143,9 +141,6 @@ #include // includes eoRealBounds.h #include // no eoIntVectorBounds -// Serialization stuff -#include - // aliens #include #include diff --git a/eo/src/eoEasyEA.h b/eo/src/eoEasyEA.h index 4d9c7b6da..2c7c5474c 100644 --- a/eo/src/eoEasyEA.h +++ b/eo/src/eoEasyEA.h @@ -37,6 +37,8 @@ #include #include + + template class eoIslandsEasyEA ; template class eoDistEvalEasyEA ; @@ -100,33 +102,6 @@ template class eoEasyEA: public eoAlgo offspring.reserve(_offspringSize); // This line avoids an incremental resize of offsprings. } - /** - * @brief Ctor allowing to specify which pop eval function we're going to use. - * - * Ctor taking a breed and merge, an overload of ctor to define an offspring size, and - * the pop eval function used. This allows to precise if we would like to use the - * parallel evaluation, for instance. - */ - eoEasyEA( - eoContinue& _continuator, - eoEvalFunc& _eval, - eoPopEvalFunc& _pop_eval, - eoBreed& _breed, - eoReplacement& _replace, - unsigned _offspringSize - ) : continuator(_continuator), - eval (_eval), - loopEval(_eval), - popEval(_pop_eval), - selectTransform(dummySelect, dummyTransform), - breed(_breed), - mergeReduce(dummyMerge, dummyReduce), - replace(_replace), - isFirstCall(true) - { - offspring.reserve(_offspringSize); // This line avoids an incremental resize of offsprings. - } - /* eoEasyEA(eoContinue & _continuator, eoPopEvalFunc & _pop_eval, @@ -244,44 +219,45 @@ template class eoEasyEA: public eoAlgo /// Apply a few generation of evolution to the population. virtual void operator()(eoPop& _pop) { + if (isFirstCall) + { + size_t total_capacity = _pop.capacity() + offspring.capacity(); + _pop.reserve(total_capacity); + offspring.reserve(total_capacity); + isFirstCall = false; + } - if (isFirstCall) + eoPop empty_pop; + + popEval(empty_pop, _pop); // A first eval of pop. + + do { - size_t total_capacity = _pop.capacity() + offspring.capacity(); - _pop.reserve(total_capacity); - offspring.reserve(total_capacity); - isFirstCall = false; - } - - eoPop empty_pop; - - do - { - try + try { - unsigned pSize = _pop.size(); + unsigned pSize = _pop.size(); + offspring.clear(); // new offspring - offspring.clear(); // new offspring + breed(_pop, offspring); - breed(_pop, offspring); + popEval(_pop, offspring); // eval of parents + offspring if necessary - popEval(_pop, offspring); // eval of parents + offspring if necessary + replace(_pop, offspring); // after replace, the new pop. is in _pop - replace(_pop, offspring); // after replace, the new pop. is in _pop + if (pSize > _pop.size()) + throw std::runtime_error("Population shrinking!"); + else if (pSize < _pop.size()) + throw std::runtime_error("Population growing!"); - if (pSize > _pop.size()) - throw std::runtime_error("Population shrinking!"); - else if (pSize < _pop.size()) - throw std::runtime_error("Population growing!"); } - catch (std::exception& e) + catch (std::exception& e) { - std::string s = e.what(); - s.append( " in eoEasyEA"); - throw std::runtime_error( s ); + std::string s = e.what(); + s.append( " in eoEasyEA"); + throw std::runtime_error( s ); } } - while ( continuator( _pop ) ); + while ( continuator( _pop ) ); } protected :