From 348da5c52cb20996155e949ff2ee0099a4270b2a Mon Sep 17 00:00:00 2001 From: jhumeau Date: Wed, 14 Oct 2009 09:44:06 +0000 Subject: [PATCH] Constructor revised git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1614 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-moeo/src/algo/moeoASEEA.h | 34 +++++++++++-------- .../src/selection/moeoDetArchiveSelect.h | 8 +++-- trunk/paradiseo-moeo/test/t-moeoASEEA.cpp | 17 +++++++--- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/trunk/paradiseo-moeo/src/algo/moeoASEEA.h b/trunk/paradiseo-moeo/src/algo/moeoASEEA.h index f9241c7df..146b4c68d 100644 --- a/trunk/paradiseo-moeo/src/algo/moeoASEEA.h +++ b/trunk/paradiseo-moeo/src/algo/moeoASEEA.h @@ -76,7 +76,7 @@ public: * @param _max the max size for the pop */ moeoASEEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, moeoArchive < MOEOT > & _archive, unsigned int _max) : - defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), selectMany(_archive, _max), selectTransform(defaultSelect, defaultTransform), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), breed (selectTransform), archive(_archive) + defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), selectMany(_archive, _max), transform(_crossover, _pCross, _mutation, _pMut), selectTransform(selectMany, transform), breed (selectTransform), archive(_archive) {} @@ -84,11 +84,15 @@ public: * Ctor with a eoContinue. * @param _continuator stopping criteria * @param _eval evaluation function + * @param _crossover crossover + * @param _pCross crossover probability + * @param _mutation mutation + * @param _pMut mutation probability * @param _archive archive * @param _max the max size for the pop */ - moeoASEEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, moeoArchive < MOEOT > & _archive, unsigned int _max) : - defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), selectMany(_archive, _max), selectTransform(defaultSelect, defaultTransform), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), breed(selectTransform), archive(_archive) + moeoASEEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, moeoArchive < MOEOT > & _archive, unsigned int _max) : + defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), selectMany(_archive, _max), transform(_crossover, _pCross, _mutation, _pMut), selectTransform(selectMany, transform), breed(selectTransform), archive(_archive) {} @@ -96,11 +100,15 @@ public: * Ctor with a eoContinue, a eoPopEval. * @param _continuator stopping criteria * @param _popEval population evaluation function + * @param _crossover crossover + * @param _pCross crossover probability + * @param _mutation mutation + * @param _pMut mutation probability * @param _archive archive * @param _max the max size for the pop */ - moeoASEEA (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, moeoArchive < MOEOT > & _archive, unsigned int _max) : - defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval), selectMany(_archive, _max), selectTransform(defaultSelect, defaultTransform), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), breed(selectTransform), archive(_archive) + moeoASEEA (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, moeoArchive < MOEOT > & _archive, unsigned int _max) : + defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval), selectMany(_archive, _max), transform(_crossover, _pCross, _mutation, _pMut), selectTransform(selectMany, transform), breed(selectTransform), archive(_archive) {} @@ -113,7 +121,7 @@ public: * @param _max the max size for the pop */ moeoASEEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _transform, moeoArchive < MOEOT > & _archive, unsigned int _max) : - defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), selectMany(_archive, _max), selectTransform(selectMany, _transform), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), breed(selectTransform), archive(_archive) + defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), selectMany(_archive, _max), transform(defaultQuadOp, 0.0, defaultMonOp, 0.0), selectTransform(selectMany, _transform), breed(selectTransform), archive(_archive) {} @@ -126,7 +134,7 @@ public: * @param _max the max size for the pop */ moeoASEEA (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoTransform < MOEOT > & _transform, moeoArchive < MOEOT > & _archive, unsigned int _max) : - defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval), selectMany(_archive, _max), selectTransform(selectMany, _transform), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), breed(selectTransform), archive(_archive) + defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval), selectMany(_archive, _max), transform(defaultQuadOp, 0.0, defaultMonOp, 0.0), selectTransform(selectMany, _transform), breed(selectTransform), archive(_archive) {} @@ -159,12 +167,6 @@ protected: void operator()(MOEOT &) {} }defaultEval; - /** default select */ - class DummySelect : public eoSelect < MOEOT >{ - public : - void operator()(const eoPop&, eoPop&) {} - }defaultSelect; - /** default transform */ class DummyTransform : public eoTransform < MOEOT >{ public : @@ -183,6 +185,8 @@ protected: eoPopEvalFunc < MOEOT > & popEval; /** default select many */ moeoDetArchiveSelect < MOEOT > selectMany; // A REMPLACER !!!!!!!!!!! => add/moeoDetArchiveSelect.h + /** eoTransform */ + eoSGATransform < MOEOT > transform; /** select transform */ eoSelectTransform < MOEOT > selectTransform; /** a default crossover */ @@ -190,7 +194,9 @@ protected: /** a default mutation */ eoMonCloneOp < MOEOT > defaultMonOp; /** an object for genetic operators (used as default) */ - eoSGAGenOp < MOEOT > defaultSGAGenOp; + //eoSGAGenOp < MOEOT > defaultSGAGenOp; + /** an object for genetic operators (used as default) */ + //eoSGAGenOp < MOEOT >& genOp; /** breeder */ eoBreed < MOEOT > & breed; /**archive */ diff --git a/trunk/paradiseo-moeo/src/selection/moeoDetArchiveSelect.h b/trunk/paradiseo-moeo/src/selection/moeoDetArchiveSelect.h index 3e17355ea..a786f60a1 100644 --- a/trunk/paradiseo-moeo/src/selection/moeoDetArchiveSelect.h +++ b/trunk/paradiseo-moeo/src/selection/moeoDetArchiveSelect.h @@ -57,15 +57,16 @@ class moeoDetArchiveSelect : public eoSelect * @param _source compatibility parameter, not used * @param _dest destination population, selected from archive */ - virtual void operator()(const eoPop < MOEOT > & _source, eoPop < MOEOT > & _dest) + void operator()(const eoPop < MOEOT > & _source, eoPop < MOEOT > & _dest) { if(max < min){ std::cout << "Warning! moeoDetArchiveSelect: min value > max value!!! Nothing is done." << std::endl; } else{ + unsigned int archive_size = archive.size(); _dest.resize(0); - if (archive_size >= min && archive_size<= max){ + if ((archive_size >= min) && (archive_size <= max)){ for (int i=0; i _dest.push_back(archive[permutation[i]]); } else { - for (int i=0; i xover; - eoUniformMutation < Solution > mutation(0.05); + eoUniformMutation < Solution > mutation(1.0); eoRealVectorBounds bounds(1, 1.0, 2.0); eoRealInitBounded < Solution > init(bounds); eoPop < Solution > pop(20, init); + + for(int i=0; i transform(xover, 0.1, mutation, 0.1); eoGenContinue continuator(10); moeoUnboundedArchive < Solution > archive; @@ -100,12 +104,17 @@ int main() // build ASSEA moeoASEEA algo1(10, eval, xover, 0.1, mutation, 0.5, archive, 10); - moeoASEEA algo2(continuator, popEval, archive, 10); - moeoASEEA algo3(continuator, eval, archive, 10); + moeoASEEA algo2(continuator, popEval, xover, 0.1, mutation, 1.0, archive, 10); + moeoASEEA algo3(continuator, eval, xover, 0.1, mutation, 1.0, archive, 10); moeoASEEA algo4(continuator, popEval, transform, archive, 10); moeoASEEA algo5(continuator, eval, transform, archive, 10); // run the algo + + algo1(pop); + algo2(pop); + algo3(pop); + algo4(pop); algo5(pop); std::cout << " OK\n";