diff --git a/trunk/paradiseo-moeo/src/algo/moeoASEEA.h b/trunk/paradiseo-moeo/src/algo/moeoASEEA.h new file mode 100644 index 000000000..f9241c7df --- /dev/null +++ b/trunk/paradiseo-moeo/src/algo/moeoASEEA.h @@ -0,0 +1,201 @@ +/* +* +* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 +* (C) OPAC Team, LIFL, 2002-2007 +* +* Arnaud Liefooghe +* Jérémie Humeau +* François Legillon +* Thibaut demaret +* +* This software is governed by the CeCILL license under French law and +* abiding by the rules of distribution of free software. You can use, +* modify and/ or redistribute the software under the terms of the CeCILL +* license as circulated by CEA, CNRS and INRIA at the following URL +* "http://www.cecill.info". +* +* As a counterpart to the access to the source code and rights to copy, +* modify and redistribute granted by the license, users are provided only +* with a limited warranty and the software's author, the holder of the +* economic rights, and the successive licensors have only limited liability. +* +* In this respect, the user's attention is drawn to the risks associated +* with loading, using, modifying and/or developing or reproducing the +* software by the user in light of its specific status of free software, +* that may mean that it is complicated to manipulate, and that also +* therefore means that it is reserved for developers and experienced +* professionals having in-depth computer knowledge. Users are therefore +* encouraged to load and test the software's suitability as regards their +* requirements in conditions enabling the security of their systems and/or +* data to be ensured and, more generally, to use and operate it in the +* same conditions as regards security. +* The fact that you are presently reading this means that you have had +* knowledge of the CeCILL license and that you accept its terms. +* +* ParadisEO WebSite : http://paradiseo.gforge.inria.fr +* Contact: paradiseo-help@lists.gforge.inria.fr +* +*/ +//----------------------------------------------------------------------------- + +#ifndef MOEOASEEA_H_ +#define MOEOASEEA_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * ASEEA (Adaptive Simple Elitist Evolutionary Algorithm). + */ +template < class MOEOT > +class moeoASEEA : public moeoEA < MOEOT > +{ +public: + + /** + * Ctor with a crossover, a mutation and their corresponding rates. + * @param _maxGen number of generations before stopping + * @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 (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) + {} + + + /** + * Ctor with a eoContinue. + * @param _continuator stopping criteria + * @param _eval evaluation function + * @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) + {} + + + /** + * Ctor with a eoContinue, a eoPopEval. + * @param _continuator stopping criteria + * @param _popEval population evaluation function + * @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) + {} + + + /** + * Ctor with a eoContinue and a eoTransform. + * @param _continuator stopping criteria + * @param _eval evaluation function + * @param _transform variation operator + * @param _archive archive + * @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) + {} + + + /** + * Ctor with a eoContinue, a eoPopEval and a eoTransform. + * @param _continuator stopping criteria + * @param _popEval population evaluation function + * @param _transform variation operator + * @param _archive archive + * @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) + {} + + + /** + * Apply a few generation of evolution to the population _pop until the stopping criteria is verified. + * @param _pop the population + */ + virtual void operator () (eoPop < MOEOT > &_pop) + { + eoPop < MOEOT > empty_pop, offspring; + popEval (empty_pop, _pop); // a first eval of _pop + archive(_pop); // archive update + while (continuator (_pop)) + { + // generate offspring + breed (_pop, offspring); + popEval (_pop, offspring); // eval of offspring + archive (_pop); // archive update + _pop.resize(0); + offspring.resize(0); + } + } + + +protected: + + /** default eval */ + class DummyEval : public eoEvalFunc < MOEOT >{ + public: + 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 : + void operator()(eoPop&) {} + }defaultTransform; + + /** a continuator based on the number of generations (used as default) */ + eoGenContinue < MOEOT > defaultGenContinuator; + /** stopping criteria */ + eoContinue < MOEOT > & continuator; + /** evaluation function */ + eoEvalFunc < MOEOT > & eval; + /** default popEval */ + eoPopLoopEval < MOEOT > defaultPopEval; + /** evaluation function used to evaluate the whole population */ + eoPopEvalFunc < MOEOT > & popEval; + /** default select many */ + moeoDetArchiveSelect < MOEOT > selectMany; // A REMPLACER !!!!!!!!!!! => add/moeoDetArchiveSelect.h + /** select transform */ + eoSelectTransform < MOEOT > selectTransform; + /** a default crossover */ + eoQuadCloneOp < MOEOT > defaultQuadOp; + /** a default mutation */ + eoMonCloneOp < MOEOT > defaultMonOp; + /** an object for genetic operators (used as default) */ + eoSGAGenOp < MOEOT > defaultSGAGenOp; + /** breeder */ + eoBreed < MOEOT > & breed; + /**archive */ + moeoArchive < MOEOT > & archive; + +}; + +#endif /*MOEOASEEA_H_*/ diff --git a/trunk/paradiseo-moeo/src/moeo b/trunk/paradiseo-moeo/src/moeo index f9fdb7392..099b89114 100644 --- a/trunk/paradiseo-moeo/src/moeo +++ b/trunk/paradiseo-moeo/src/moeo @@ -50,8 +50,10 @@ #include #include #include +#include #include + #include #include #include diff --git a/trunk/paradiseo-moeo/src/selection/moeoDetArchiveSelect.h b/trunk/paradiseo-moeo/src/selection/moeoDetArchiveSelect.h index 2a9b8e946..3e17355ea 100644 --- a/trunk/paradiseo-moeo/src/selection/moeoDetArchiveSelect.h +++ b/trunk/paradiseo-moeo/src/selection/moeoDetArchiveSelect.h @@ -1,3 +1,43 @@ +/* +* +* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 +* (C) OPAC Team, LIFL, 2002-2007 +* +* Arnaud Liefooghe +* Jérémie Humeau +* François Legillon +* Thibaut demaret +* +* This software is governed by the CeCILL license under French law and +* abiding by the rules of distribution of free software. You can use, +* modify and/ or redistribute the software under the terms of the CeCILL +* license as circulated by CEA, CNRS and INRIA at the following URL +* "http://www.cecill.info". +* +* As a counterpart to the access to the source code and rights to copy, +* modify and redistribute granted by the license, users are provided only +* with a limited warranty and the software's author, the holder of the +* economic rights, and the successive licensors have only limited liability. +* +* In this respect, the user's attention is drawn to the risks associated +* with loading, using, modifying and/or developing or reproducing the +* software by the user in light of its specific status of free software, +* that may mean that it is complicated to manipulate, and that also +* therefore means that it is reserved for developers and experienced +* professionals having in-depth computer knowledge. Users are therefore +* encouraged to load and test the software's suitability as regards their +* requirements in conditions enabling the security of their systems and/or +* data to be ensured and, more generally, to use and operate it in the +* same conditions as regards security. +* The fact that you are presently reading this means that you have had +* knowledge of the CeCILL license and that you accept its terms. +* +* ParadisEO WebSite : http://paradiseo.gforge.inria.fr +* Contact: paradiseo-help@lists.gforge.inria.fr +* +*/ +//----------------------------------------------------------------------------- + #ifndef MOEODETARCHIVESELECT_H #define MOEODETARCHIVESELECT_H diff --git a/trunk/paradiseo-moeo/test/CMakeLists.txt b/trunk/paradiseo-moeo/test/CMakeLists.txt index 58faf4479..a33702083 100644 --- a/trunk/paradiseo-moeo/test/CMakeLists.txt +++ b/trunk/paradiseo-moeo/test/CMakeLists.txt @@ -68,6 +68,7 @@ SET (TEST_LIST t-moeoImprOnlyBoundedArchive t-moeoFitDivBoundedArchive t-moeoDetArchiveSelect + t-moeoASEEA ) FOREACH (test ${TEST_LIST}) diff --git a/trunk/paradiseo-moeo/test/t-moeoASEEA.cpp b/trunk/paradiseo-moeo/test/t-moeoASEEA.cpp new file mode 100644 index 000000000..c8191d538 --- /dev/null +++ b/trunk/paradiseo-moeo/test/t-moeoASEEA.cpp @@ -0,0 +1,113 @@ +/* +* +* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008 +* (C) OPAC Team, LIFL, 2002-2008 +* +* Arnaud Liefooghe +* Jeremie Humeau +* +* This software is governed by the CeCILL license under French law and +* abiding by the rules of distribution of free software. You can use, +* modify and/ or redistribute the software under the terms of the CeCILL +* license as circulated by CEA, CNRS and INRIA at the following URL +* "http://www.cecill.info". +* +* As a counterpart to the access to the source code and rights to copy, +* modify and redistribute granted by the license, users are provided only +* with a limited warranty and the software's author, the holder of the +* economic rights, and the successive licensors have only limited liability. +* +* In this respect, the user's attention is drawn to the risks associated +* with loading, using, modifying and/or developing or reproducing the +* software by the user in light of its specific status of free software, +* that may mean that it is complicated to manipulate, and that also +* therefore means that it is reserved for developers and experienced +* professionals having in-depth computer knowledge. Users are therefore +* encouraged to load and test the software's suitability as regards their +* requirements in conditions enabling the security of their systems and/or +* data to be ensured and, more generally, to use and operate it in the +* same conditions as regards security. +* The fact that you are presently reading this means that you have had +* knowledge of the CeCILL license and that you accept its terms. +* +* ParadisEO WebSite : http://paradiseo.gforge.inria.fr +* Contact: paradiseo-help@lists.gforge.inria.fr +* +*/ +//----------------------------------------------------------------------------- +// t-moeoASEEA.cpp +//----------------------------------------------------------------------------- + +#include +#include +#include +#include +#include + +class ObjectiveVectorTraits : public moeoObjectiveVectorTraits +{ +public: + static bool minimizing (int i) + { + return true; + } + static bool maximizing (int i) + { + return false; + } + static unsigned int nObjectives () + { + return 2; + } +}; + +typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector; + +class Solution : public moeoRealVector < ObjectiveVector, double, double > +{ +public: + Solution() : moeoRealVector < ObjectiveVector, double, double > (1) {} +}; + +class TestEval : public moeoEvalFunc < Solution > +{ +public: + void operator () (Solution & _sol) + { + ObjectiveVector objVec; + objVec[0] = _sol[0]; + objVec[1] = _sol[0] * _sol[0]; + _sol.objectiveVector(objVec); + } +}; + +int main() +{ + std::cout << "[moeoASSEA] => \n"; + + TestEval eval; + eoQuadCloneOp < Solution > xover; + eoUniformMutation < Solution > mutation(0.05); + + eoRealVectorBounds bounds(1, 1.0, 2.0); + eoRealInitBounded < Solution > init(bounds); + eoPop < Solution > pop(20, init); + eoSGATransform < Solution > transform(xover, 0.1, mutation, 0.1); + eoGenContinue continuator(10); + moeoUnboundedArchive < Solution > archive; + eoPopLoopEval loopEval(eval); + eoPopEvalFunc & popEval(loopEval); + + // 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 algo4(continuator, popEval, transform, archive, 10); + moeoASEEA algo5(continuator, eval, transform, archive, 10); + + // run the algo + algo5(pop); + + std::cout << " OK\n"; + return EXIT_SUCCESS; +}