New style for MOEO

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@788 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
canape 2007-11-16 11:29:25 +00:00
commit 39709d3d12
103 changed files with 2607 additions and 2521 deletions

View file

@ -3,11 +3,11 @@
@section Introduction @section Introduction
ParadisEO-MOEO is a white-box object-oriented generic framework dedicated to the flexible design of evolutionary multi-objective algorithms. ParadisEO-MOEO is a white-box object-oriented generic framework dedicated to the flexible design of evolutionary multi-objective algorithms.
This paradigm-free software embeds some features and techniques for Pareto-based resolution and This paradigm-free software embeds some features and techniques for Pareto-based resolution and
aims to provide a set of classes allowing to ease and speed up the development of computationally efficient programs. aims to provide a set of classes allowing to ease and speed up the development of computationally efficient programs.
It is based on a clear conceptual distinction between the solution methods and the multi-objective problems they are intended to solve. It is based on a clear conceptual distinction between the solution methods and the multi-objective problems they are intended to solve.
This separation confers a maximum design and code reuse. This separation confers a maximum design and code reuse.
ParadisEO-MOEO provides a broad range of archive-related features (such as elitism or performance metrics) ParadisEO-MOEO provides a broad range of archive-related features (such as elitism or performance metrics)
and the most common Pareto-based fitness assignment strategies (MOGA, NSGA, SPEA, IBEA and more). and the most common Pareto-based fitness assignment strategies (MOGA, NSGA, SPEA, IBEA and more).
Furthermore, parallel and distributed models as well as hybridization mechanisms can be applied to an algorithm designed within ParadisEO-MOEO Furthermore, parallel and distributed models as well as hybridization mechanisms can be applied to an algorithm designed within ParadisEO-MOEO
using the whole version of ParadisEO. using the whole version of ParadisEO.
@ -29,7 +29,7 @@ href="../../README">README</a> file in the top-directory of the source-tree.
@section Design @section Design
For an introduction to the design of ParadisEO-MOEO, For an introduction to the design of ParadisEO-MOEO,
you can look at the <a href="http://paradiseo.gforge.inria.fr">ParadisEO website</a>. you can look at the <a href="http://paradiseo.gforge.inria.fr">ParadisEO website</a>.

View file

@ -1,4 +1,4 @@
/* /*
* <moeoAlgo.h> * <moeoAlgo.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -41,6 +41,7 @@
/** /**
* Abstract class for multi-objective algorithms. * Abstract class for multi-objective algorithms.
*/ */
class moeoAlgo {}; class moeoAlgo
{};
#endif /*MOEOALGO_H_*/ #endif /*MOEOALGO_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoCombinedLS.h> * <moeoCombinedLS.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -48,8 +48,8 @@
*/ */
template < class MOEOT, class Type > template < class MOEOT, class Type >
class moeoCombinedLS : public moeoLS < MOEOT, Type > class moeoCombinedLS : public moeoLS < MOEOT, Type >
{ {
public: public:
/** /**
* Ctor * Ctor
@ -57,7 +57,7 @@ public:
*/ */
moeoCombinedLS(moeoLS < MOEOT, Type > & _first_mols) moeoCombinedLS(moeoLS < MOEOT, Type > & _first_mols)
{ {
combinedLS.push_back (& _first_mols); combinedLS.push_back (& _first_mols);
} }
/** /**
@ -65,9 +65,9 @@ public:
* @param _mols the multi-objective local search to add * @param _mols the multi-objective local search to add
*/ */
void add(moeoLS < MOEOT, Type > & _mols) void add(moeoLS < MOEOT, Type > & _mols)
{ {
combinedLS.push_back(& _mols); combinedLS.push_back(& _mols);
} }
/** /**
* Gives a new solution in order to explore the neigborhood. * Gives a new solution in order to explore the neigborhood.
@ -77,16 +77,16 @@ public:
*/ */
void operator () (Type _type, moeoArchive < MOEOT > & _arch) void operator () (Type _type, moeoArchive < MOEOT > & _arch)
{ {
for (unsigned int i=0; i<combinedLS.size(); i++) for (unsigned int i=0; i<combinedLS.size(); i++)
combinedLS[i] -> operator()(_type, _arch); combinedLS[i] -> operator()(_type, _arch);
} }
private: private:
/** the vector that contains the combined LS */ /** the vector that contains the combined LS */
std::vector< moeoLS < MOEOT, Type > * > combinedLS; std::vector< moeoLS < MOEOT, Type > * > combinedLS;
}; };
#endif /*MOEOCOMBINEDLS_H_*/ #endif /*MOEOCOMBINEDLS_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoEA.h> * <moeoEA.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,6 +45,7 @@
* Abstract class for multi-objective evolutionary algorithms. * Abstract class for multi-objective evolutionary algorithms.
*/ */
template < class MOEOT > template < class MOEOT >
class moeoEA : public moeoAlgo, public eoAlgo < MOEOT > {}; class moeoEA : public moeoAlgo, public eoAlgo < MOEOT >
{};
#endif /*MOEOEA_H_*/ #endif /*MOEOEA_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoEasyEA.h> * <moeoEasyEA.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -56,8 +56,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoEasyEA: public moeoEA < MOEOT > class moeoEasyEA: public moeoEA < MOEOT >
{ {
public: public:
/** /**
* Ctor taking a breed and merge. * Ctor taking a breed and merge.
@ -71,9 +71,9 @@ public:
*/ */
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace, moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace,
moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false) moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
: :
continuator(_continuator), eval (_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace), continuator(_continuator), eval (_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
{} {}
@ -89,9 +89,9 @@ public:
*/ */
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace, moeoEasyEA(eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace,
moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false) moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
: :
continuator(_continuator), eval (dummyEval), loopEval(dummyEval), popEval(_popEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace), continuator(_continuator), eval (dummyEval), loopEval(dummyEval), popEval(_popEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
{} {}
@ -108,9 +108,9 @@ public:
*/ */
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, eoMerge < MOEOT > & _merge, eoReduce< MOEOT > & _reduce, moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, eoMerge < MOEOT > & _merge, eoReduce< MOEOT > & _reduce,
moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false) moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
: :
continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(_merge,_reduce), replace(mergeReduce), continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(_merge,_reduce), replace(mergeReduce),
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
{} {}
@ -127,9 +127,9 @@ public:
*/ */
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, moeoReplacement < MOEOT > & _replace, moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, moeoReplacement < MOEOT > & _replace,
moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false) moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
: :
continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(dummyMerge, dummyReduce), replace(_replace), continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
{} {}
@ -147,9 +147,9 @@ public:
*/ */
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, eoMerge < MOEOT > & _merge, eoReduce< MOEOT > & _reduce, moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, eoMerge < MOEOT > & _merge, eoReduce< MOEOT > & _reduce,
moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false) moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
: :
continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(_merge,_reduce), replace(mergeReduce), continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(_merge,_reduce), replace(mergeReduce),
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
{} {}
@ -159,45 +159,46 @@ public:
*/ */
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.
bool firstTime = true; bool firstTime = true;
do do
{ {
try try
{ {
unsigned int pSize = _pop.size(); unsigned int pSize = _pop.size();
offspring.clear(); // new offspring offspring.clear(); // new offspring
// fitness and diversity assignment (if you want to or if it is the first generation) // fitness and diversity assignment (if you want to or if it is the first generation)
if (evalFitAndDivBeforeSelection || firstTime) if (evalFitAndDivBeforeSelection || firstTime)
{ {
firstTime = false; firstTime = false;
fitnessEval(_pop); fitnessEval(_pop);
diversityEval(_pop); diversityEval(_pop);
} }
breed(_pop, offspring); breed(_pop, offspring);
popEval(_pop, offspring); // eval of parents + offspring if necessary popEval(_pop, offspring); // eval of parents + offspring if necessary
replace(_pop, offspring); // after replace, the new pop. is in _pop replace(_pop, offspring); // after replace, the new pop. is in _pop
if (pSize > _pop.size()) if (pSize > _pop.size())
{ {
throw std::runtime_error("Population shrinking!"); throw std::runtime_error("Population shrinking!");
} }
else if (pSize < _pop.size()) else if (pSize < _pop.size())
{ {
throw std::runtime_error("Population growing!"); throw std::runtime_error("Population growing!");
} }
} }
catch (std::exception& e) catch (std::exception& e)
{ {
std::string s = e.what(); std::string s = e.what();
s.append( " in moeoEasyEA"); s.append( " in moeoEasyEA");
throw std::runtime_error( s ); throw std::runtime_error( s );
} }
} while (continuator(_pop)); }
while (continuator(_pop));
} }
protected: protected:
/** the stopping criteria */ /** the stopping criteria */
eoContinue < MOEOT > & continuator; eoContinue < MOEOT > & continuator;
@ -222,22 +223,34 @@ protected:
/** if this parameter is set to 'true', the fitness and the diversity of the whole population will be re-evaluated before the selection process */ /** if this parameter is set to 'true', the fitness and the diversity of the whole population will be re-evaluated before the selection process */
bool evalFitAndDivBeforeSelection; bool evalFitAndDivBeforeSelection;
/** a dummy eval */ /** a dummy eval */
class eoDummyEval : public eoEvalFunc < MOEOT > class eoDummyEval : public eoEvalFunc < MOEOT >
{ public: /** the dummy functor */ {
void operator()(MOEOT &) {}} dummyEval; public: /** the dummy functor */
void operator()(MOEOT &)
{}
}
dummyEval;
/** a dummy select */ /** a dummy select */
class eoDummySelect : public eoSelect < MOEOT > class eoDummySelect : public eoSelect < MOEOT >
{ public: /** the dummy functor */ {
void operator()(const eoPop < MOEOT > &, eoPop < MOEOT > &) {} } dummySelect; public: /** the dummy functor */
void operator()(const eoPop < MOEOT > &, eoPop < MOEOT > &)
{}
}
dummySelect;
/** a dummy transform */ /** a dummy transform */
class eoDummyTransform : public eoTransform < MOEOT > class eoDummyTransform : public eoTransform < MOEOT >
{ public: /** the dummy functor */ {
void operator()(eoPop < MOEOT > &) {} } dummyTransform; public: /** the dummy functor */
void operator()(eoPop < MOEOT > &)
{}
}
dummyTransform;
/** a dummy merge */ /** a dummy merge */
eoNoElitism < MOEOT > dummyMerge; eoNoElitism < MOEOT > dummyMerge;
/** a dummy reduce */ /** a dummy reduce */
eoTruncate < MOEOT > dummyReduce; eoTruncate < MOEOT > dummyReduce;
}; };
#endif /*MOEOEASYEA_H_*/ #endif /*MOEOEASYEA_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoHybridLS.h> * <moeoHybridLS.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -51,8 +51,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoHybridLS : public eoUpdater class moeoHybridLS : public eoUpdater
{ {
public: public:
/** /**
* Ctor * Ctor
@ -62,7 +62,7 @@ public:
* @param _arch the archive * @param _arch the archive
*/ */
moeoHybridLS (eoContinue < MOEOT > & _term, eoSelect < MOEOT > & _select, moeoLS < MOEOT, MOEOT > & _mols, moeoArchive < MOEOT > & _arch) : moeoHybridLS (eoContinue < MOEOT > & _term, eoSelect < MOEOT > & _select, moeoLS < MOEOT, MOEOT > & _mols, moeoArchive < MOEOT > & _arch) :
term(_term), select(_select), mols(_mols), arch(_arch) term(_term), select(_select), mols(_mols), arch(_arch)
{} {}
@ -71,21 +71,21 @@ public:
*/ */
void operator () () void operator () ()
{ {
if (! term (arch)) if (! term (arch))
{ {
// selection of solutions // selection of solutions
eoPop < MOEOT > selectedSolutions; eoPop < MOEOT > selectedSolutions;
select(arch, selectedSolutions); select(arch, selectedSolutions);
// apply the local search to every selected solution // apply the local search to every selected solution
for (unsigned int i=0; i<selectedSolutions.size(); i++) for (unsigned int i=0; i<selectedSolutions.size(); i++)
{ {
mols(selectedSolutions[i], arch); mols(selectedSolutions[i], arch);
} }
} }
} }
private: private:
/** stopping criteria */ /** stopping criteria */
eoContinue < MOEOT > & term; eoContinue < MOEOT > & term;
@ -96,6 +96,6 @@ private:
/** archive */ /** archive */
moeoArchive < MOEOT > & arch; moeoArchive < MOEOT > & arch;
}; };
#endif /*MOEOHYBRIDLS_H_*/ #endif /*MOEOHYBRIDLS_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoIBEA.h> * <moeoIBEA.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -61,8 +61,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoIBEA : public moeoEA < MOEOT > class moeoIBEA : public moeoEA < MOEOT >
{ {
public: public:
/** The type of objective vector */ /** The type of objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -77,8 +77,8 @@ public:
* @param _kappa scaling factor kappa * @param _kappa scaling factor kappa
*/ */
moeoIBEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) : moeoIBEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed) fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
{} {}
@ -91,8 +91,8 @@ public:
* @param _kappa scaling factor kappa * @param _kappa scaling factor kappa
*/ */
moeoIBEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) : moeoIBEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed) fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
{} {}
@ -108,9 +108,9 @@ public:
* @param _kappa scaling factor kappa * @param _kappa scaling factor kappa
*/ */
moeoIBEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) : moeoIBEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2), defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2),
fitnessAssignment(_metric, _kappa), replace (fitnessAssignment, dummyDiversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), fitnessAssignment(_metric, _kappa), replace (fitnessAssignment, dummyDiversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut),
genBreed (select, defaultSGAGenOp), breed (genBreed) genBreed (select, defaultSGAGenOp), breed (genBreed)
{} {}
@ -123,8 +123,8 @@ public:
* @param _kappa scaling factor kappa * @param _kappa scaling factor kappa
*/ */
moeoIBEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) : moeoIBEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) :
continuator(_continuator), popEval(_eval), select(2), continuator(_continuator), popEval(_eval), select(2),
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed) fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
{} {}
@ -137,8 +137,8 @@ public:
* @param _kappa scaling factor kappa * @param _kappa scaling factor kappa
*/ */
moeoIBEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) : moeoIBEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) :
continuator(_continuator), popEval(_eval), select(2), continuator(_continuator), popEval(_eval), select(2),
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed) fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
{} {}
@ -148,24 +148,25 @@ public:
*/ */
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);
dummyDiversityAssignment(_pop); dummyDiversityAssignment(_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;
@ -188,6 +189,6 @@ protected:
/** breeder */ /** breeder */
eoBreed < MOEOT > & breed; eoBreed < MOEOT > & breed;
}; };
#endif /*MOEOIBEA_H_*/ #endif /*MOEOIBEA_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoIBMOLS.h> * <moeoIBMOLS.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -56,8 +56,8 @@
*/ */
template < class MOEOT, class Move > template < class MOEOT, class Move >
class moeoIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & > class moeoIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & >
{ {
public: public:
/** The type of objective vector */ /** The type of objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -73,19 +73,19 @@ public:
* @param _continuator the stopping criteria * @param _continuator the stopping criteria
*/ */
moeoIBMOLS( moeoIBMOLS(
moMoveInit < Move > & _moveInit, moMoveInit < Move > & _moveInit,
moNextMove < Move > & _nextMove, moNextMove < Move > & _nextMove,
eoEvalFunc < MOEOT > & _eval, eoEvalFunc < MOEOT > & _eval,
moeoMoveIncrEval < Move > & _moveIncrEval, moeoMoveIncrEval < Move > & _moveIncrEval,
moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment, moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
eoContinue < MOEOT > & _continuator eoContinue < MOEOT > & _continuator
) : ) :
moveInit(_moveInit), moveInit(_moveInit),
nextMove(_nextMove), nextMove(_nextMove),
eval(_eval), eval(_eval),
moveIncrEval(_moveIncrEval), moveIncrEval(_moveIncrEval),
fitnessAssignment (_fitnessAssignment), fitnessAssignment (_fitnessAssignment),
continuator (_continuator) continuator (_continuator)
{} {}
@ -97,32 +97,33 @@ public:
*/ */
void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _arch) void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _arch)
{ {
// evaluation of the objective values // evaluation of the objective values
/* /*
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
eval(_pop[i]); eval(_pop[i]);
} }
*/ */
// fitness assignment for the whole population // fitness assignment for the whole population
fitnessAssignment(_pop); fitnessAssignment(_pop);
// creation of a local archive // creation of a local archive
moeoArchive < MOEOT > archive; moeoArchive < MOEOT > archive;
// creation of another local archive (for the stopping criteria) // creation of another local archive (for the stopping criteria)
moeoArchive < MOEOT > previousArchive; moeoArchive < MOEOT > previousArchive;
// update the archive with the initial population // update the archive with the initial population
archive.update(_pop); archive.update(_pop);
do do
{ {
previousArchive.update(archive); previousArchive.update(archive);
oneStep(_pop); oneStep(_pop);
archive.update(_pop); archive.update(_pop);
} while ( (! archive.equals(previousArchive)) && (continuator(_arch)) ); }
_arch.update(archive); while ( (! archive.equals(previousArchive)) && (continuator(_arch)) );
_arch.update(archive);
} }
private: private:
/** the move initializer */ /** the move initializer */
moMoveInit < Move > & moveInit; moMoveInit < Move > & moveInit;
@ -144,162 +145,162 @@ private:
*/ */
void oneStep (eoPop < MOEOT > & _pop) void oneStep (eoPop < MOEOT > & _pop)
{ {
// the move // the move
Move move; Move move;
// the objective vector and the fitness of the current solution // the objective vector and the fitness of the current solution
ObjectiveVector x_objVec; ObjectiveVector x_objVec;
double x_fitness; double x_fitness;
// the index, the objective vector and the fitness of the worst solution in the population (-1 implies that the worst is the newly created one) // the index, the objective vector and the fitness of the worst solution in the population (-1 implies that the worst is the newly created one)
int worst_idx; int worst_idx;
ObjectiveVector worst_objVec; ObjectiveVector worst_objVec;
double worst_fitness; double worst_fitness;
////////////////////////////////////////////
// the indexes and the objective vectors of the extreme non-dominated points
int ext_0_idx, ext_1_idx;
ObjectiveVector ext_0_objVec, ext_1_objVec;
unsigned int ind;
//////////////////////////////////////////// ////////////////////////////////////////////
// the index of the current solution to be explored // the indexes and the objective vectors of the extreme non-dominated points
unsigned int i=0; int ext_0_idx, ext_1_idx;
// initilization of the move for the first individual ObjectiveVector ext_0_objVec, ext_1_objVec;
moveInit(move, _pop[i]); unsigned int ind;
while (i<_pop.size() && continuator(_pop)) ////////////////////////////////////////////
// the index of the current solution to be explored
unsigned int i=0;
// initilization of the move for the first individual
moveInit(move, _pop[i]);
while (i<_pop.size() && continuator(_pop))
{ {
// x = one neigbour of pop[i] // x = one neigbour of pop[i]
// evaluate x in the objective space // evaluate x in the objective space
x_objVec = moveIncrEval(move, _pop[i]); x_objVec = moveIncrEval(move, _pop[i]);
// update every fitness values to take x into account and compute the fitness of x // update every fitness values to take x into account and compute the fitness of x
x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec); x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec);
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// extreme solutions (min only!) // extreme solutions (min only!)
ext_0_idx = -1; ext_0_idx = -1;
ext_0_objVec = x_objVec; ext_0_objVec = x_objVec;
ext_1_idx = -1; ext_1_idx = -1;
ext_1_objVec = x_objVec; ext_1_objVec = x_objVec;
for (unsigned int k=0; k<_pop.size(); k++) for (unsigned int k=0; k<_pop.size(); k++)
{ {
// ext_0 // ext_0
if (_pop[k].objectiveVector()[0] < ext_0_objVec[0]) if (_pop[k].objectiveVector()[0] < ext_0_objVec[0])
{ {
ext_0_idx = k; ext_0_idx = k;
ext_0_objVec = _pop[k].objectiveVector(); ext_0_objVec = _pop[k].objectiveVector();
} }
else if ( (_pop[k].objectiveVector()[0] == ext_0_objVec[0]) && (_pop[k].objectiveVector()[1] < ext_0_objVec[1]) ) else if ( (_pop[k].objectiveVector()[0] == ext_0_objVec[0]) && (_pop[k].objectiveVector()[1] < ext_0_objVec[1]) )
{ {
ext_0_idx = k; ext_0_idx = k;
ext_0_objVec = _pop[k].objectiveVector(); ext_0_objVec = _pop[k].objectiveVector();
} }
// ext_1 // ext_1
else if (_pop[k].objectiveVector()[1] < ext_1_objVec[1]) else if (_pop[k].objectiveVector()[1] < ext_1_objVec[1])
{ {
ext_1_idx = k; ext_1_idx = k;
ext_1_objVec = _pop[k].objectiveVector(); ext_1_objVec = _pop[k].objectiveVector();
} }
else if ( (_pop[k].objectiveVector()[1] == ext_1_objVec[1]) && (_pop[k].objectiveVector()[0] < ext_1_objVec[0]) ) else if ( (_pop[k].objectiveVector()[1] == ext_1_objVec[1]) && (_pop[k].objectiveVector()[0] < ext_1_objVec[0]) )
{ {
ext_1_idx = k; ext_1_idx = k;
ext_1_objVec = _pop[k].objectiveVector(); ext_1_objVec = _pop[k].objectiveVector();
} }
} }
// worst init // worst init
if (ext_0_idx == -1) if (ext_0_idx == -1)
{ {
ind = 0; ind = 0;
while (ind == ext_1_idx) while (ind == ext_1_idx)
{ {
ind++; ind++;
} }
worst_idx = ind; worst_idx = ind;
worst_objVec = _pop[ind].objectiveVector(); worst_objVec = _pop[ind].objectiveVector();
worst_fitness = _pop[ind].fitness(); worst_fitness = _pop[ind].fitness();
} }
else if (ext_1_idx == -1) else if (ext_1_idx == -1)
{ {
ind = 0; ind = 0;
while (ind == ext_0_idx) while (ind == ext_0_idx)
{ {
ind++; ind++;
} }
worst_idx = ind; worst_idx = ind;
worst_objVec = _pop[ind].objectiveVector(); worst_objVec = _pop[ind].objectiveVector();
worst_fitness = _pop[ind].fitness(); worst_fitness = _pop[ind].fitness();
} }
else else
{ {
worst_idx = -1; worst_idx = -1;
worst_objVec = x_objVec; worst_objVec = x_objVec;
worst_fitness = x_fitness; worst_fitness = x_fitness;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// who is the worst ? // who is the worst ?
for (unsigned int j=0; j<_pop.size(); j++) for (unsigned int j=0; j<_pop.size(); j++)
{ {
if ( (j!=ext_0_idx) && (j!=ext_1_idx) ) if ( (j!=ext_0_idx) && (j!=ext_1_idx) )
{ {
if (_pop[j].fitness() < worst_fitness) if (_pop[j].fitness() < worst_fitness)
{ {
worst_idx = j; worst_idx = j;
worst_objVec = _pop[j].objectiveVector(); worst_objVec = _pop[j].objectiveVector();
worst_fitness = _pop[j].fitness(); worst_fitness = _pop[j].fitness();
} }
} }
} }
// if the worst solution is the new one // if the worst solution is the new one
if (worst_idx == -1) if (worst_idx == -1)
{ {
// if all its neighbours have been explored, // if all its neighbours have been explored,
// let's explore the neighborhoud of the next individual // let's explore the neighborhoud of the next individual
if (! nextMove(move, _pop[i])) if (! nextMove(move, _pop[i]))
{ {
i++; i++;
if (i<_pop.size()) if (i<_pop.size())
{ {
// initilization of the move for the next individual // initilization of the move for the next individual
moveInit(move, _pop[i]); moveInit(move, _pop[i]);
} }
} }
} }
// if the worst solution is located before _pop[i] // if the worst solution is located before _pop[i]
else if (worst_idx <= i) else if (worst_idx <= i)
{ {
// the new solution takes place insteed of _pop[worst_idx] // the new solution takes place insteed of _pop[worst_idx]
_pop[worst_idx] = _pop[i]; _pop[worst_idx] = _pop[i];
move(_pop[worst_idx]); move(_pop[worst_idx]);
_pop[worst_idx].objectiveVector(x_objVec); _pop[worst_idx].objectiveVector(x_objVec);
_pop[worst_idx].fitness(x_fitness); _pop[worst_idx].fitness(x_fitness);
// let's explore the neighborhoud of the next individual // let's explore the neighborhoud of the next individual
i++; i++;
if (i<_pop.size()) if (i<_pop.size())
{ {
// initilization of the move for the next individual // initilization of the move for the next individual
moveInit(move, _pop[i]); moveInit(move, _pop[i]);
} }
} }
// if the worst solution is located after _pop[i] // if the worst solution is located after _pop[i]
else if (worst_idx > i) else if (worst_idx > i)
{ {
// the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted // the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted
_pop[worst_idx] = _pop[i+1]; _pop[worst_idx] = _pop[i+1];
_pop[i+1] = _pop[i]; _pop[i+1] = _pop[i];
move(_pop[i+1]); move(_pop[i+1]);
_pop[i+1].objectiveVector(x_objVec); _pop[i+1].objectiveVector(x_objVec);
_pop[i+1].fitness(x_fitness); _pop[i+1].fitness(x_fitness);
// let's explore the neighborhoud of the individual _pop[i+2] // let's explore the neighborhoud of the individual _pop[i+2]
i += 2; i += 2;
if (i<_pop.size()) if (i<_pop.size())
{ {
// initilization of the move for the next individual // initilization of the move for the next individual
moveInit(move, _pop[i]); moveInit(move, _pop[i]);
} }
} }
// update fitness values // update fitness values
fitnessAssignment.updateByDeleting(_pop, worst_objVec); fitnessAssignment.updateByDeleting(_pop, worst_objVec);
} }
} }
@ -328,153 +329,153 @@ private:
*/ */
void new_oneStep (eoPop < MOEOT > & _pop) void new_oneStep (eoPop < MOEOT > & _pop)
{ {
// the move // the move
Move move; Move move;
// the objective vector and the fitness of the current solution // the objective vector and the fitness of the current solution
ObjectiveVector x_objVec; ObjectiveVector x_objVec;
double x_fitness; double x_fitness;
// the index, the objective vector and the fitness of the worst solution in the population (-1 implies that the worst is the newly created one) // the index, the objective vector and the fitness of the worst solution in the population (-1 implies that the worst is the newly created one)
int worst_idx; int worst_idx;
ObjectiveVector worst_objVec; ObjectiveVector worst_objVec;
double worst_fitness; double worst_fitness;
////////////////////////////////////////////
// the index of the extreme non-dominated points
int ext_0_idx, ext_1_idx;
unsigned int ind;
//////////////////////////////////////////// ////////////////////////////////////////////
// the index current of the current solution to be explored // the index of the extreme non-dominated points
unsigned int i=0; int ext_0_idx, ext_1_idx;
// initilization of the move for the first individual unsigned int ind;
moveInit(move, _pop[i]); ////////////////////////////////////////////
while (i<_pop.size() && continuator(_pop)) // the index current of the current solution to be explored
unsigned int i=0;
// initilization of the move for the first individual
moveInit(move, _pop[i]);
while (i<_pop.size() && continuator(_pop))
{ {
// x = one neigbour of pop[i] // x = one neigbour of pop[i]
// evaluate x in the objective space // evaluate x in the objective space
x_objVec = moveIncrEval(move, _pop[i]); x_objVec = moveIncrEval(move, _pop[i]);
// update every fitness values to take x into account and compute the fitness of x // update every fitness values to take x into account and compute the fitness of x
x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec); x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec);
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// extremes solutions // extremes solutions
OneObjectiveComparator comp0(0); OneObjectiveComparator comp0(0);
ext_0_idx = std::min_element(_pop.begin(), _pop.end(), comp0) - _pop.begin(); ext_0_idx = std::min_element(_pop.begin(), _pop.end(), comp0) - _pop.begin();
OneObjectiveComparator comp1(1); OneObjectiveComparator comp1(1);
ext_1_idx = std::min_element(_pop.begin(), _pop.end(), comp1) - _pop.begin(); ext_1_idx = std::min_element(_pop.begin(), _pop.end(), comp1) - _pop.begin();
// new = extreme ? // new = extreme ?
if (x_objVec[0] < _pop[ext_0_idx].objectiveVector()[0]) if (x_objVec[0] < _pop[ext_0_idx].objectiveVector()[0])
{ {
ext_0_idx = -1; ext_0_idx = -1;
} }
else if ( (x_objVec[0] == _pop[ext_0_idx].objectiveVector()[0]) && (x_objVec[1] < _pop[ext_0_idx].objectiveVector()[1]) ) else if ( (x_objVec[0] == _pop[ext_0_idx].objectiveVector()[0]) && (x_objVec[1] < _pop[ext_0_idx].objectiveVector()[1]) )
{ {
ext_0_idx = -1; ext_0_idx = -1;
} }
else if (x_objVec[1] < _pop[ext_1_idx].objectiveVector()[1]) else if (x_objVec[1] < _pop[ext_1_idx].objectiveVector()[1])
{ {
ext_1_idx = -1; ext_1_idx = -1;
} }
else if ( (x_objVec[1] == _pop[ext_1_idx].objectiveVector()[1]) && (x_objVec[0] < _pop[ext_1_idx].objectiveVector()[0]) ) else if ( (x_objVec[1] == _pop[ext_1_idx].objectiveVector()[1]) && (x_objVec[0] < _pop[ext_1_idx].objectiveVector()[0]) )
{ {
ext_1_idx = -1; ext_1_idx = -1;
} }
// worst init // worst init
if (ext_0_idx == -1) if (ext_0_idx == -1)
{ {
ind = 0; ind = 0;
while (ind == ext_1_idx) while (ind == ext_1_idx)
{ {
ind++; ind++;
} }
worst_idx = ind; worst_idx = ind;
worst_objVec = _pop[ind].objectiveVector(); worst_objVec = _pop[ind].objectiveVector();
worst_fitness = _pop[ind].fitness(); worst_fitness = _pop[ind].fitness();
} }
else if (ext_1_idx == -1) else if (ext_1_idx == -1)
{ {
ind = 0; ind = 0;
while (ind == ext_0_idx) while (ind == ext_0_idx)
{ {
ind++; ind++;
} }
worst_idx = ind; worst_idx = ind;
worst_objVec = _pop[ind].objectiveVector(); worst_objVec = _pop[ind].objectiveVector();
worst_fitness = _pop[ind].fitness(); worst_fitness = _pop[ind].fitness();
} }
else else
{ {
worst_idx = -1; worst_idx = -1;
worst_objVec = x_objVec; worst_objVec = x_objVec;
worst_fitness = x_fitness; worst_fitness = x_fitness;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// who is the worst ? // who is the worst ?
for (unsigned int j=0; j<_pop.size(); j++) for (unsigned int j=0; j<_pop.size(); j++)
{ {
if ( (j!=ext_0_idx) && (j!=ext_1_idx) ) if ( (j!=ext_0_idx) && (j!=ext_1_idx) )
{ {
if (_pop[j].fitness() < worst_fitness) if (_pop[j].fitness() < worst_fitness)
{ {
worst_idx = j; worst_idx = j;
worst_objVec = _pop[j].objectiveVector(); worst_objVec = _pop[j].objectiveVector();
worst_fitness = _pop[j].fitness(); worst_fitness = _pop[j].fitness();
} }
} }
} }
// if the worst solution is the new one // if the worst solution is the new one
if (worst_idx == -1) if (worst_idx == -1)
{ {
// if all its neighbours have been explored, // if all its neighbours have been explored,
// let's explore the neighborhoud of the next individual // let's explore the neighborhoud of the next individual
if (! nextMove(move, _pop[i])) if (! nextMove(move, _pop[i]))
{ {
i++; i++;
if (i<_pop.size()) if (i<_pop.size())
{ {
// initilization of the move for the next individual // initilization of the move for the next individual
moveInit(move, _pop[i]); moveInit(move, _pop[i]);
} }
} }
} }
// if the worst solution is located before _pop[i] // if the worst solution is located before _pop[i]
else if (worst_idx <= i) else if (worst_idx <= i)
{ {
// the new solution takes place insteed of _pop[worst_idx] // the new solution takes place insteed of _pop[worst_idx]
_pop[worst_idx] = _pop[i]; _pop[worst_idx] = _pop[i];
move(_pop[worst_idx]); move(_pop[worst_idx]);
_pop[worst_idx].objectiveVector(x_objVec); _pop[worst_idx].objectiveVector(x_objVec);
_pop[worst_idx].fitness(x_fitness); _pop[worst_idx].fitness(x_fitness);
// let's explore the neighborhoud of the next individual // let's explore the neighborhoud of the next individual
i++; i++;
if (i<_pop.size()) if (i<_pop.size())
{ {
// initilization of the move for the next individual // initilization of the move for the next individual
moveInit(move, _pop[i]); moveInit(move, _pop[i]);
} }
} }
// if the worst solution is located after _pop[i] // if the worst solution is located after _pop[i]
else if (worst_idx > i) else if (worst_idx > i)
{ {
// the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted // the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted
_pop[worst_idx] = _pop[i+1]; _pop[worst_idx] = _pop[i+1];
_pop[i+1] = _pop[i]; _pop[i+1] = _pop[i];
move(_pop[i+1]); move(_pop[i+1]);
_pop[i+1].objectiveVector(x_objVec); _pop[i+1].objectiveVector(x_objVec);
_pop[i+1].fitness(x_fitness); _pop[i+1].fitness(x_fitness);
// let's explore the neighborhoud of the individual _pop[i+2] // let's explore the neighborhoud of the individual _pop[i+2]
i += 2; i += 2;
if (i<_pop.size()) if (i<_pop.size())
{ {
// initilization of the move for the next individual // initilization of the move for the next individual
moveInit(move, _pop[i]); moveInit(move, _pop[i]);
} }
} }
// update fitness values // update fitness values
fitnessAssignment.updateByDeleting(_pop, worst_objVec); fitnessAssignment.updateByDeleting(_pop, worst_objVec);
} }
} }
@ -484,35 +485,35 @@ private:
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
class OneObjectiveComparator : public moeoComparator < MOEOT > class OneObjectiveComparator : public moeoComparator < MOEOT >
{ {
public: public:
OneObjectiveComparator(unsigned int _obj) : obj(_obj) OneObjectiveComparator(unsigned int _obj) : obj(_obj)
{ {
if (obj > MOEOT::ObjectiveVector::nObjectives()) if (obj > MOEOT::ObjectiveVector::nObjectives())
{ {
throw std::runtime_error("Problem with the index of objective in OneObjectiveComparator"); throw std::runtime_error("Problem with the index of objective in OneObjectiveComparator");
} }
} }
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{ {
if (_moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj]) if (_moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj])
{ {
return true; return true;
} }
else else
{ {
return (_moeo1.objectiveVector()[obj] == _moeo2.objectiveVector()[obj]) && (_moeo1.objectiveVector()[(obj+1)%2] < _moeo2.objectiveVector()[(obj+1)%2]); return (_moeo1.objectiveVector()[obj] == _moeo2.objectiveVector()[obj]) && (_moeo1.objectiveVector()[(obj+1)%2] < _moeo2.objectiveVector()[(obj+1)%2]);
} }
} }
private: private:
unsigned int obj; unsigned int obj;
}; };
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
}; };
#endif /*MOEOIBMOLS_H_*/ #endif /*MOEOIBMOLS_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoIteratedIBMOLS.h> * <moeoIteratedIBMOLS.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -64,8 +64,8 @@
*/ */
template < class MOEOT, class Move > template < class MOEOT, class Move >
class moeoIteratedIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & > class moeoIteratedIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & >
{ {
public: public:
/** The type of objective vector */ /** The type of objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -84,22 +84,22 @@ public:
* @param _nNoiseIterations the number of iterations to apply the random noise * @param _nNoiseIterations the number of iterations to apply the random noise
*/ */
moeoIteratedIBMOLS( moeoIteratedIBMOLS(
moMoveInit < Move > & _moveInit, moMoveInit < Move > & _moveInit,
moNextMove < Move > & _nextMove, moNextMove < Move > & _nextMove,
eoEvalFunc < MOEOT > & _eval, eoEvalFunc < MOEOT > & _eval,
moeoMoveIncrEval < Move > & _moveIncrEval, moeoMoveIncrEval < Move > & _moveIncrEval,
moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment, moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
eoContinue < MOEOT > & _continuator, eoContinue < MOEOT > & _continuator,
eoMonOp < MOEOT > & _monOp, eoMonOp < MOEOT > & _monOp,
eoMonOp < MOEOT > & _randomMonOp, eoMonOp < MOEOT > & _randomMonOp,
unsigned int _nNoiseIterations=1 unsigned int _nNoiseIterations=1
) : ) :
ibmols(_moveInit, _nextMove, _eval, _moveIncrEval, _fitnessAssignment, _continuator), ibmols(_moveInit, _nextMove, _eval, _moveIncrEval, _fitnessAssignment, _continuator),
eval(_eval), eval(_eval),
continuator(_continuator), continuator(_continuator),
monOp(_monOp), monOp(_monOp),
randomMonOp(_randomMonOp), randomMonOp(_randomMonOp),
nNoiseIterations(_nNoiseIterations) nNoiseIterations(_nNoiseIterations)
{} {}
@ -110,19 +110,19 @@ public:
*/ */
void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _arch) void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _arch)
{ {
_arch.update(_pop); _arch.update(_pop);
ibmols(_pop, _arch); ibmols(_pop, _arch);
while (continuator(_arch)) while (continuator(_arch))
{ {
// generate new solutions from the archive // generate new solutions from the archive
generateNewSolutions(_pop, _arch); generateNewSolutions(_pop, _arch);
// apply the local search (the global archive is updated in the sub-function) // apply the local search (the global archive is updated in the sub-function)
ibmols(_pop, _arch); ibmols(_pop, _arch);
} }
} }
private: private:
/** the local search to iterate */ /** the local search to iterate */
moeoIBMOLS < MOEOT, Move > ibmols; moeoIBMOLS < MOEOT, Move > ibmols;
@ -145,38 +145,38 @@ private:
*/ */
void generateNewSolutions(eoPop < MOEOT > & _pop, const moeoArchive < MOEOT > & _arch) void generateNewSolutions(eoPop < MOEOT > & _pop, const moeoArchive < MOEOT > & _arch)
{ {
// shuffle vector for the random selection of individuals // shuffle vector for the random selection of individuals
vector<unsigned int> shuffle; vector<unsigned int> shuffle;
shuffle.resize(std::max(_pop.size(), _arch.size())); shuffle.resize(std::max(_pop.size(), _arch.size()));
// init shuffle // init shuffle
for (unsigned int i=0; i<shuffle.size(); i++) for (unsigned int i=0; i<shuffle.size(); i++)
{ {
shuffle[i] = i; shuffle[i] = i;
} }
// randomize shuffle // randomize shuffle
UF_random_generator <unsigned int> gen; UF_random_generator <unsigned int> gen;
std::random_shuffle(shuffle.begin(), shuffle.end(), gen); std::random_shuffle(shuffle.begin(), shuffle.end(), gen);
// start the creation of new solutions // start the creation of new solutions
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
if (shuffle[i] < _arch.size()) // the given archive contains the individual i if (shuffle[i] < _arch.size()) // the given archive contains the individual i
{ {
// add it to the resulting pop // add it to the resulting pop
_pop[i] = _arch[shuffle[i]]; _pop[i] = _arch[shuffle[i]];
// apply noise // apply noise
for (unsigned int j=0; j<nNoiseIterations; j++) for (unsigned int j=0; j<nNoiseIterations; j++)
{ {
monOp(_pop[i]); monOp(_pop[i]);
} }
} }
else // a random solution needs to be added else // a random solution needs to be added
{ {
// random initialization // random initialization
randomMonOp(_pop[i]); randomMonOp(_pop[i]);
} }
// evaluation of the new individual // evaluation of the new individual
_pop[i].invalidate(); _pop[i].invalidate();
eval(_pop[i]); eval(_pop[i]);
} }
} }
@ -233,6 +233,6 @@ private:
}; };
#endif /*MOEOITERATEDIBMOLS_H_*/ #endif /*MOEOITERATEDIBMOLS_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoLS.h> * <moeoLS.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -47,6 +47,7 @@
* Starting from a Type (i.e.: an individual, a pop, an archive...), it produces a set of new non-dominated solutions. * Starting from a Type (i.e.: an individual, a pop, an archive...), it produces a set of new non-dominated solutions.
*/ */
template < class MOEOT, class Type > template < class MOEOT, class Type >
class moeoLS: public moeoAlgo, public eoBF < Type, moeoArchive < MOEOT > &, void > {}; class moeoLS: public moeoAlgo, public eoBF < Type, moeoArchive < MOEOT > &, void >
{};
#endif /*MOEOLS_H_*/ #endif /*MOEOLS_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoNSGA.h> * <moeoNSGA.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -60,8 +60,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoNSGA: public moeoEA < MOEOT > class moeoNSGA: public moeoEA < MOEOT >
{ {
public: public:
/** /**
* Simple ctor with a eoGenOp. * Simple ctor with a eoGenOp.
@ -71,8 +71,8 @@ public:
* @param _nicheSize niche size * @param _nicheSize niche size
*/ */
moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, double _nicheSize = 0.5) : moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, double _nicheSize = 0.5) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed) diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
{} {}
@ -84,8 +84,8 @@ public:
* @param _nicheSize niche size * @param _nicheSize niche size
*/ */
moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, double _nicheSize = 0.5) : moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, double _nicheSize = 0.5) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed) diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
{} {}
@ -100,9 +100,9 @@ public:
* @param _nicheSize niche size * @param _nicheSize niche size
*/ */
moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, double _nicheSize = 0.5) : moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, double _nicheSize = 0.5) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2), defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2),
diversityAssignment(_nicheSize), replace (fitnessAssignment, diversityAssignment), diversityAssignment(_nicheSize), replace (fitnessAssignment, diversityAssignment),
defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), genBreed (select, defaultSGAGenOp), breed (genBreed) defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), genBreed (select, defaultSGAGenOp), breed (genBreed)
{} {}
@ -114,8 +114,8 @@ public:
* @param _nicheSize niche size * @param _nicheSize niche size
*/ */
moeoNSGA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, double _nicheSize = 0.5) : moeoNSGA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, double _nicheSize = 0.5) :
continuator(_continuator), popEval(_eval), select(2), continuator(_continuator), popEval(_eval), select(2),
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed) diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
{} {}
@ -127,8 +127,8 @@ public:
* @param _nicheSize niche size * @param _nicheSize niche size
*/ */
moeoNSGA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, double _nicheSize = 0.5) : moeoNSGA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, double _nicheSize = 0.5) :
continuator(_continuator), popEval(_eval), select(2), continuator(_continuator), popEval(_eval), select(2),
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed) diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
{} {}
@ -138,24 +138,25 @@ public:
*/ */
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;
@ -178,6 +179,6 @@ protected:
/** breeder */ /** breeder */
eoBreed < MOEOT > & breed; eoBreed < MOEOT > & breed;
}; };
#endif /*MOEONSGAII_H_*/ #endif /*MOEONSGAII_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoNSGAII.h> * <moeoNSGAII.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -63,8 +63,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoNSGAII: public moeoEA < MOEOT > class moeoNSGAII: public moeoEA < MOEOT >
{ {
public: public:
/** /**
* Simple ctor with a eoGenOp. * Simple ctor with a eoGenOp.
@ -73,9 +73,9 @@ public:
* @param _op variation operator * @param _op variation operator
*/ */
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) : moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
genBreed(select, _op), breed(genBreed) genBreed(select, _op), breed(genBreed)
{} {}
@ -86,9 +86,9 @@ public:
* @param _op variation operator * @param _op variation operator
*/ */
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) : moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
genBreed(select, _op), breed(genBreed) genBreed(select, _op), breed(genBreed)
{} {}
@ -102,9 +102,9 @@ public:
* @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), popEval(_eval), select (2),
replace (fitnessAssignment, diversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), replace (fitnessAssignment, diversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut),
genBreed (select, defaultSGAGenOp), breed (genBreed) genBreed (select, defaultSGAGenOp), breed (genBreed)
{} {}
@ -115,9 +115,9 @@ public:
* @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), popEval(_eval), select(2),
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0),
genBreed(select, _op), breed(genBreed) genBreed(select, _op), breed(genBreed)
{} {}
@ -128,9 +128,9 @@ public:
* @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 > & _op) :
continuator(_continuator), popEval(_eval), select(2), continuator(_continuator), popEval(_eval), select(2),
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
genBreed(select, _op), breed(genBreed) genBreed(select, _op), breed(genBreed)
{} {}
@ -140,24 +140,25 @@ public:
*/ */
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;
@ -184,6 +185,6 @@ protected:
/** breeder */ /** breeder */
eoBreed < MOEOT > & breed; eoBreed < MOEOT > & breed;
}; };
#endif /*MOEONSGAII_H_*/ #endif /*MOEONSGAII_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoArchive.h> * <moeoArchive.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -47,8 +47,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoArchive : public eoPop < MOEOT > class moeoArchive : public eoPop < MOEOT >
{ {
public: public:
using eoPop < MOEOT > :: size; using eoPop < MOEOT > :: size;
using eoPop < MOEOT > :: operator[]; using eoPop < MOEOT > :: operator[];
@ -83,17 +83,17 @@ public:
* @param _objectiveVector the objective vector to compare with the current archive * @param _objectiveVector the objective vector to compare with the current archive
*/ */
bool dominates (const ObjectiveVector & _objectiveVector) const bool dominates (const ObjectiveVector & _objectiveVector) const
{ {
for (unsigned int i = 0; i<size(); i++) for (unsigned int i = 0; i<size(); i++)
{ {
// if _objectiveVector is dominated by the ith individual of the archive... // if _objectiveVector is dominated by the ith individual of the archive...
if ( comparator(_objectiveVector, operator[](i).objectiveVector()) ) if ( comparator(_objectiveVector, operator[](i).objectiveVector()) )
{ {
return true; return true;
} }
} }
return false; return false;
} }
/** /**
@ -101,16 +101,16 @@ public:
* @param _objectiveVector the objective vector to compare with the current archive * @param _objectiveVector the objective vector to compare with the current archive
*/ */
bool contains (const ObjectiveVector & _objectiveVector) const bool contains (const ObjectiveVector & _objectiveVector) const
{ {
for (unsigned int i = 0; i<size(); i++) for (unsigned int i = 0; i<size(); i++)
{ {
if (operator[](i).objectiveVector() == _objectiveVector) if (operator[](i).objectiveVector() == _objectiveVector)
{ {
return true; return true;
} }
} }
return false; return false;
} }
/** /**
@ -119,39 +119,39 @@ public:
*/ */
void update (const MOEOT & _moeo) void update (const MOEOT & _moeo)
{ {
// first step: removing the dominated solutions from the archive // first step: removing the dominated solutions from the archive
for (unsigned int j=0; j<size();) for (unsigned int j=0; j<size();)
{ {
// if the jth solution contained in the archive is dominated by _moeo // if the jth solution contained in the archive is dominated by _moeo
if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) ) if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
{ {
operator[](j) = back(); operator[](j) = back();
pop_back(); pop_back();
} }
else if (_moeo.objectiveVector() == operator[](j).objectiveVector()) else if (_moeo.objectiveVector() == operator[](j).objectiveVector())
{ {
operator[](j) = back(); operator[](j) = back();
pop_back(); pop_back();
} }
else else
{ {
j++; j++;
} }
} }
// second step: is _moeo dominated? // second step: is _moeo dominated?
bool dom = false; bool dom = false;
for (unsigned int j=0; j<size(); j++) for (unsigned int j=0; j<size(); j++)
{ {
// if _moeo is dominated by the jth solution contained in the archive // if _moeo is dominated by the jth solution contained in the archive
if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) ) if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
{ {
dom = true; dom = true;
break; break;
} }
} }
if (!dom) if (!dom)
{ {
push_back(_moeo); push_back(_moeo);
} }
} }
@ -162,9 +162,9 @@ public:
*/ */
void update (const eoPop < MOEOT > & _pop) void update (const eoPop < MOEOT > & _pop)
{ {
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
update(_pop[i]); update(_pop[i]);
} }
} }
@ -175,31 +175,31 @@ public:
*/ */
bool equals (const moeoArchive < MOEOT > & _arch) bool equals (const moeoArchive < MOEOT > & _arch)
{ {
for (unsigned int i=0; i<size(); i++) for (unsigned int i=0; i<size(); i++)
{ {
if (! _arch.contains(operator[](i).objectiveVector())) if (! _arch.contains(operator[](i).objectiveVector()))
{ {
return false; return false;
} }
} }
for (unsigned int i=0; i<_arch.size() ; i++) for (unsigned int i=0; i<_arch.size() ; i++)
{ {
if (! contains(_arch[i].objectiveVector())) if (! contains(_arch[i].objectiveVector()))
{ {
return false; return false;
} }
} }
return true; return true;
} }
private: private:
/** The moeoObjectiveVectorComparator used to compare solutions */ /** The moeoObjectiveVectorComparator used to compare solutions */
moeoObjectiveVectorComparator < ObjectiveVector > & comparator; moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
/** A moeoObjectiveVectorComparator based on Pareto dominance (used as default) */ /** A moeoObjectiveVectorComparator based on Pareto dominance (used as default) */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator; moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
}; };
#endif /*MOEOARCHIVE_H_ */ #endif /*MOEOARCHIVE_H_ */

View file

@ -1,4 +1,4 @@
/* /*
* <moeoAggregativeComparator.h> * <moeoAggregativeComparator.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,8 +45,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoAggregativeComparator : public moeoComparator < MOEOT > class moeoAggregativeComparator : public moeoComparator < MOEOT >
{ {
public: public:
/** /**
* Ctor. * Ctor.
@ -64,17 +64,17 @@ public:
*/ */
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{ {
return ( weightFitness * _moeo1.fitness() + weightDiversity * _moeo1.diversity() ) < ( weightFitness * _moeo2.fitness() + weightDiversity * _moeo2.diversity() ); return ( weightFitness * _moeo1.fitness() + weightDiversity * _moeo1.diversity() ) < ( weightFitness * _moeo2.fitness() + weightDiversity * _moeo2.diversity() );
} }
private: private:
/** the weight for fitness */ /** the weight for fitness */
double weightFitness; double weightFitness;
/** the weight for diversity */ /** the weight for diversity */
double weightDiversity; double weightDiversity;
}; };
#endif /*MOEOAGGREGATIVECOMPARATOR_H_*/ #endif /*MOEOAGGREGATIVECOMPARATOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoComparator.h> * <moeoComparator.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -44,6 +44,7 @@
* Functor allowing to compare two solutions. * Functor allowing to compare two solutions.
*/ */
template < class MOEOT > template < class MOEOT >
class moeoComparator : public eoBF < const MOEOT &, const MOEOT &, const bool > {}; class moeoComparator : public eoBF < const MOEOT &, const MOEOT &, const bool >
{};
#endif /*MOEOCOMPARATOR_H_*/ #endif /*MOEOCOMPARATOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoDiversityThenFitnessComparator.h> * <moeoDiversityThenFitnessComparator.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,8 +45,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoDiversityThenFitnessComparator : public moeoComparator < MOEOT > class moeoDiversityThenFitnessComparator : public moeoComparator < MOEOT >
{ {
public: public:
/** /**
* Returns true if _moeo1 < _moeo2 according to their diversity values, then according to their fitness values * Returns true if _moeo1 < _moeo2 according to their diversity values, then according to their fitness values
@ -55,16 +55,16 @@ public:
*/ */
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{ {
if (_moeo1.diversity() == _moeo2.diversity()) if (_moeo1.diversity() == _moeo2.diversity())
{ {
return _moeo1.fitness() < _moeo2.fitness(); return _moeo1.fitness() < _moeo2.fitness();
} }
else else
{ {
return _moeo1.diversity() < _moeo2.diversity(); return _moeo1.diversity() < _moeo2.diversity();
} }
} }
}; };
#endif /*MOEODIVERSITYTHENFITNESSCOMPARATOR_H_*/ #endif /*MOEODIVERSITYTHENFITNESSCOMPARATOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoFitnessThenDiversityComparator.h> * <moeoFitnessThenDiversityComparator.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,8 +45,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoFitnessThenDiversityComparator : public moeoComparator < MOEOT > class moeoFitnessThenDiversityComparator : public moeoComparator < MOEOT >
{ {
public: public:
/** /**
* Returns true if _moeo1 < _moeo2 according to their fitness values, then according to their diversity values * Returns true if _moeo1 < _moeo2 according to their fitness values, then according to their diversity values
@ -55,16 +55,16 @@ public:
*/ */
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{ {
if (_moeo1.fitness() == _moeo2.fitness()) if (_moeo1.fitness() == _moeo2.fitness())
{ {
return _moeo1.diversity() < _moeo2.diversity(); return _moeo1.diversity() < _moeo2.diversity();
} }
else else
{ {
return _moeo1.fitness() < _moeo2.fitness(); return _moeo1.fitness() < _moeo2.fitness();
} }
} }
}; };
#endif /*MOEOFITNESSTHENDIVERSITYCOMPARATOR_H_*/ #endif /*MOEOFITNESSTHENDIVERSITYCOMPARATOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoGDominanceObjectiveVectorComparator.h> * <moeoGDominanceObjectiveVectorComparator.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -48,8 +48,8 @@
*/ */
template < class ObjectiveVector > template < class ObjectiveVector >
class moeoGDominanceObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector > class moeoGDominanceObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
{ {
public: public:
/** /**
* Ctor. * Ctor.
@ -66,27 +66,27 @@ public:
*/ */
const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
{ {
unsigned int flag1 = flag(_objectiveVector1); unsigned int flag1 = flag(_objectiveVector1);
unsigned int flag2 = flag(_objectiveVector2); unsigned int flag2 = flag(_objectiveVector2);
if (flag2==0) if (flag2==0)
{ {
// cannot dominate // cannot dominate
return false; return false;
} }
else if ( (flag2==1) && (flag1==0) ) else if ( (flag2==1) && (flag1==0) )
{ {
// is dominated // is dominated
return true; return true;
} }
else // (flag1==1) && (flag2==1) else // (flag1==1) && (flag2==1)
{ {
// both are on the good region, so let's use the classical Pareto dominance // both are on the good region, so let's use the classical Pareto dominance
return paretoComparator(_objectiveVector1, _objectiveVector2); return paretoComparator(_objectiveVector1, _objectiveVector2);
} }
} }
private: private:
/** the reference point */ /** the reference point */
ObjectiveVector & ref; ObjectiveVector & ref;
@ -100,28 +100,28 @@ private:
*/ */
unsigned int flag(const ObjectiveVector & _objectiveVector) unsigned int flag(const ObjectiveVector & _objectiveVector)
{ {
unsigned int result=1; unsigned int result=1;
for (unsigned int i=0; i<ref.nObjectives(); i++) for (unsigned int i=0; i<ref.nObjectives(); i++)
{ {
if (_objectiveVector[i] > ref[i]) if (_objectiveVector[i] > ref[i])
{ {
result=0; result=0;
} }
} }
if (result==0) if (result==0)
{ {
result=1; result=1;
for (unsigned int i=0; i<ref.nObjectives(); i++) for (unsigned int i=0; i<ref.nObjectives(); i++)
{ {
if (_objectiveVector[i] < ref[i]) if (_objectiveVector[i] < ref[i])
{ {
result=0; result=0;
} }
} }
} }
return result; return result;
} }
}; };
#endif /*MOEOGDOMINANCEOBJECTIVEVECTORCOMPARATOR_H_*/ #endif /*MOEOGDOMINANCEOBJECTIVEVECTORCOMPARATOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoObjectiveObjectiveVectorComparator.h> * <moeoObjectiveObjectiveVectorComparator.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,8 +45,8 @@
*/ */
template < class ObjectiveVector > template < class ObjectiveVector >
class moeoObjectiveObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector > class moeoObjectiveObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
{ {
public: public:
/** /**
* Returns true if _objectiveVector1 < _objectiveVector2 on the first objective, then on the second, and so on * Returns true if _objectiveVector1 < _objectiveVector2 on the first objective, then on the second, and so on
@ -55,23 +55,23 @@ public:
*/ */
const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
{ {
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++) for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
{ {
if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() ) if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() )
{ {
if (_objectiveVector1[i] < _objectiveVector2[i]) if (_objectiveVector1[i] < _objectiveVector2[i])
{ {
return true; return true;
} }
else else
{ {
return false; return false;
} }
} }
} }
return false; return false;
} }
}; };
#endif /*MOEOOBJECTIVEOBJECTIVEVECTORCOMPARATOR_H_*/ #endif /*MOEOOBJECTIVEOBJECTIVEVECTORCOMPARATOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoObjectiveVectorComparator.h> * <moeoObjectiveVectorComparator.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -46,6 +46,7 @@
* The template argument ObjectiveVector have to be a moeoObjectiveVector. * The template argument ObjectiveVector have to be a moeoObjectiveVector.
*/ */
template < class ObjectiveVector > template < class ObjectiveVector >
class moeoObjectiveVectorComparator : public eoBF < const ObjectiveVector &, const ObjectiveVector &, const bool > {}; class moeoObjectiveVectorComparator : public eoBF < const ObjectiveVector &, const ObjectiveVector &, const bool >
{};
#endif /*MOEOOBJECTIVEVECTORCOMPARATOR_H_*/ #endif /*MOEOOBJECTIVEVECTORCOMPARATOR_H_*/

Some files were not shown because too many files have changed in this diff Show more