From b5800caeb48d60d3674e2f49b7f71edf7f37613b Mon Sep 17 00:00:00 2001 From: legrand Date: Thu, 21 Dec 2006 13:14:36 +0000 Subject: [PATCH] NSGAII algo for ParadisEO-MOEO added git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@110 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-moeo/src/moeoNSGA_II.h | 130 +++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 trunk/paradiseo-moeo/src/moeoNSGA_II.h diff --git a/trunk/paradiseo-moeo/src/moeoNSGA_II.h b/trunk/paradiseo-moeo/src/moeoNSGA_II.h new file mode 100644 index 000000000..a798ca0d0 --- /dev/null +++ b/trunk/paradiseo-moeo/src/moeoNSGA_II.h @@ -0,0 +1,130 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// moeoNSGA_II.h +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006 +// (c) Deneche Abdelhakim, 2006 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr + */ +//----------------------------------------------------------------------------- +#ifndef MOEONSGA_II_H_ +#define MOEONSGA_II_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/** +*/ +template class moeoNSGA_II: public eoAlgo { +public: + + /** + This constructor builds the algorithm as descibed in the paper + + Deb, K., S. Agrawal, A. Pratap, and T. Meyarivan, + A fast elitist non-dominated sorting genetic algorithm for multi-objective optimization: NSGA-II. + In IEEE Transactions on Evolutionary Computation, Vol. 6, No 2, pp 182-197, April 2002. + @param _max_gen number of generations before stopping + @param _eval evaluation function + @param _op variation operator + */ + + moeoNSGA_II( + unsigned _max_gen, + eoEvalFunc& _eval, + eoGenOp& _op + ): continuator(*(new eoGenContinue(_max_gen))), + eval(_eval), + loopEval(_eval), + popEval(loopEval), + selectOne(sorting, 2), // binary tournament selection + replace(sorting), + genBreed(selectOne, _op), + breed(genBreed) + {} + + /// Ctor taking _max_gen, crossover and mutation + moeoNSGA_II( + unsigned _max_gen, + eoEvalFunc& _eval, + eoQuadOp& crossover, + double pCross, + eoMonOp& mutation, + double pMut + ): continuator(*(new eoGenContinue(_max_gen))), + eval(_eval), + loopEval(_eval), + popEval(loopEval), + selectOne(sorting, 2), // binary tournament selection + replace(sorting), + genBreed(selectOne, *new eoSGAGenOp(crossover, pCross, mutation, pMut)), + breed(genBreed) + {} + + /// Ctor taking a continuator instead of _gen_max + moeoNSGA_II( + eoContinue& _continuator, + eoEvalFunc& _eval, + eoGenOp& _op + ): + continuator(_continuator), + eval (_eval), + loopEval(_eval), + popEval(loopEval), + selectOne(sorting, 2), // binary tournament selection + replace(sorting), + genBreed(selectOne, _op), + breed(genBreed) + {} + + ///Apply a few generation of evolution to the population. + virtual void operator()(eoPop& _pop) + { + eoPop offspring, empty_pop; + popEval(empty_pop, _pop); // a first eval of _pop + do + { + // generate offspring, worths are recalculated if necessary + breed(_pop, offspring); + + // eval of offspring + popEval(_pop, offspring); + + // after replace, the new pop is in _pop. Worths are recalculated if necessary + replace(_pop, offspring); + + } while (continuator(_pop)); + } + +protected: + eoContinue& continuator; + + eoEvalFunc& eval; + eoPopLoopEval loopEval; + + eoPopEvalFunc& popEval; + + /// NSGAII sorting + moeoNDSorting_II sorting; + /// Binary tournament selection + eoDetTournamentWorthSelect selectOne; + /// Elitist replacement + moeoElitistReplacement replace; + eoGeneralBreeder genBreed; + eoBreed& breed; +}; + +#endif