bug corrected on some Ctors
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1210 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
61f5d010b0
commit
c751eb1f0b
1 changed files with 86 additions and 66 deletions
|
|
@ -39,6 +39,7 @@
|
||||||
#define MOEONSGAII_H_
|
#define MOEONSGAII_H_
|
||||||
|
|
||||||
#include <eoBreed.h>
|
#include <eoBreed.h>
|
||||||
|
#include <eoCloneOps.h>
|
||||||
#include <eoContinue.h>
|
#include <eoContinue.h>
|
||||||
#include <eoEvalFunc.h>
|
#include <eoEvalFunc.h>
|
||||||
#include <eoGenContinue.h>
|
#include <eoGenContinue.h>
|
||||||
|
|
@ -52,45 +53,15 @@
|
||||||
#include <replacement/moeoElitistReplacement.h>
|
#include <replacement/moeoElitistReplacement.h>
|
||||||
#include <selection/moeoDetTournamentSelect.h>
|
#include <selection/moeoDetTournamentSelect.h>
|
||||||
|
|
||||||
|
|
||||||
#include <eoCloneOps.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NSGA-II (Non-dominated Sorting Genetic Algorithm II) as described in:
|
* NSGA-II (Non-dominated Sorting Genetic Algorithm II).
|
||||||
* Deb, K., S. Agrawal, A. Pratap, and T. Meyarivan : "A fast elitist non-dominated sorting genetic algorithm for multi-objective optimization: NSGA-II".
|
* Deb, K., S. Agrawal, A. Pratap, and T. Meyarivan. A fast elitist non-dominated sorting genetic algorithm for multi-objective optimization: NSGA-II. IEEE Transactions on Evolutionary Computation, Vol. 6, No 2, pp 182-197 (2002).
|
||||||
* In IEEE Transactions on Evolutionary Computation, Vol. 6, No 2, pp 182-197 (April 2002).
|
|
||||||
* This class builds the NSGA-II algorithm only by using the fine-grained components of the ParadisEO-MOEO framework.
|
* This class builds the NSGA-II algorithm only by using the fine-grained components of the ParadisEO-MOEO framework.
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT >
|
||||||
class moeoNSGAII: public moeoEA < MOEOT >
|
class moeoNSGAII: public moeoEA < MOEOT >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple ctor with a eoGenOp.
|
|
||||||
* @param _maxGen number of generations before stopping
|
|
||||||
* @param _eval evaluation function
|
|
||||||
* @param _op variation operator
|
|
||||||
*/
|
|
||||||
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
|
|
||||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
|
||||||
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
|
|
||||||
genBreed(select, _op), breed(genBreed)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple ctor with a eoTransform.
|
|
||||||
* @param _maxGen number of generations before stopping
|
|
||||||
* @param _eval evaluation function
|
|
||||||
* @param _op variation operator
|
|
||||||
*/
|
|
||||||
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) :
|
|
||||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
|
||||||
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
|
|
||||||
genBreed(select, _op), breed(genBreed)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor with a crossover, a mutation and their corresponding rates.
|
* Ctor with a crossover, a mutation and their corresponding rates.
|
||||||
|
|
@ -102,9 +73,7 @@ class moeoNSGAII: public moeoEA < MOEOT >
|
||||||
* @param _pMut mutation probability
|
* @param _pMut mutation probability
|
||||||
*/
|
*/
|
||||||
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut) :
|
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut) :
|
||||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2),
|
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), select (2), selectMany(select,0.0), selectTransform(defaultSelect, defaultTransform),replace (fitnessAssignment, diversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), genBreed (select, defaultSGAGenOp), breed (genBreed)
|
||||||
replace (fitnessAssignment, diversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut),
|
|
||||||
genBreed (select, defaultSGAGenOp), breed (genBreed)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -115,9 +84,20 @@ class moeoNSGAII: public moeoEA < MOEOT >
|
||||||
* @param _op variation operator
|
* @param _op variation operator
|
||||||
*/
|
*/
|
||||||
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
|
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
|
||||||
defaultGenContinuator(0), continuator(_continuator), popEval(_eval), select(2),
|
defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), select(2),
|
||||||
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0),
|
selectMany(select,0.0), selectTransform(defaultSelect, defaultTransform), replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), genBreed(select, _op), breed(genBreed)
|
||||||
genBreed(select, _op), breed(genBreed)
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor with a continuator (instead of _maxGen) and a eoGenOp.
|
||||||
|
* @param _continuator stopping criteria
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
*/
|
||||||
|
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoGenOp < MOEOT > & _op) :
|
||||||
|
defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval), select(2),
|
||||||
|
selectMany(select,0.0), selectTransform(defaultSelect, defaultTransform), replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), genBreed(select, _op), breed(genBreed)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -127,10 +107,21 @@ class moeoNSGAII: public moeoEA < MOEOT >
|
||||||
* @param _eval evaluation function
|
* @param _eval evaluation function
|
||||||
* @param _op variation operator
|
* @param _op variation operator
|
||||||
*/
|
*/
|
||||||
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) :
|
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _transform) :
|
||||||
continuator(_continuator), popEval(_eval), select(2),
|
defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval),
|
||||||
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
|
select(2), selectMany(select, 1.0), selectTransform(selectMany, _transform), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), genBreed(select, defaultSGAGenOp), breed(selectTransform), replace(fitnessAssignment, diversityAssignment)
|
||||||
genBreed(select, _op), breed(genBreed)
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor with a continuator (instead of _maxGen) and a eoTransform.
|
||||||
|
* @param _continuator stopping criteria
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
*/
|
||||||
|
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoTransform < MOEOT > & _transform) :
|
||||||
|
defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval),
|
||||||
|
select(2), selectMany(select, 1.0), selectTransform(selectMany, _transform), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), genBreed(select, defaultSGAGenOp), breed(selectTransform), replace(fitnessAssignment, diversityAssignment)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -140,51 +131,80 @@ class moeoNSGAII: public moeoEA < MOEOT >
|
||||||
*/
|
*/
|
||||||
virtual void operator () (eoPop < MOEOT > &_pop)
|
virtual void operator () (eoPop < MOEOT > &_pop)
|
||||||
{
|
{
|
||||||
eoPop < MOEOT > offspring, empty_pop;
|
eoPop < MOEOT > offspring, empty_pop;
|
||||||
popEval (empty_pop, _pop); // a first eval of _pop
|
popEval (empty_pop, _pop); // a first eval of _pop
|
||||||
// evaluate fitness and diversity
|
// evaluate fitness and diversity
|
||||||
fitnessAssignment(_pop);
|
fitnessAssignment(_pop);
|
||||||
diversityAssignment(_pop);
|
diversityAssignment(_pop);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// generate offspring, worths are recalculated if necessary
|
// generate offspring, worths are recalculated if necessary
|
||||||
breed (_pop, offspring);
|
breed (_pop, offspring);
|
||||||
// eval of offspring
|
// eval of offspring
|
||||||
popEval (_pop, offspring);
|
popEval (_pop, offspring);
|
||||||
// after replace, the new pop is in _pop. Worths are recalculated if necessary
|
// after replace, the new pop is in _pop. Worths are recalculated if necessary
|
||||||
replace (_pop, offspring);
|
replace (_pop, offspring);
|
||||||
}
|
}
|
||||||
while (continuator (_pop));
|
while (continuator (_pop));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/** a continuator based on the number of generations (used as default) */
|
/** a continuator based on the number of generations (used as default) */
|
||||||
eoGenContinue < MOEOT > defaultGenContinuator;
|
eoGenContinue < MOEOT > defaultGenContinuator;
|
||||||
/** stopping criteria */
|
/** stopping criteria */
|
||||||
eoContinue < MOEOT > & continuator;
|
eoContinue < MOEOT > & continuator;
|
||||||
|
/** default eval */
|
||||||
|
class DummyEval : public eoEvalFunc < MOEOT >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void operator()(MOEOT &) {}
|
||||||
|
}
|
||||||
|
defaultEval;
|
||||||
|
/** evaluation function */
|
||||||
|
eoEvalFunc < MOEOT > & eval;
|
||||||
|
/** default popEval */
|
||||||
|
eoPopLoopEval < MOEOT > defaultPopEval;
|
||||||
/** evaluation function used to evaluate the whole population */
|
/** evaluation function used to evaluate the whole population */
|
||||||
eoPopLoopEval < MOEOT > popEval;
|
eoPopEvalFunc < MOEOT > & popEval;
|
||||||
|
/** default select */
|
||||||
|
class DummySelect : public eoSelect < MOEOT >
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
void operator()(const eoPop<MOEOT>&, eoPop<MOEOT>&) {}
|
||||||
|
}
|
||||||
|
defaultSelect;
|
||||||
/** binary tournament selection */
|
/** binary tournament selection */
|
||||||
moeoDetTournamentSelect < MOEOT > select;
|
moeoDetTournamentSelect < MOEOT > select;
|
||||||
/** fitness assignment used in NSGA-II */
|
/** default select many */
|
||||||
moeoFastNonDominatedSortingFitnessAssignment < MOEOT > fitnessAssignment;
|
eoSelectMany < MOEOT > selectMany;
|
||||||
/** diversity assignment used in NSGA-II */
|
/** select transform */
|
||||||
moeoFrontByFrontCrowdingDiversityAssignment < MOEOT > diversityAssignment;
|
eoSelectTransform < MOEOT > selectTransform;
|
||||||
/** elitist replacement */
|
|
||||||
moeoElitistReplacement < MOEOT > replace;
|
|
||||||
/** a default crossover */
|
/** a default crossover */
|
||||||
eoQuadCloneOp < MOEOT > defaultQuadOp;
|
eoQuadCloneOp < MOEOT > defaultQuadOp;
|
||||||
/** a default mutation */
|
/** a default mutation */
|
||||||
eoMonCloneOp < MOEOT > defaultMonOp;
|
eoMonCloneOp < MOEOT > defaultMonOp;
|
||||||
/** an object for genetic operators (used as default) */
|
/** an object for genetic operators (used as default) */
|
||||||
eoSGAGenOp < MOEOT > defaultSGAGenOp;
|
eoSGAGenOp < MOEOT > defaultSGAGenOp;
|
||||||
|
/** default transform */
|
||||||
|
class DummyTransform : public eoTransform < MOEOT >
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
void operator()(eoPop<MOEOT>&) {}
|
||||||
|
}
|
||||||
|
defaultTransform;
|
||||||
/** general breeder */
|
/** general breeder */
|
||||||
eoGeneralBreeder < MOEOT > genBreed;
|
eoGeneralBreeder < MOEOT > genBreed;
|
||||||
/** breeder */
|
/** breeder */
|
||||||
eoBreed < MOEOT > & breed;
|
eoBreed < MOEOT > & breed;
|
||||||
|
/** fitness assignment used in NSGA-II */
|
||||||
|
moeoFastNonDominatedSortingFitnessAssignment < MOEOT > fitnessAssignment;
|
||||||
|
/** diversity assignment used in NSGA-II */
|
||||||
|
moeoFrontByFrontCrowdingDiversityAssignment < MOEOT > diversityAssignment;
|
||||||
|
/** elitist replacement */
|
||||||
|
moeoElitistReplacement < MOEOT > replace;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*MOEONSGAII_H_*/
|
#endif /*MOEONSGAII_H_*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue