From 6ac423bf22c4e68014edcd6cabc1af3218321e46 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 20 Jun 2012 11:46:18 +0200 Subject: [PATCH] Adding eoEasyEA constructor allowing to precise which eoPopEvalFunc should be used --- eo/src/eoEasyEA.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/eo/src/eoEasyEA.h b/eo/src/eoEasyEA.h index 2c7c5474..4d74932f 100644 --- a/eo/src/eoEasyEA.h +++ b/eo/src/eoEasyEA.h @@ -102,6 +102,33 @@ 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, @@ -219,6 +246,8 @@ template class eoEasyEA: public eoAlgo /// Apply a few generation of evolution to the population. virtual void operator()(eoPop& _pop) { + + eo::log << "[EasyEA] Call to operator()" << std::endl; if (isFirstCall) { size_t total_capacity = _pop.capacity() + offspring.capacity(); @@ -227,22 +256,33 @@ template class eoEasyEA: public eoAlgo isFirstCall = false; } + // TODO TODOB delete all log traces + std::cout << "[EasyEA] After is first call." << std::endl; + eoPop empty_pop; + std::cout << "[EasyEA] After empty_pop." << std::endl; popEval(empty_pop, _pop); // A first eval of pop. + std::cout << "[EasyEA] After pop_eval." << std::endl; do { try { + std::cout << "[EasyEA] Beginning try." << std::endl; unsigned pSize = _pop.size(); + std::cout << "[EasyEA] psize determinated." << std::endl; offspring.clear(); // new offspring + std::cout << "[EasyEA] offspring cleared." << std::endl; breed(_pop, offspring); + std::cout << "[EasyEA] After breed, evaluating pop." << std::endl; popEval(_pop, offspring); // eval of parents + offspring if necessary + std::cout << "[EasyEA] After evaluation, replacing pop." << std::endl; replace(_pop, offspring); // after replace, the new pop. is in _pop + std::cout << "[EasyEA] After replacing, continuator." << std::endl; if (pSize > _pop.size()) throw std::runtime_error("Population shrinking!");