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_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoOneObjectiveComparator.h> * <moeoOneObjectiveComparator.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 moeoOneObjectiveComparator : public moeoComparator < MOEOT > class moeoOneObjectiveComparator : public moeoComparator < MOEOT >
{ {
public: public:
/** /**
* Ctor. * Ctor.
@ -54,9 +54,9 @@ public:
*/ */
moeoOneObjectiveComparator(unsigned int _obj) : obj(_obj) moeoOneObjectiveComparator(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 moeoOneObjectiveComparator"); throw std::runtime_error("Problem with the index of objective in moeoOneObjectiveComparator");
} }
} }
@ -68,15 +68,15 @@ public:
*/ */
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{ {
return _moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj]; return _moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj];
} }
private: private:
/** the index of objective */ /** the index of objective */
unsigned int obj; unsigned int obj;
}; };
#endif /*MOEOONEOBJECTIVECOMPARATOR_H_*/ #endif /*MOEOONEOBJECTIVECOMPARATOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoParetoObjectiveVectorComparator.h> * <moeoParetoObjectiveVectorComparator.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 moeoParetoObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector > class moeoParetoObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
{ {
public: public:
/** /**
* Returns true if _objectiveVector1 is dominated by _objectiveVector2 * Returns true if _objectiveVector1 is dominated by _objectiveVector2
@ -55,41 +55,41 @@ public:
*/ */
const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
{ {
bool dom = false; bool dom = false;
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++) for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
{ {
// first, we have to check if the 2 objective values are not equal for the ith objective // first, we have to check if the 2 objective values are not equal for the ith objective
if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() ) if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() )
{ {
// if the ith objective have to be minimized... // if the ith objective have to be minimized...
if (ObjectiveVector::minimizing(i)) if (ObjectiveVector::minimizing(i))
{ {
if (_objectiveVector1[i] > _objectiveVector2[i]) if (_objectiveVector1[i] > _objectiveVector2[i])
{ {
dom = true; //_objectiveVector1[i] is not better than _objectiveVector2[i] dom = true; //_objectiveVector1[i] is not better than _objectiveVector2[i]
} }
else else
{ {
return false; //_objectiveVector2 cannot dominate _objectiveVector1 return false; //_objectiveVector2 cannot dominate _objectiveVector1
} }
} }
// if the ith objective have to be maximized... // if the ith objective have to be maximized...
else if (ObjectiveVector::maximizing(i)) else if (ObjectiveVector::maximizing(i))
{ {
if (_objectiveVector1[i] < _objectiveVector2[i]) if (_objectiveVector1[i] < _objectiveVector2[i])
{ {
dom = true; //_objectiveVector1[i] is not better than _objectiveVector2[i] dom = true; //_objectiveVector1[i] is not better than _objectiveVector2[i]
} }
else else
{ {
return false; //_objectiveVector2 cannot dominate _objectiveVector1 return false; //_objectiveVector2 cannot dominate _objectiveVector1
} }
} }
} }
} }
return dom; return dom;
} }
}; };
#endif /*MOEOPARETOOBJECTIVEVECTORCOMPARATOR_H_*/ #endif /*MOEOPARETOOBJECTIVEVECTORCOMPARATOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <MOEO.h> * <MOEO.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
@ -57,8 +57,8 @@
*/ */
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity > template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
class MOEO : public EO < MOEOObjectiveVector > class MOEO : public EO < MOEOObjectiveVector >
{ {
public: public:
/** the objective vector type of a solution */ /** the objective vector type of a solution */
typedef MOEOObjectiveVector ObjectiveVector; typedef MOEOObjectiveVector ObjectiveVector;
@ -75,32 +75,33 @@ public:
*/ */
MOEO() MOEO()
{ {
// default values for every parameters // default values for every parameters
objectiveVectorValue = ObjectiveVector(); objectiveVectorValue = ObjectiveVector();
fitnessValue = Fitness(); fitnessValue = Fitness();
diversityValue = Diversity(); diversityValue = Diversity();
// invalidate all // invalidate all
invalidate(); invalidate();
} }
/** /**
* Virtual dtor * Virtual dtor
*/ */
virtual ~MOEO() {}; virtual ~MOEO()
{};
/** /**
* Returns the objective vector of the current solution * Returns the objective vector of the current solution
*/ */
ObjectiveVector objectiveVector() const ObjectiveVector objectiveVector() const
{ {
if ( invalidObjectiveVector() ) if ( invalidObjectiveVector() )
{ {
throw std::runtime_error("invalid objective vector in MOEO"); throw std::runtime_error("invalid objective vector in MOEO");
} }
return objectiveVectorValue; return objectiveVectorValue;
} }
/** /**
@ -109,8 +110,8 @@ public:
*/ */
void objectiveVector(const ObjectiveVector & _objectiveVectorValue) void objectiveVector(const ObjectiveVector & _objectiveVectorValue)
{ {
objectiveVectorValue = _objectiveVectorValue; objectiveVectorValue = _objectiveVectorValue;
invalidObjectiveVectorValue = false; invalidObjectiveVectorValue = false;
} }
@ -119,7 +120,7 @@ public:
*/ */
void invalidateObjectiveVector() void invalidateObjectiveVector()
{ {
invalidObjectiveVectorValue = true; invalidObjectiveVectorValue = true;
} }
@ -127,22 +128,22 @@ public:
* Returns true if the objective vector is invalid, false otherwise * Returns true if the objective vector is invalid, false otherwise
*/ */
bool invalidObjectiveVector() const bool invalidObjectiveVector() const
{ {
return invalidObjectiveVectorValue; return invalidObjectiveVectorValue;
} }
/** /**
* Returns the fitness value of the current solution * Returns the fitness value of the current solution
*/ */
Fitness fitness() const Fitness fitness() const
{ {
if ( invalidFitness() ) if ( invalidFitness() )
{ {
throw std::runtime_error("invalid fitness in MOEO"); throw std::runtime_error("invalid fitness in MOEO");
} }
return fitnessValue; return fitnessValue;
} }
/** /**
@ -151,8 +152,8 @@ public:
*/ */
void fitness(const Fitness & _fitnessValue) void fitness(const Fitness & _fitnessValue)
{ {
fitnessValue = _fitnessValue; fitnessValue = _fitnessValue;
invalidFitnessValue = false; invalidFitnessValue = false;
} }
@ -161,7 +162,7 @@ public:
*/ */
void invalidateFitness() void invalidateFitness()
{ {
invalidFitnessValue = true; invalidFitnessValue = true;
} }
@ -169,22 +170,22 @@ public:
* Returns true if the fitness value is invalid, false otherwise * Returns true if the fitness value is invalid, false otherwise
*/ */
bool invalidFitness() const bool invalidFitness() const
{ {
return invalidFitnessValue; return invalidFitnessValue;
} }
/** /**
* Returns the diversity value of the current solution * Returns the diversity value of the current solution
*/ */
Diversity diversity() const Diversity diversity() const
{ {
if ( invalidDiversity() ) if ( invalidDiversity() )
{ {
throw std::runtime_error("invalid diversity in MOEO"); throw std::runtime_error("invalid diversity in MOEO");
} }
return diversityValue; return diversityValue;
} }
/** /**
@ -193,8 +194,8 @@ public:
*/ */
void diversity(const Diversity & _diversityValue) void diversity(const Diversity & _diversityValue)
{ {
diversityValue = _diversityValue; diversityValue = _diversityValue;
invalidDiversityValue = false; invalidDiversityValue = false;
} }
@ -203,7 +204,7 @@ public:
*/ */
void invalidateDiversity() void invalidateDiversity()
{ {
invalidDiversityValue = true; invalidDiversityValue = true;
} }
@ -211,9 +212,9 @@ public:
* Returns true if the diversity value is invalid, false otherwise * Returns true if the diversity value is invalid, false otherwise
*/ */
bool invalidDiversity() const bool invalidDiversity() const
{ {
return invalidDiversityValue; return invalidDiversityValue;
} }
/** /**
@ -221,9 +222,9 @@ public:
*/ */
void invalidate() void invalidate()
{ {
invalidateObjectiveVector(); invalidateObjectiveVector();
invalidateFitness(); invalidateFitness();
invalidateDiversity(); invalidateDiversity();
} }
@ -231,9 +232,9 @@ public:
* Returns true if the fitness value is invalid, false otherwise * Returns true if the fitness value is invalid, false otherwise
*/ */
bool invalid() const bool invalid() const
{ {
return invalidObjectiveVector(); return invalidObjectiveVector();
} }
/** /**
@ -243,18 +244,18 @@ public:
* @param _other the other MOEO object to compare with * @param _other the other MOEO object to compare with
*/ */
bool operator<(const MOEO & _other) const bool operator<(const MOEO & _other) const
{ {
return objectiveVector() < _other.objectiveVector(); return objectiveVector() < _other.objectiveVector();
} }
/** /**
* Return the class id (the class name as a std::string) * Return the class id (the class name as a std::string)
*/ */
virtual std::string className() const virtual std::string className() const
{ {
return "MOEO"; return "MOEO";
} }
/** /**
@ -262,16 +263,16 @@ public:
* @param _os output stream * @param _os output stream
*/ */
virtual void printOn(std::ostream & _os) const virtual void printOn(std::ostream & _os) const
{ {
if ( invalidObjectiveVector() ) if ( invalidObjectiveVector() )
{ {
_os << "INVALID\t"; _os << "INVALID\t";
} }
else else
{ {
_os << objectiveVectorValue << '\t'; _os << objectiveVectorValue << '\t';
} }
} }
/** /**
@ -280,23 +281,23 @@ public:
*/ */
virtual void readFrom(std::istream & _is) virtual void readFrom(std::istream & _is)
{ {
std::string objectiveVector_str; std::string objectiveVector_str;
int pos = _is.tellg(); int pos = _is.tellg();
_is >> objectiveVector_str; _is >> objectiveVector_str;
if (objectiveVector_str == "INVALID") if (objectiveVector_str == "INVALID")
{ {
invalidateObjectiveVector(); invalidateObjectiveVector();
} }
else else
{ {
invalidObjectiveVectorValue = false; invalidObjectiveVectorValue = false;
_is.seekg(pos); // rewind _is.seekg(pos); // rewind
_is >> objectiveVectorValue; _is >> objectiveVectorValue;
} }
} }
private: private:
/** the objective vector of this solution */ /** the objective vector of this solution */
ObjectiveVector objectiveVectorValue; ObjectiveVector objectiveVectorValue;
@ -311,6 +312,6 @@ private:
/** true if the diversity value is invalid */ /** true if the diversity value is invalid */
bool invalidDiversityValue; bool invalidDiversityValue;
}; };
#endif /*MOEO_H_*/ #endif /*MOEO_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoBitVector.h> * <moeoBitVector.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 MOEOObjectiveVector, class MOEOFitness, class MOEODiversity > template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
class moeoBitVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > class moeoBitVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool >
{ {
public: public:
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: begin; using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: begin;
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: end; using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: end;
@ -67,22 +67,22 @@ public:
* Returns the class name as a std::string * Returns the class name as a std::string
*/ */
virtual std::string className() const virtual std::string className() const
{ {
return "moeoBitVector"; return "moeoBitVector";
} }
/** /**
* Writing object * Writing object
* @param _os output stream * @param _os output stream
*/ */
virtual void printOn(std::ostream & _os) const virtual void printOn(std::ostream & _os) const
{ {
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os); MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os);
_os << ' '; _os << ' ';
_os << size() << ' '; _os << size() << ' ';
std::copy(begin(), end(), std::ostream_iterator<bool>(_os)); std::copy(begin(), end(), std::ostream_iterator<bool>(_os));
} }
/** /**
@ -91,18 +91,18 @@ public:
*/ */
virtual void readFrom(std::istream & _is) virtual void readFrom(std::istream & _is)
{ {
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is); MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is);
unsigned int s; unsigned int s;
_is >> s; _is >> s;
std::string bits; std::string bits;
_is >> bits; _is >> bits;
if (_is) if (_is)
{ {
resize(bits.size()); resize(bits.size());
std::transform(bits.begin(), bits.end(), begin(), std::bind2nd(std::equal_to<char>(), '1')); std::transform(bits.begin(), bits.end(), begin(), std::bind2nd(std::equal_to<char>(), '1'));
} }
} }
}; };
#endif /*MOEOBITVECTOR_H_*/ #endif /*MOEOBITVECTOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoEvalFunc.h> * <moeoEvalFunc.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 that evaluates one MOEO by setting all its objective values. * Functor that evaluates one MOEO by setting all its objective values.
*/ */
template < class MOEOT > template < class MOEOT >
class moeoEvalFunc : public eoEvalFunc< MOEOT > {}; class moeoEvalFunc : public eoEvalFunc< MOEOT >
{};
#endif /*MOEOEVALFUNC_H_*/ #endif /*MOEOEVALFUNC_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoObjectiveVector.h> * <moeoObjectiveVector.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 ObjectiveVectorTraits, class ObjectiveVectorType > template < class ObjectiveVectorTraits, class ObjectiveVectorType >
class moeoObjectiveVector : public std::vector < ObjectiveVectorType > class moeoObjectiveVector : public std::vector < ObjectiveVectorType >
{ {
public: public:
/** The traits of objective vectors */ /** The traits of objective vectors */
typedef ObjectiveVectorTraits Traits; typedef ObjectiveVectorTraits Traits;
@ -79,7 +79,7 @@ public:
*/ */
static void setup(unsigned int _nObjectives, std::vector < bool > & _bObjectives) static void setup(unsigned int _nObjectives, std::vector < bool > & _bObjectives)
{ {
ObjectiveVectorTraits::setup(_nObjectives, _bObjectives); ObjectiveVectorTraits::setup(_nObjectives, _bObjectives);
} }
@ -88,7 +88,7 @@ public:
*/ */
static unsigned int nObjectives() static unsigned int nObjectives()
{ {
return ObjectiveVectorTraits::nObjectives(); return ObjectiveVectorTraits::nObjectives();
} }
@ -98,7 +98,7 @@ public:
*/ */
static bool minimizing(unsigned int _i) static bool minimizing(unsigned int _i)
{ {
return ObjectiveVectorTraits::minimizing(_i); return ObjectiveVectorTraits::minimizing(_i);
} }
@ -108,9 +108,9 @@ public:
*/ */
static bool maximizing(unsigned int _i) static bool maximizing(unsigned int _i)
{ {
return ObjectiveVectorTraits::maximizing(_i); return ObjectiveVectorTraits::maximizing(_i);
} }
}; };
#endif /*MOEOOBJECTIVEVECTOR_H_*/ #endif /*MOEOOBJECTIVEVECTOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoObjectiveVectorTraits.cpp> * <moeoObjectiveVectorTraits.cpp>
* 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

View file

@ -1,4 +1,4 @@
/* /*
* <moeoObjectiveVectorTraits.h> * <moeoObjectiveVectorTraits.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,8 +46,8 @@
* A traits class for moeoObjectiveVector to specify the number of objectives and which ones have to be minimized or maximized. * A traits class for moeoObjectiveVector to specify the number of objectives and which ones have to be minimized or maximized.
*/ */
class moeoObjectiveVectorTraits class moeoObjectiveVectorTraits
{ {
public: public:
/** /**
* Parameters setting * Parameters setting
@ -56,20 +56,21 @@ public:
*/ */
static void setup(unsigned int _nObjectives, std::vector < bool > & _bObjectives) static void setup(unsigned int _nObjectives, std::vector < bool > & _bObjectives)
{ {
// in case the number of objectives was already set to a different value // in case the number of objectives was already set to a different value
if ( nObj && (nObj != _nObjectives) ) { if ( nObj && (nObj != _nObjectives) )
std::cout << "WARNING\n"; {
std::cout << "WARNING : the number of objectives are changing\n"; std::cout << "WARNING\n";
std::cout << "WARNING : Make sure all existing objects are destroyed\n"; std::cout << "WARNING : the number of objectives are changing\n";
std::cout << "WARNING\n"; std::cout << "WARNING : Make sure all existing objects are destroyed\n";
std::cout << "WARNING\n";
} }
// number of objectives // number of objectives
nObj = _nObjectives; nObj = _nObjectives;
// min/max vector // min/max vector
bObj = _bObjectives; bObj = _bObjectives;
// in case the number of objectives and the min/max vector size don't match // in case the number of objectives and the min/max vector size don't match
if (nObj != bObj.size()) if (nObj != bObj.size())
throw std::runtime_error("Number of objectives and min/max size don't match in moeoObjectiveVectorTraits::setup"); throw std::runtime_error("Number of objectives and min/max size don't match in moeoObjectiveVectorTraits::setup");
} }
@ -78,10 +79,10 @@ public:
*/ */
static unsigned int nObjectives() static unsigned int nObjectives()
{ {
// in case the number of objectives would not be assigned yet // in case the number of objectives would not be assigned yet
if (! nObj) if (! nObj)
throw std::runtime_error("Number of objectives not assigned in moeoObjectiveVectorTraits"); throw std::runtime_error("Number of objectives not assigned in moeoObjectiveVectorTraits");
return nObj; return nObj;
} }
@ -91,10 +92,10 @@ public:
*/ */
static bool minimizing(unsigned int _i) static bool minimizing(unsigned int _i)
{ {
// in case there would be a wrong index // in case there would be a wrong index
if (_i >= bObj.size()) if (_i >= bObj.size())
throw std::runtime_error("Wrong index in moeoObjectiveVectorTraits"); throw std::runtime_error("Wrong index in moeoObjectiveVectorTraits");
return bObj[_i]; return bObj[_i];
} }
@ -102,8 +103,9 @@ public:
* Returns true if the _ith objective have to be maximized * Returns true if the _ith objective have to be maximized
* @param _i the index * @param _i the index
*/ */
static bool maximizing(unsigned int _i) { static bool maximizing(unsigned int _i)
return (! minimizing(_i)); {
return (! minimizing(_i));
} }
@ -112,17 +114,17 @@ public:
*/ */
static double tolerance() static double tolerance()
{ {
return 1e-6; return 1e-6;
} }
private: private:
/** The number of objectives */ /** The number of objectives */
static unsigned int nObj; static unsigned int nObj;
/** The min/max vector */ /** The min/max vector */
static std::vector < bool > bObj; static std::vector < bool > bObj;
}; };
#endif /*MOEOOBJECTIVEVECTORTRAITS_H_*/ #endif /*MOEOOBJECTIVEVECTORTRAITS_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoRealObjectiveVector.h> * <moeoRealObjectiveVector.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
@ -50,8 +50,8 @@
*/ */
template < class ObjectiveVectorTraits > template < class ObjectiveVectorTraits >
class moeoRealObjectiveVector : public moeoObjectiveVector < ObjectiveVectorTraits, double > class moeoRealObjectiveVector : public moeoObjectiveVector < ObjectiveVectorTraits, double >
{ {
public: public:
using moeoObjectiveVector < ObjectiveVectorTraits, double >::size; using moeoObjectiveVector < ObjectiveVectorTraits, double >::size;
using moeoObjectiveVector < ObjectiveVectorTraits, double >::operator[]; using moeoObjectiveVector < ObjectiveVectorTraits, double >::operator[];
@ -77,10 +77,10 @@ public:
* @param _other the other moeoRealObjectiveVector object to compare with * @param _other the other moeoRealObjectiveVector object to compare with
*/ */
bool dominates(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const bool dominates(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{ {
moeoParetoObjectiveVectorComparator < moeoRealObjectiveVector<ObjectiveVectorTraits> > comparator; moeoParetoObjectiveVectorComparator < moeoRealObjectiveVector<ObjectiveVectorTraits> > comparator;
return comparator(_other, *this); return comparator(_other, *this);
} }
/** /**
@ -88,16 +88,16 @@ public:
* @param _other the other moeoRealObjectiveVector object to compare with * @param _other the other moeoRealObjectiveVector object to compare with
*/ */
bool operator==(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const bool operator==(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{ {
for (unsigned int i=0; i < size(); i++) for (unsigned int i=0; i < size(); i++)
{ {
if ( fabs(operator[](i) - _other[i]) > ObjectiveVectorTraits::tolerance() ) if ( fabs(operator[](i) - _other[i]) > ObjectiveVectorTraits::tolerance() )
{ {
return false; return false;
} }
} }
return true; return true;
} }
/** /**
@ -105,9 +105,9 @@ public:
* @param _other the other moeoRealObjectiveVector object to compare with * @param _other the other moeoRealObjectiveVector object to compare with
*/ */
bool operator!=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const bool operator!=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{ {
return ! operator==(_other); return ! operator==(_other);
} }
/** /**
@ -116,10 +116,10 @@ public:
* @param _other the other moeoRealObjectiveVector object to compare with * @param _other the other moeoRealObjectiveVector object to compare with
*/ */
bool operator<(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const bool operator<(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{ {
moeoObjectiveObjectiveVectorComparator < moeoRealObjectiveVector < ObjectiveVectorTraits > > cmp; moeoObjectiveObjectiveVectorComparator < moeoRealObjectiveVector < ObjectiveVectorTraits > > cmp;
return cmp(*this, _other); return cmp(*this, _other);
} }
/** /**
@ -128,9 +128,9 @@ public:
* @param _other the other moeoRealObjectiveVector object to compare with * @param _other the other moeoRealObjectiveVector object to compare with
*/ */
bool operator>(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const bool operator>(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{ {
return _other < *this; return _other < *this;
} }
/** /**
@ -139,9 +139,9 @@ public:
* @param _other the other moeoRealObjectiveVector object to compare with * @param _other the other moeoRealObjectiveVector object to compare with
*/ */
bool operator<=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const bool operator<=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{ {
return operator==(_other) || operator<(_other); return operator==(_other) || operator<(_other);
} }
/** /**
@ -150,11 +150,11 @@ public:
* @param _other the other moeoRealObjectiveVector object to compare with * @param _other the other moeoRealObjectiveVector object to compare with
*/ */
bool operator>=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const bool operator>=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{ {
return operator==(_other) || operator>(_other); return operator==(_other) || operator>(_other);
} }
}; };
/** /**
@ -165,11 +165,11 @@ public:
template < class ObjectiveVectorTraits > template < class ObjectiveVectorTraits >
std::ostream & operator<<(std::ostream & _os, const moeoRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector) std::ostream & operator<<(std::ostream & _os, const moeoRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector)
{ {
for (unsigned int i=0; i<_objectiveVector.size(); i++) for (unsigned int i=0; i<_objectiveVector.size(); i++)
{ {
_os << _objectiveVector[i] << '\t'; _os << _objectiveVector[i] << '\t';
} }
return _os; return _os;
} }
/** /**
@ -180,12 +180,12 @@ std::ostream & operator<<(std::ostream & _os, const moeoRealObjectiveVector < Ob
template < class ObjectiveVectorTraits > template < class ObjectiveVectorTraits >
std::istream & operator>>(std::istream & _is, moeoRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector) std::istream & operator>>(std::istream & _is, moeoRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector)
{ {
_objectiveVector = moeoRealObjectiveVector < ObjectiveVectorTraits > (); _objectiveVector = moeoRealObjectiveVector < ObjectiveVectorTraits > ();
for (unsigned int i=0; i<_objectiveVector.size(); i++) for (unsigned int i=0; i<_objectiveVector.size(); i++)
{ {
_is >> _objectiveVector[i]; _is >> _objectiveVector[i];
} }
return _is; return _is;
} }
#endif /*MOEOREALOBJECTIVEVECTOR_H_*/ #endif /*MOEOREALOBJECTIVEVECTOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoRealVector.h> * <moeoRealVector.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 MOEOObjectiveVector, class MOEOFitness, class MOEODiversity > template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
class moeoRealVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, double > class moeoRealVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, double >
{ {
public: public:
/** /**
* Ctor * Ctor
@ -55,16 +55,16 @@ public:
*/ */
moeoRealVector(unsigned int _size = 0, double _value = 0.0) : moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, double >(_size, _value) moeoRealVector(unsigned int _size = 0, double _value = 0.0) : moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, double >(_size, _value)
{} {}
/** /**
* Returns the class name as a std::string * Returns the class name as a std::string
*/ */
virtual std::string className() const virtual std::string className() const
{ {
return "moeoRealVector"; return "moeoRealVector";
} }
}; };
#endif /*MOEOREALVECTOR_H_*/ #endif /*MOEOREALVECTOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoVector.h> * <moeoVector.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 MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType > template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType >
class moeoVector : public MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >, public std::vector < GeneType > class moeoVector : public MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >, public std::vector < GeneType >
{ {
public: public:
using MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity > :: invalidate; using MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity > :: invalidate;
using std::vector < GeneType > :: operator[]; using std::vector < GeneType > :: operator[];
@ -70,30 +70,30 @@ public:
* @param _value Initial value of all elements (default is default value of type GeneType) * @param _value Initial value of all elements (default is default value of type GeneType)
*/ */
moeoVector(unsigned int _size = 0, GeneType _value = GeneType()) : moeoVector(unsigned int _size = 0, GeneType _value = GeneType()) :
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >(), std::vector<GeneType>(_size, _value) MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >(), std::vector<GeneType>(_size, _value)
{} {}
/** /**
* We can't have a Ctor from a std::vector as it would create ambiguity with the copy Ctor. * We can't have a Ctor from a std::vector as it would create ambiguity with the copy Ctor.
* @param _v a vector of GeneType * @param _v a vector of GeneType
*/ */
void value(const std::vector < GeneType > & _v) void value(const std::vector < GeneType > & _v)
{ {
if (_v.size() != size()) // safety check if (_v.size() != size()) // safety check
{ {
if (size()) // NOT an initial empty std::vector if (size()) // NOT an initial empty std::vector
{ {
std::cout << "Warning: Changing size in moeoVector assignation"<<std::endl; std::cout << "Warning: Changing size in moeoVector assignation"<<std::endl;
resize(_v.size()); resize(_v.size());
} }
else else
{ {
throw std::runtime_error("Size not initialized in moeoVector"); throw std::runtime_error("Size not initialized in moeoVector");
} }
} }
std::copy(_v.begin(), _v.end(), begin()); std::copy(_v.begin(), _v.end(), begin());
invalidate(); invalidate();
} }
@ -102,9 +102,9 @@ public:
* @param _moeo the object to compare with * @param _moeo the object to compare with
*/ */
bool operator<(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo) const bool operator<(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo) const
{ {
return MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::operator<(_moeo); return MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::operator<(_moeo);
} }
/** /**
@ -112,12 +112,12 @@ public:
* @param _os output stream * @param _os output stream
*/ */
virtual void printOn(std::ostream & _os) const virtual void printOn(std::ostream & _os) const
{ {
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os); MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os);
_os << ' '; _os << ' ';
_os << size() << ' '; _os << size() << ' ';
std::copy(begin(), end(), std::ostream_iterator<AtomType>(_os, " ")); std::copy(begin(), end(), std::ostream_iterator<AtomType>(_os, " "));
} }
/** /**
@ -126,20 +126,20 @@ public:
*/ */
virtual void readFrom(std::istream & _is) virtual void readFrom(std::istream & _is)
{ {
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is); MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is);
unsigned int sz; unsigned int sz;
_is >> sz; _is >> sz;
resize(sz); resize(sz);
unsigned int i; unsigned int i;
for (i = 0; i < sz; ++i) for (i = 0; i < sz; ++i)
{ {
AtomType atom; AtomType atom;
_is >> atom; _is >> atom;
operator[](i) = atom; operator[](i) = atom;
} }
} }
}; };
/** /**
@ -150,7 +150,7 @@ public:
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType > template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType >
bool operator<(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo1, const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo2) bool operator<(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo1, const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo2)
{ {
return _moeo1.operator<(_moeo2); return _moeo1.operator<(_moeo2);
} }
@ -162,7 +162,7 @@ bool operator<(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType > template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType >
bool operator>(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo1, const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo2) bool operator>(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo1, const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo2)
{ {
return _moeo1.operator>(_moeo2); return _moeo1.operator>(_moeo2);
} }
#endif /*MOEOVECTOR_H_*/ #endif /*MOEOVECTOR_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoDistance.h> * <moeoDistance.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 , class Type > template < class MOEOT , class Type >
class moeoDistance : public eoBF < const MOEOT &, const MOEOT &, const Type > class moeoDistance : public eoBF < const MOEOT &, const MOEOT &, const Type >
{ {
public: public:
/** /**
* Nothing to do * Nothing to do
@ -74,6 +74,6 @@ public:
virtual void setup(eoRealInterval _realInterval, unsigned int _obj) virtual void setup(eoRealInterval _realInterval, unsigned int _obj)
{} {}
}; };
#endif /*MOEODISTANCE_H_*/ #endif /*MOEODISTANCE_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoDistanceMatrix.h> * <moeoDistanceMatrix.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 , class Type > template < class MOEOT , class Type >
class moeoDistanceMatrix : public eoUF < const eoPop < MOEOT > &, void > , public std::vector< std::vector < Type > > class moeoDistanceMatrix : public eoUF < const eoPop < MOEOT > &, void > , public std::vector< std::vector < Type > >
{ {
public: public:
using std::vector< std::vector < Type > > :: size; using std::vector< std::vector < Type > > :: size;
using std::vector< std::vector < Type > > :: operator[]; using std::vector< std::vector < Type > > :: operator[];
@ -61,10 +61,10 @@ public:
*/ */
moeoDistanceMatrix (unsigned int _size, moeoDistance < MOEOT , Type > & _distance) : distance(_distance) moeoDistanceMatrix (unsigned int _size, moeoDistance < MOEOT , Type > & _distance) : distance(_distance)
{ {
this->resize(_size); this->resize(_size);
for (unsigned int i=0; i<_size; i++) for (unsigned int i=0; i<_size; i++)
{ {
this->operator[](i).resize(_size); this->operator[](i).resize(_size);
} }
} }
@ -75,27 +75,27 @@ public:
*/ */
void operator()(const eoPop < MOEOT > & _pop) void operator()(const eoPop < MOEOT > & _pop)
{ {
// 1 - setup the bounds (if necessary) // 1 - setup the bounds (if necessary)
distance.setup(_pop); distance.setup(_pop);
// 2 - compute distances // 2 - compute distances
this->operator[](0).operator[](0) = Type(); this->operator[](0).operator[](0) = Type();
for (unsigned int i=0; i<size(); i++) for (unsigned int i=0; i<size(); i++)
{ {
this->operator[](i).operator[](i) = Type(); this->operator[](i).operator[](i) = Type();
for (unsigned int j=0; j<i; j++) for (unsigned int j=0; j<i; j++)
{ {
this->operator[](i).operator[](j) = distance(_pop[i], _pop[j]); this->operator[](i).operator[](j) = distance(_pop[i], _pop[j]);
this->operator[](j).operator[](i) = this->operator[](i).operator[](j); this->operator[](j).operator[](i) = this->operator[](i).operator[](j);
} }
} }
} }
private: private:
/** the distance to use */ /** the distance to use */
moeoDistance < MOEOT , Type > & distance; moeoDistance < MOEOT , Type > & distance;
}; };
#endif /*MOEODISTANCEMATRIX_H_*/ #endif /*MOEODISTANCEMATRIX_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoEuclideanDistance.h> * <moeoEuclideanDistance.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 moeoEuclideanDistance : public moeoNormalizedDistance < MOEOT > class moeoEuclideanDistance : public moeoNormalizedDistance < MOEOT >
{ {
public: public:
/** the objective vector type of the solutions */ /** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -61,23 +61,23 @@ public:
*/ */
const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{ {
double result = 0.0; double result = 0.0;
double tmp1, tmp2; double tmp1, tmp2;
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++) for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
{ {
tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range(); tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range(); tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
result += (tmp1-tmp2) * (tmp1-tmp2); result += (tmp1-tmp2) * (tmp1-tmp2);
} }
return sqrt(result); return sqrt(result);
} }
private: private:
/** the bounds for every objective */ /** the bounds for every objective */
using moeoNormalizedDistance < MOEOT > :: bounds; using moeoNormalizedDistance < MOEOT > :: bounds;
}; };
#endif /*MOEOEUCLIDEANDISTANCE_H_*/ #endif /*MOEOEUCLIDEANDISTANCE_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoManhattanDistance.h> * <moeoManhattanDistance.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 moeoManhattanDistance : public moeoNormalizedDistance < MOEOT > class moeoManhattanDistance : public moeoNormalizedDistance < MOEOT >
{ {
public: public:
/** the objective vector type of the solutions */ /** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -61,23 +61,23 @@ public:
*/ */
const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{ {
double result = 0.0; double result = 0.0;
double tmp1, tmp2; double tmp1, tmp2;
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++) for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
{ {
tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range(); tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range(); tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
result += fabs(tmp1-tmp2); result += fabs(tmp1-tmp2);
} }
return result; return result;
} }
private: private:
/** the bounds for every objective */ /** the bounds for every objective */
using moeoNormalizedDistance < MOEOT > :: bounds; using moeoNormalizedDistance < MOEOT > :: bounds;
}; };
#endif /*MOEOMANHATTANDISTANCE_H_*/ #endif /*MOEOMANHATTANDISTANCE_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoNormalizedDistance.h> * <moeoNormalizedDistance.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 , class Type = double > template < class MOEOT , class Type = double >
class moeoNormalizedDistance : public moeoDistance < MOEOT , Type > class moeoNormalizedDistance : public moeoDistance < MOEOT , Type >
{ {
public: public:
/** the objective vector type of the solutions */ /** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -59,11 +59,11 @@ public:
*/ */
moeoNormalizedDistance() moeoNormalizedDistance()
{ {
bounds.resize(ObjectiveVector::Traits::nObjectives()); bounds.resize(ObjectiveVector::Traits::nObjectives());
// initialize bounds in case someone does not want to use them // initialize bounds in case someone does not want to use them
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++) for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{ {
bounds[i] = eoRealInterval(0,1); bounds[i] = eoRealInterval(0,1);
} }
} }
@ -73,7 +73,7 @@ public:
*/ */
static double tiny() static double tiny()
{ {
return 1e-6; return 1e-6;
} }
@ -83,18 +83,18 @@ public:
*/ */
virtual void setup(const eoPop < MOEOT > & _pop) virtual void setup(const eoPop < MOEOT > & _pop)
{ {
double min, max; double min, max;
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++) for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{ {
min = _pop[0].objectiveVector()[i]; min = _pop[0].objectiveVector()[i];
max = _pop[0].objectiveVector()[i]; max = _pop[0].objectiveVector()[i];
for (unsigned int j=1; j<_pop.size(); j++) for (unsigned int j=1; j<_pop.size(); j++)
{ {
min = std::min(min, _pop[j].objectiveVector()[i]); min = std::min(min, _pop[j].objectiveVector()[i]);
max = std::max(max, _pop[j].objectiveVector()[i]); max = std::max(max, _pop[j].objectiveVector()[i]);
} }
// setting of the bounds for the objective i // setting of the bounds for the objective i
setup(min, max, i); setup(min, max, i);
} }
} }
@ -107,12 +107,12 @@ public:
*/ */
virtual void setup(double _min, double _max, unsigned int _obj) virtual void setup(double _min, double _max, unsigned int _obj)
{ {
if (_min == _max) if (_min == _max)
{ {
_min -= tiny(); _min -= tiny();
_max += tiny(); _max += tiny();
} }
bounds[_obj] = eoRealInterval(_min, _max); bounds[_obj] = eoRealInterval(_min, _max);
} }
@ -123,15 +123,15 @@ public:
*/ */
virtual void setup(eoRealInterval _realInterval, unsigned int _obj) virtual void setup(eoRealInterval _realInterval, unsigned int _obj)
{ {
bounds[_obj] = _realInterval; bounds[_obj] = _realInterval;
} }
protected: protected:
/** the bounds for every objective (bounds[i] = bounds for the objective i) */ /** the bounds for every objective (bounds[i] = bounds for the objective i) */
std::vector < eoRealInterval > bounds; std::vector < eoRealInterval > bounds;
}; };
#endif /*MOEONORMALIZEDDISTANCE_H_*/ #endif /*MOEONORMALIZEDDISTANCE_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoCrowdingDiversityAssignment.h> * <moeoCrowdingDiversityAssignment.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 > template < class MOEOT >
class moeoCrowdingDiversityAssignment : public moeoDiversityAssignment < MOEOT > class moeoCrowdingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{ {
public: public:
/** the objective vector type of the solutions */ /** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -59,18 +59,18 @@ public:
* Returns a big value (regarded as infinite) * Returns a big value (regarded as infinite)
*/ */
double inf() const double inf() const
{ {
return std::numeric_limits<double>::max(); return std::numeric_limits<double>::max();
} }
/** /**
* Returns a very small value that can be used to avoid extreme cases (where the min bound == the max bound) * Returns a very small value that can be used to avoid extreme cases (where the min bound == the max bound)
*/ */
double tiny() const double tiny() const
{ {
return 1e-6; return 1e-6;
} }
/** /**
@ -79,16 +79,16 @@ public:
*/ */
void operator()(eoPop < MOEOT > & _pop) void operator()(eoPop < MOEOT > & _pop)
{ {
if (_pop.size() <= 2) if (_pop.size() <= 2)
{ {
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
_pop[i].diversity(inf()); _pop[i].diversity(inf());
} }
} }
else else
{ {
setDistances(_pop); setDistances(_pop);
} }
} }
@ -102,11 +102,11 @@ public:
*/ */
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
std::cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << std::endl; std::cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << std::endl;
} }
protected: protected:
/** /**
* Sets the distance values * Sets the distance values
@ -114,34 +114,34 @@ protected:
*/ */
virtual void setDistances (eoPop < MOEOT > & _pop) virtual void setDistances (eoPop < MOEOT > & _pop)
{ {
double min, max, distance; double min, max, distance;
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives(); unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
// set diversity to 0 // set diversity to 0
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
_pop[i].diversity(0); _pop[i].diversity(0);
} }
// for each objective // for each objective
for (unsigned int obj=0; obj<nObjectives; obj++) for (unsigned int obj=0; obj<nObjectives; obj++)
{ {
// comparator // comparator
moeoOneObjectiveComparator < MOEOT > objComp(obj); moeoOneObjectiveComparator < MOEOT > objComp(obj);
// sort // sort
std::sort(_pop.begin(), _pop.end(), objComp); std::sort(_pop.begin(), _pop.end(), objComp);
// min & max // min & max
min = _pop[0].objectiveVector()[obj]; min = _pop[0].objectiveVector()[obj];
max = _pop[_pop.size()-1].objectiveVector()[obj]; max = _pop[_pop.size()-1].objectiveVector()[obj];
// set the diversity value to infiny for min and max // set the diversity value to infiny for min and max
_pop[0].diversity(inf()); _pop[0].diversity(inf());
_pop[_pop.size()-1].diversity(inf()); _pop[_pop.size()-1].diversity(inf());
for (unsigned int i=1; i<_pop.size()-1; i++) for (unsigned int i=1; i<_pop.size()-1; i++)
{ {
distance = (_pop[i+1].objectiveVector()[obj] - _pop[i-1].objectiveVector()[obj]) / (max-min); distance = (_pop[i+1].objectiveVector()[obj] - _pop[i-1].objectiveVector()[obj]) / (max-min);
_pop[i].diversity(_pop[i].diversity() + distance); _pop[i].diversity(_pop[i].diversity() + distance);
} }
} }
} }
}; };
#endif /*MOEOCROWDINGDIVERSITYASSIGNMENT_H_*/ #endif /*MOEOCROWDINGDIVERSITYASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoDiversityAssignment.h> * <moeoDiversityAssignment.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,8 +46,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoDiversityAssignment : public eoUF < eoPop < MOEOT > &, void > class moeoDiversityAssignment : public eoUF < eoPop < MOEOT > &, void >
{ {
public: public:
/** The type for objective vector */ /** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -68,9 +68,9 @@ public:
*/ */
void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo) void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo)
{ {
updateByDeleting(_pop, _moeo.objectiveVector()); updateByDeleting(_pop, _moeo.objectiveVector());
} }
}; };
#endif /*MOEODIVERSITYASSIGNMENT_H_*/ #endif /*MOEODIVERSITYASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoDummyDiversityAssignment.h> * <moeoDummyDiversityAssignment.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 moeoDummyDiversityAssignment : public moeoDiversityAssignment < MOEOT > class moeoDummyDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{ {
public: public:
/** The type for objective vector */ /** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -58,12 +58,12 @@ public:
*/ */
void operator () (eoPop < MOEOT > & _pop) void operator () (eoPop < MOEOT > & _pop)
{ {
for (unsigned int idx = 0; idx<_pop.size (); idx++) for (unsigned int idx = 0; idx<_pop.size (); idx++)
{ {
if (_pop[idx].invalidDiversity()) if (_pop[idx].invalidDiversity())
{ {
// set the diversity to 0 // set the diversity to 0
_pop[idx].diversity(0.0); _pop[idx].diversity(0.0);
} }
} }
} }
@ -76,9 +76,9 @@ public:
*/ */
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
// nothing to do... ;-) // nothing to do... ;-)
} }
}; };
#endif /*MOEODUMMYDIVERSITYASSIGNMENT_H_*/ #endif /*MOEODUMMYDIVERSITYASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoFrontByFrontCrowdingDiversityAssignment.h> * <moeoFrontByFrontCrowdingDiversityAssignment.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 > template < class MOEOT >
class moeoFrontByFrontCrowdingDiversityAssignment : public moeoCrowdingDiversityAssignment < MOEOT > class moeoFrontByFrontCrowdingDiversityAssignment : public moeoCrowdingDiversityAssignment < MOEOT >
{ {
public: public:
/** the objective vector type of the solutions */ /** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -64,11 +64,11 @@ public:
*/ */
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
std::cout << "WARNING : updateByDeleting not implemented in moeoFrontByFrontCrowdingDistanceDiversityAssignment" << std::endl; std::cout << "WARNING : updateByDeleting not implemented in moeoFrontByFrontCrowdingDistanceDiversityAssignment" << std::endl;
} }
private: private:
using moeoCrowdingDiversityAssignment < MOEOT >::inf; using moeoCrowdingDiversityAssignment < MOEOT >::inf;
using moeoCrowdingDiversityAssignment < MOEOT >::tiny; using moeoCrowdingDiversityAssignment < MOEOT >::tiny;
@ -79,61 +79,61 @@ private:
*/ */
void setDistances (eoPop < MOEOT > & _pop) void setDistances (eoPop < MOEOT > & _pop)
{ {
unsigned int a,b; unsigned int a,b;
double min, max, distance; double min, max, distance;
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives(); unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
// set diversity to 0 for every individual // set diversity to 0 for every individual
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
_pop[i].diversity(0.0); _pop[i].diversity(0.0);
} }
// sort the whole pop according to fitness values // sort the whole pop according to fitness values
moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator; moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator;
std::sort(_pop.begin(), _pop.end(), fitnessComparator); std::sort(_pop.begin(), _pop.end(), fitnessComparator);
// compute the crowding distance values for every individual "front" by "front" (front : from a to b) // compute the crowding distance values for every individual "front" by "front" (front : from a to b)
a = 0; // the front starts at a a = 0; // the front starts at a
while (a < _pop.size()) while (a < _pop.size())
{ {
b = lastIndex(_pop,a); // the front ends at b b = lastIndex(_pop,a); // the front ends at b
// if there is less than 2 individuals in the front... // if there is less than 2 individuals in the front...
if ((b-a) < 2) if ((b-a) < 2)
{ {
for (unsigned int i=a; i<=b; i++) for (unsigned int i=a; i<=b; i++)
{ {
_pop[i].diversity(inf()); _pop[i].diversity(inf());
} }
} }
// else... // else...
else else
{ {
// for each objective // for each objective
for (unsigned int obj=0; obj<nObjectives; obj++) for (unsigned int obj=0; obj<nObjectives; obj++)
{ {
// sort in the descending order using the values of the objective 'obj' // sort in the descending order using the values of the objective 'obj'
moeoOneObjectiveComparator < MOEOT > objComp(obj); moeoOneObjectiveComparator < MOEOT > objComp(obj);
std::sort(_pop.begin()+a, _pop.begin()+b+1, objComp); std::sort(_pop.begin()+a, _pop.begin()+b+1, objComp);
// min & max // min & max
min = _pop[b].objectiveVector()[obj]; min = _pop[b].objectiveVector()[obj];
max = _pop[a].objectiveVector()[obj]; max = _pop[a].objectiveVector()[obj];
// avoid extreme case // avoid extreme case
if (min == max) if (min == max)
{ {
min -= tiny(); min -= tiny();
max += tiny(); max += tiny();
} }
// set the diversity value to infiny for min and max // set the diversity value to infiny for min and max
_pop[a].diversity(inf()); _pop[a].diversity(inf());
_pop[b].diversity(inf()); _pop[b].diversity(inf());
// set the diversity values for the other individuals // set the diversity values for the other individuals
for (unsigned int i=a+1; i<b; i++) for (unsigned int i=a+1; i<b; i++)
{ {
distance = (_pop[i-1].objectiveVector()[obj] - _pop[i+1].objectiveVector()[obj]) / (max-min); distance = (_pop[i-1].objectiveVector()[obj] - _pop[i+1].objectiveVector()[obj]) / (max-min);
_pop[i].diversity(_pop[i].diversity() + distance); _pop[i].diversity(_pop[i].diversity() + distance);
} }
} }
} }
// go to the next front // go to the next front
a = b+1; a = b+1;
} }
} }
@ -145,14 +145,14 @@ private:
*/ */
unsigned int lastIndex (eoPop < MOEOT > & _pop, unsigned int _start) unsigned int lastIndex (eoPop < MOEOT > & _pop, unsigned int _start)
{ {
unsigned int i=_start; unsigned int i=_start;
while ( (i<_pop.size()-1) && (_pop[i].fitness()==_pop[i+1].fitness()) ) while ( (i<_pop.size()-1) && (_pop[i].fitness()==_pop[i+1].fitness()) )
{ {
i++; i++;
} }
return i; return i;
} }
}; };
#endif /*MOEOFRONTBYFRONTCROWDINGDIVERSITYASSIGNMENT_H_*/ #endif /*MOEOFRONTBYFRONTCROWDINGDIVERSITYASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoFrontByFrontSharingDiversityAssignment.h> * <moeoFrontByFrontSharingDiversityAssignment.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 moeoFrontByFrontSharingDiversityAssignment : public moeoSharingDiversityAssignment < MOEOT > class moeoFrontByFrontSharingDiversityAssignment : public moeoSharingDiversityAssignment < MOEOT >
{ {
public: public:
/** the objective vector type of the solutions */ /** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -80,11 +80,11 @@ public:
*/ */
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl; std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl;
} }
private: private:
using moeoSharingDiversityAssignment < MOEOT >::distance; using moeoSharingDiversityAssignment < MOEOT >::distance;
using moeoSharingDiversityAssignment < MOEOT >::nicheSize; using moeoSharingDiversityAssignment < MOEOT >::nicheSize;
@ -98,34 +98,34 @@ private:
*/ */
void setSimilarities(eoPop < MOEOT > & _pop) void setSimilarities(eoPop < MOEOT > & _pop)
{ {
// compute distances between every individuals // compute distances between every individuals
moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance); moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
dMatrix(_pop); dMatrix(_pop);
// sets the distance to bigger than the niche size for every couple of solutions that do not belong to the same front // sets the distance to bigger than the niche size for every couple of solutions that do not belong to the same front
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
for (unsigned int j=0; j<i; j++) for (unsigned int j=0; j<i; j++)
{ {
if (_pop[i].fitness() != _pop[j].fitness()) if (_pop[i].fitness() != _pop[j].fitness())
{ {
dMatrix[i][j] = nicheSize; dMatrix[i][j] = nicheSize;
dMatrix[j][i] = nicheSize; dMatrix[j][i] = nicheSize;
} }
} }
} }
// compute similarities // compute similarities
double sum; double sum;
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
sum = 0.0; sum = 0.0;
for (unsigned int j=0; j<_pop.size(); j++) for (unsigned int j=0; j<_pop.size(); j++)
{ {
sum += sh(dMatrix[i][j]); sum += sh(dMatrix[i][j]);
} }
_pop[i].diversity(sum); _pop[i].diversity(sum);
} }
} }
}; };
#endif /*MOEOFRONTBYFRONTSHARINGDIVERSITYASSIGNMENT_H_*/ #endif /*MOEOFRONTBYFRONTSHARINGDIVERSITYASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoSharingDiversityAssignment.h> * <moeoSharingDiversityAssignment.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 moeoSharingDiversityAssignment : public moeoDiversityAssignment < MOEOT > class moeoSharingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{ {
public: public:
/** the objective vector type of the solutions */ /** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -83,14 +83,14 @@ public:
*/ */
void operator()(eoPop < MOEOT > & _pop) void operator()(eoPop < MOEOT > & _pop)
{ {
// 1 - set simuilarities // 1 - set simuilarities
setSimilarities(_pop); setSimilarities(_pop);
// 2 - a higher diversity is better, so the values need to be inverted // 2 - a higher diversity is better, so the values need to be inverted
moeoDiversityThenFitnessComparator < MOEOT > divComparator; moeoDiversityThenFitnessComparator < MOEOT > divComparator;
double max = std::max_element(_pop.begin(), _pop.end(), divComparator)->diversity(); double max = std::max_element(_pop.begin(), _pop.end(), divComparator)->diversity();
for (unsigned int i=0 ; i<_pop.size() ; i++) for (unsigned int i=0 ; i<_pop.size() ; i++)
{ {
_pop[i].diversity(max - _pop[i].diversity()); _pop[i].diversity(max - _pop[i].diversity());
} }
} }
@ -104,11 +104,11 @@ public:
*/ */
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl; std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl;
} }
protected: protected:
/** the distance used to compute the neighborhood of solutions */ /** the distance used to compute the neighborhood of solutions */
moeoDistance < MOEOT , double > & distance; moeoDistance < MOEOT , double > & distance;
@ -126,19 +126,19 @@ protected:
*/ */
virtual void setSimilarities(eoPop < MOEOT > & _pop) virtual void setSimilarities(eoPop < MOEOT > & _pop)
{ {
// compute distances between every individuals // compute distances between every individuals
moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance); moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
dMatrix(_pop); dMatrix(_pop);
// compute similarities // compute similarities
double sum; double sum;
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
sum = 0.0; sum = 0.0;
for (unsigned int j=0; j<_pop.size(); j++) for (unsigned int j=0; j<_pop.size(); j++)
{ {
sum += sh(dMatrix[i][j]); sum += sh(dMatrix[i][j]);
} }
_pop[i].diversity(sum); _pop[i].diversity(sum);
} }
} }
@ -149,19 +149,19 @@ protected:
*/ */
double sh(double _dist) double sh(double _dist)
{ {
double result; double result;
if (_dist < nicheSize) if (_dist < nicheSize)
{ {
result = 1.0 - pow(_dist / nicheSize, alpha); result = 1.0 - pow(_dist / nicheSize, alpha);
} }
else else
{ {
result = 0.0; result = 0.0;
} }
return result; return result;
} }
}; };
#endif /*MOEOSHARINGDIVERSITYASSIGNMENT_H_*/ #endif /*MOEOSHARINGDIVERSITYASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <make_checkpoint_moeo.h> * <make_checkpoint_moeo.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
@ -66,136 +66,136 @@ bool testDirRes(std::string _dirName, bool _erase);
template < class MOEOT > template < class MOEOT >
eoCheckPoint < MOEOT > & do_make_checkpoint_moeo (eoParser & _parser, eoState & _state, eoEvalFuncCounter < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _archive) eoCheckPoint < MOEOT > & do_make_checkpoint_moeo (eoParser & _parser, eoState & _state, eoEvalFuncCounter < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _archive)
{ {
eoCheckPoint < MOEOT > & checkpoint = _state.storeFunctor(new eoCheckPoint < MOEOT > (_continue)); eoCheckPoint < MOEOT > & checkpoint = _state.storeFunctor(new eoCheckPoint < MOEOT > (_continue));
/* the objective vector type */ /* the objective vector type */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
///////////////////
// Counters
//////////////////
// is nb Eval to be used as counter?
//bool useEval = _parser.getORcreateParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output").value();
// Create anyway a generation-counter parameter
eoValueParam<unsigned int> *generationCounter = new eoValueParam<unsigned int>(0, "Gen.");
// Create an incrementor (sub-class of eoUpdater).
eoIncrementor<unsigned int> & increment = _state.storeFunctor( new eoIncrementor<unsigned int>(generationCounter->value()) );
// Add it to the checkpoint
checkpoint.add(increment);
// dir for DISK output
std::string & dirName = _parser.getORcreateParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output").value();
// shoudl we empty it if exists
eoValueParam<bool>& eraseParam = _parser.getORcreateParam(true, "eraseDir", "erase files in dirName if any", '\0', "Output");
bool dirOK = false; // not tested yet
// Dump of the whole population ///////////////////
//----------------------------- // Counters
bool printPop = _parser.getORcreateParam(false, "printPop", "Print sorted pop. every gen.", '\0', "Output").value(); //////////////////
eoSortedPopStat<MOEOT> * popStat; // is nb Eval to be used as counter?
if ( printPop ) // we do want pop dump //bool useEval = _parser.getORcreateParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output").value();
// Create anyway a generation-counter parameter
eoValueParam<unsigned int> *generationCounter = new eoValueParam<unsigned int>(0, "Gen.");
// Create an incrementor (sub-class of eoUpdater).
eoIncrementor<unsigned int> & increment = _state.storeFunctor( new eoIncrementor<unsigned int>(generationCounter->value()) );
// Add it to the checkpoint
checkpoint.add(increment);
// dir for DISK output
std::string & dirName = _parser.getORcreateParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output").value();
// shoudl we empty it if exists
eoValueParam<bool>& eraseParam = _parser.getORcreateParam(true, "eraseDir", "erase files in dirName if any", '\0', "Output");
bool dirOK = false; // not tested yet
// Dump of the whole population
//-----------------------------
bool printPop = _parser.getORcreateParam(false, "printPop", "Print sorted pop. every gen.", '\0', "Output").value();
eoSortedPopStat<MOEOT> * popStat;
if ( printPop ) // we do want pop dump
{ {
popStat = & _state.storeFunctor(new eoSortedPopStat<MOEOT>); popStat = & _state.storeFunctor(new eoSortedPopStat<MOEOT>);
checkpoint.add(*popStat); checkpoint.add(*popStat);
} }
////////////////////////////////// //////////////////////////////////
// State savers // State savers
////////////////////////////// //////////////////////////////
// feed the state to state savers // feed the state to state savers
// save state every N generation // save state every N generation
eoValueParam<unsigned int>& saveFrequencyParam = _parser.createParam((unsigned int)(0), "saveFrequency", "Save every F generation (0 = only final state, absent = never)", '\0', "Persistence" ); eoValueParam<unsigned int>& saveFrequencyParam = _parser.createParam((unsigned int)(0), "saveFrequency", "Save every F generation (0 = only final state, absent = never)", '\0', "Persistence" );
if (_parser.isItThere(saveFrequencyParam)) if (_parser.isItThere(saveFrequencyParam))
{ {
// first make sure dirName is OK // first make sure dirName is OK
if (! dirOK ) if (! dirOK )
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
unsigned int freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX ); unsigned int freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX );
#ifdef _MSVC #ifdef _MSVC
std::string stmp = dirName + "\generations"; std::string stmp = dirName + "\generations";
#else #else
std::string stmp = dirName + "/generations"; std::string stmp = dirName + "/generations";
#endif #endif
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp); eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
_state.storeFunctor(stateSaver1); _state.storeFunctor(stateSaver1);
checkpoint.add(*stateSaver1); checkpoint.add(*stateSaver1);
} }
// save state every T seconds // save state every T seconds
eoValueParam<unsigned int>& saveTimeIntervalParam = _parser.getORcreateParam((unsigned int)(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" ); eoValueParam<unsigned int>& saveTimeIntervalParam = _parser.getORcreateParam((unsigned int)(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" );
if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0) if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0)
{ {
// first make sure dirName is OK // first make sure dirName is OK
if (! dirOK ) if (! dirOK )
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
#ifdef _MSVC #ifdef _MSVC
std::string stmp = dirName + "\time"; std::string stmp = dirName + "\time";
#else #else
std::string stmp = dirName + "/time"; std::string stmp = dirName + "/time";
#endif #endif
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp); eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
_state.storeFunctor(stateSaver2); _state.storeFunctor(stateSaver2);
checkpoint.add(*stateSaver2); checkpoint.add(*stateSaver2);
} }
/////////////////// ///////////////////
// Archive // Archive
////////////////// //////////////////
// update the archive every generation // update the archive every generation
bool updateArch = _parser.getORcreateParam(true, "updateArch", "Update the archive at each gen.", '\0', "Evolution Engine").value(); bool updateArch = _parser.getORcreateParam(true, "updateArch", "Update the archive at each gen.", '\0', "Evolution Engine").value();
if (updateArch) if (updateArch)
{ {
moeoArchiveUpdater < MOEOT > * updater = new moeoArchiveUpdater < MOEOT > (_archive, _pop); moeoArchiveUpdater < MOEOT > * updater = new moeoArchiveUpdater < MOEOT > (_archive, _pop);
_state.storeFunctor(updater); _state.storeFunctor(updater);
checkpoint.add(*updater); checkpoint.add(*updater);
} }
// store the objective vectors contained in the archive every generation // store the objective vectors contained in the archive every generation
bool storeArch = _parser.getORcreateParam(false, "storeArch", "Store the archive's objective vectors at each gen.", '\0', "Output").value(); bool storeArch = _parser.getORcreateParam(false, "storeArch", "Store the archive's objective vectors at each gen.", '\0', "Output").value();
if (storeArch) if (storeArch)
{ {
if (! dirOK ) if (! dirOK )
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
#ifdef _MSVC #ifdef _MSVC
std::string stmp = dirName + "\arch"; std::string stmp = dirName + "\arch";
#else #else
std::string stmp = dirName + "/arch"; std::string stmp = dirName + "/arch";
#endif #endif
moeoArchiveObjectiveVectorSavingUpdater < MOEOT > * save_updater = new moeoArchiveObjectiveVectorSavingUpdater < MOEOT > (_archive, stmp); moeoArchiveObjectiveVectorSavingUpdater < MOEOT > * save_updater = new moeoArchiveObjectiveVectorSavingUpdater < MOEOT > (_archive, stmp);
_state.storeFunctor(save_updater); _state.storeFunctor(save_updater);
checkpoint.add(*save_updater); checkpoint.add(*save_updater);
} }
// store the contribution of the non-dominated solutions // store the contribution of the non-dominated solutions
bool cont = _parser.getORcreateParam(false, "contribution", "Store the contribution of the archive at each gen.", '\0', "Output").value(); bool cont = _parser.getORcreateParam(false, "contribution", "Store the contribution of the archive at each gen.", '\0', "Output").value();
if (cont) if (cont)
{ {
if (! dirOK ) if (! dirOK )
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
#ifdef _MSVC #ifdef _MSVC
std::string stmp = dirName + "\contribution"; std::string stmp = dirName + "\contribution";
#else #else
std::string stmp = dirName + "/contribution"; std::string stmp = dirName + "/contribution";
#endif #endif
moeoContributionMetric < ObjectiveVector > * contribution = new moeoContributionMetric < ObjectiveVector >; moeoContributionMetric < ObjectiveVector > * contribution = new moeoContributionMetric < ObjectiveVector >;
moeoBinaryMetricSavingUpdater < MOEOT > * contribution_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*contribution, _archive, stmp); moeoBinaryMetricSavingUpdater < MOEOT > * contribution_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*contribution, _archive, stmp);
_state.storeFunctor(contribution_updater); _state.storeFunctor(contribution_updater);
checkpoint.add(*contribution_updater); checkpoint.add(*contribution_updater);
} }
// store the entropy of the non-dominated solutions // store the entropy of the non-dominated solutions
bool ent = _parser.getORcreateParam(false, "entropy", "Store the entropy of the archive at each gen.", '\0', "Output").value(); bool ent = _parser.getORcreateParam(false, "entropy", "Store the entropy of the archive at each gen.", '\0', "Output").value();
if (ent) if (ent)
{ {
if (! dirOK ) if (! dirOK )
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
#ifdef _MSVC #ifdef _MSVC
std::string stmp = dirName + "\entropy"; std::string stmp = dirName + "\entropy";
#else #else
std::string stmp = dirName + "/entropy"; std::string stmp = dirName + "/entropy";
#endif #endif
moeoEntropyMetric < ObjectiveVector > * entropy = new moeoEntropyMetric < ObjectiveVector >; moeoEntropyMetric < ObjectiveVector > * entropy = new moeoEntropyMetric < ObjectiveVector >;
moeoBinaryMetricSavingUpdater < MOEOT > * entropy_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*entropy, _archive, stmp); moeoBinaryMetricSavingUpdater < MOEOT > * entropy_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*entropy, _archive, stmp);
_state.storeFunctor(entropy_updater); _state.storeFunctor(entropy_updater);
checkpoint.add(*entropy_updater); checkpoint.add(*entropy_updater);
} }
// and that's it for the (control and) output // and that's it for the (control and) output
return checkpoint; return checkpoint;
} }
#endif /*MAKE_CHECKPOINT_MOEO_H_*/ #endif /*MAKE_CHECKPOINT_MOEO_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <make_continue_moeo.h> * <make_continue_moeo.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
@ -58,11 +58,11 @@
template <class MOEOT> template <class MOEOT>
eoCombinedContinue<MOEOT> * make_combinedContinue(eoCombinedContinue<MOEOT> *_combined, eoContinue<MOEOT> *_cont) eoCombinedContinue<MOEOT> * make_combinedContinue(eoCombinedContinue<MOEOT> *_combined, eoContinue<MOEOT> *_cont)
{ {
if (_combined) // already exists if (_combined) // already exists
_combined->add(*_cont); _combined->add(*_cont);
else else
_combined = new eoCombinedContinue<MOEOT>(*_cont); _combined = new eoCombinedContinue<MOEOT>(*_cont);
return _combined; return _combined;
} }
@ -75,57 +75,57 @@ eoCombinedContinue<MOEOT> * make_combinedContinue(eoCombinedContinue<MOEOT> *_co
template <class MOEOT> template <class MOEOT>
eoContinue<MOEOT> & do_make_continue_moeo(eoParser& _parser, eoState& _state, eoEvalFuncCounter<MOEOT> & _eval) eoContinue<MOEOT> & do_make_continue_moeo(eoParser& _parser, eoState& _state, eoEvalFuncCounter<MOEOT> & _eval)
{ {
// the combined continue - to be filled // the combined continue - to be filled
eoCombinedContinue<MOEOT> *continuator = NULL; eoCombinedContinue<MOEOT> *continuator = NULL;
// First the eoGenContinue - need a default value so you can run blind // First the eoGenContinue - need a default value so you can run blind
// but we also need to be able to avoid it <--> 0 // but we also need to be able to avoid it <--> 0
eoValueParam<unsigned int>& maxGenParam = _parser.createParam((unsigned int)(100), "maxGen", "Maximum number of generations (0 = none)",'G',"Stopping criterion"); eoValueParam<unsigned int>& maxGenParam = _parser.createParam((unsigned int)(100), "maxGen", "Maximum number of generations (0 = none)",'G',"Stopping criterion");
if (maxGenParam.value()) // positive: -> define and store if (maxGenParam.value()) // positive: -> define and store
{ {
eoGenContinue<MOEOT> *genCont = new eoGenContinue<MOEOT>(maxGenParam.value()); eoGenContinue<MOEOT> *genCont = new eoGenContinue<MOEOT>(maxGenParam.value());
_state.storeFunctor(genCont); _state.storeFunctor(genCont);
// and "add" to combined // and "add" to combined
continuator = make_combinedContinue<MOEOT>(continuator, genCont); continuator = make_combinedContinue<MOEOT>(continuator, genCont);
} }
// maxEval // maxEval
eoValueParam<unsigned long>& maxEvalParam = _parser.getORcreateParam((unsigned long)(0), "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion"); eoValueParam<unsigned long>& maxEvalParam = _parser.getORcreateParam((unsigned long)(0), "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion");
if (maxEvalParam.value()) if (maxEvalParam.value())
{ {
eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value()); eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value());
_state.storeFunctor(evalCont); _state.storeFunctor(evalCont);
// and "add" to combined // and "add" to combined
continuator = make_combinedContinue<MOEOT>(continuator, evalCont); continuator = make_combinedContinue<MOEOT>(continuator, evalCont);
} }
// maxTime // maxTime
eoValueParam<unsigned long>& maxTimeParam = _parser.getORcreateParam((unsigned long)(0), "maxTime", "Maximum running time in seconds (0 = none)", 'T', "Stopping criterion"); eoValueParam<unsigned long>& maxTimeParam = _parser.getORcreateParam((unsigned long)(0), "maxTime", "Maximum running time in seconds (0 = none)", 'T', "Stopping criterion");
if (maxTimeParam.value()) // positive: -> define and store if (maxTimeParam.value()) // positive: -> define and store
{ {
eoTimeContinue<MOEOT> *timeCont = new eoTimeContinue<MOEOT>(maxTimeParam.value()); eoTimeContinue<MOEOT> *timeCont = new eoTimeContinue<MOEOT>(maxTimeParam.value());
_state.storeFunctor(timeCont); _state.storeFunctor(timeCont);
// and "add" to combined // and "add" to combined
continuator = make_combinedContinue<MOEOT>(continuator, timeCont); continuator = make_combinedContinue<MOEOT>(continuator, timeCont);
} }
// CtrlC // CtrlC
#ifndef _MSC_VER #ifndef _MSC_VER
// the CtrlC interception (Linux only I'm afraid) // the CtrlC interception (Linux only I'm afraid)
eoCtrlCContinue<MOEOT> *ctrlCCont; eoCtrlCContinue<MOEOT> *ctrlCCont;
eoValueParam<bool>& ctrlCParam = _parser.createParam(true, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion"); eoValueParam<bool>& ctrlCParam = _parser.createParam(true, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion");
if (_parser.isItThere(ctrlCParam)) if (_parser.isItThere(ctrlCParam))
{ {
ctrlCCont = new eoCtrlCContinue<MOEOT>; ctrlCCont = new eoCtrlCContinue<MOEOT>;
// store // store
_state.storeFunctor(ctrlCCont); _state.storeFunctor(ctrlCCont);
// add to combinedContinue // add to combinedContinue
continuator = make_combinedContinue<MOEOT>(continuator, ctrlCCont); continuator = make_combinedContinue<MOEOT>(continuator, ctrlCCont);
} }
#endif #endif
// now check that there is at least one! // now check that there is at least one!
if (!continuator) if (!continuator)
throw std::runtime_error("You MUST provide a stopping criterion"); throw std::runtime_error("You MUST provide a stopping criterion");
// OK, it's there: store in the eoState // OK, it's there: store in the eoState
_state.storeFunctor(continuator); _state.storeFunctor(continuator);
// and return // and return
return *continuator; return *continuator;
} }
#endif /*MAKE_CONTINUE_MOEO_H_*/ #endif /*MAKE_CONTINUE_MOEO_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <make_ea_moeo.h> * <make_ea_moeo.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
@ -88,209 +88,209 @@ template < class MOEOT >
moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalFunc < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoGenOp < MOEOT > & _op, moeoArchive < MOEOT > & _archive) moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalFunc < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoGenOp < MOEOT > & _op, moeoArchive < MOEOT > & _archive)
{ {
/* the objective vector type */ /* the objective vector type */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/* the fitness assignment strategy */ /* the fitness assignment strategy */
std::string & fitnessParam = _parser.createParam(std::string("FastNonDominatedSorting"), "fitness", std::string & fitnessParam = _parser.createParam(std::string("FastNonDominatedSorting"), "fitness",
"Fitness assignment scheme: Dummy, FastNonDominatedSorting or IndicatorBased", 'F', "Fitness assignment scheme: Dummy, FastNonDominatedSorting or IndicatorBased", 'F',
"Evolution Engine").value(); "Evolution Engine").value();
std::string & indicatorParam = _parser.createParam(std::string("Epsilon"), "indicator", std::string & indicatorParam = _parser.createParam(std::string("Epsilon"), "indicator",
"Binary indicator for IndicatorBased: Epsilon, Hypervolume", 'i', "Binary indicator for IndicatorBased: Epsilon, Hypervolume", 'i',
"Evolution Engine").value(); "Evolution Engine").value();
double rho = _parser.createParam(1.1, "rho", "reference point for the hypervolume indicator", 'r', double rho = _parser.createParam(1.1, "rho", "reference point for the hypervolume indicator", 'r',
"Evolution Engine").value();
double kappa = _parser.createParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", 'k',
"Evolution Engine").value(); "Evolution Engine").value();
double kappa = _parser.createParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", 'k', moeoFitnessAssignment < MOEOT > * fitnessAssignment;
"Evolution Engine").value(); if (fitnessParam == std::string("Dummy"))
moeoFitnessAssignment < MOEOT > * fitnessAssignment;
if (fitnessParam == std::string("Dummy"))
{ {
fitnessAssignment = new moeoDummyFitnessAssignment < MOEOT> (); fitnessAssignment = new moeoDummyFitnessAssignment < MOEOT> ();
} }
else if (fitnessParam == std::string("FastNonDominatedSorting")) else if (fitnessParam == std::string("FastNonDominatedSorting"))
{ {
fitnessAssignment = new moeoFastNonDominatedSortingFitnessAssignment < MOEOT> (); fitnessAssignment = new moeoFastNonDominatedSortingFitnessAssignment < MOEOT> ();
} }
else if (fitnessParam == std::string("IndicatorBased")) else if (fitnessParam == std::string("IndicatorBased"))
{ {
// metric // metric
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric; moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric;
if (indicatorParam == std::string("Epsilon")) if (indicatorParam == std::string("Epsilon"))
{ {
metric = new moeoAdditiveEpsilonBinaryMetric < ObjectiveVector >; metric = new moeoAdditiveEpsilonBinaryMetric < ObjectiveVector >;
} }
else if (indicatorParam == std::string("Hypervolume")) else if (indicatorParam == std::string("Hypervolume"))
{ {
metric = new moeoHypervolumeBinaryMetric < ObjectiveVector > (rho); metric = new moeoHypervolumeBinaryMetric < ObjectiveVector > (rho);
} }
else else
{ {
std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam; std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam;
throw std::runtime_error(stmp.c_str()); throw std::runtime_error(stmp.c_str());
} }
fitnessAssignment = new moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT > (*metric, kappa); fitnessAssignment = new moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT > (*metric, kappa);
} }
else else
{ {
std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam; std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam;
throw std::runtime_error(stmp.c_str()); throw std::runtime_error(stmp.c_str());
} }
_state.storeFunctor(fitnessAssignment); _state.storeFunctor(fitnessAssignment);
/* the diversity assignment strategy */ /* the diversity assignment strategy */
eoValueParam<eoParamParamType> & diversityParam = _parser.createParam(eoParamParamType("Dummy"), "diversity", eoValueParam<eoParamParamType> & diversityParam = _parser.createParam(eoParamParamType("Dummy"), "diversity",
"Diversity assignment scheme: Dummy, Sharing(nicheSize) or Crowding", 'D', "Evolution Engine"); "Diversity assignment scheme: Dummy, Sharing(nicheSize) or Crowding", 'D', "Evolution Engine");
eoParamParamType & diversityParamValue = diversityParam.value(); eoParamParamType & diversityParamValue = diversityParam.value();
moeoDiversityAssignment < MOEOT > * diversityAssignment; moeoDiversityAssignment < MOEOT > * diversityAssignment;
if (diversityParamValue.first == std::string("Dummy")) if (diversityParamValue.first == std::string("Dummy"))
{ {
diversityAssignment = new moeoDummyDiversityAssignment < MOEOT> (); diversityAssignment = new moeoDummyDiversityAssignment < MOEOT> ();
} }
else if (diversityParamValue.first == std::string("Sharing")) else if (diversityParamValue.first == std::string("Sharing"))
{ {
double nicheSize; double nicheSize;
if (!diversityParamValue.second.size()) // no parameter added if (!diversityParamValue.second.size()) // no parameter added
{ {
std::cerr << "WARNING, no niche size given for Sharing, using 0.5" << std::endl; std::cerr << "WARNING, no niche size given for Sharing, using 0.5" << std::endl;
nicheSize = 0.5; nicheSize = 0.5;
diversityParamValue.second.push_back(std::string("0.5")); diversityParamValue.second.push_back(std::string("0.5"));
} }
else else
{ {
nicheSize = atoi(diversityParamValue.second[0].c_str()); nicheSize = atoi(diversityParamValue.second[0].c_str());
} }
diversityAssignment = new moeoFrontByFrontSharingDiversityAssignment < MOEOT> (nicheSize); diversityAssignment = new moeoFrontByFrontSharingDiversityAssignment < MOEOT> (nicheSize);
} }
else if (diversityParamValue.first == std::string("Crowding")) else if (diversityParamValue.first == std::string("Crowding"))
{ {
diversityAssignment = new moeoFrontByFrontCrowdingDiversityAssignment < MOEOT> (); diversityAssignment = new moeoFrontByFrontCrowdingDiversityAssignment < MOEOT> ();
} }
else else
{ {
std::string stmp = std::string("Invalid diversity assignment strategy: ") + diversityParamValue.first; std::string stmp = std::string("Invalid diversity assignment strategy: ") + diversityParamValue.first;
throw std::runtime_error(stmp.c_str()); throw std::runtime_error(stmp.c_str());
} }
_state.storeFunctor(diversityAssignment); _state.storeFunctor(diversityAssignment);
/* the comparator strategy */ /* the comparator strategy */
std::string & comparatorParam = _parser.createParam(std::string("FitnessThenDiversity"), "comparator", std::string & comparatorParam = _parser.createParam(std::string("FitnessThenDiversity"), "comparator",
"Comparator scheme: FitnessThenDiversity, DiversityThenFitness or Aggregative", 'C', "Evolution Engine").value(); "Comparator scheme: FitnessThenDiversity, DiversityThenFitness or Aggregative", 'C', "Evolution Engine").value();
moeoComparator < MOEOT > * comparator; moeoComparator < MOEOT > * comparator;
if (comparatorParam == std::string("FitnessThenDiversity")) if (comparatorParam == std::string("FitnessThenDiversity"))
{ {
comparator = new moeoFitnessThenDiversityComparator < MOEOT> (); comparator = new moeoFitnessThenDiversityComparator < MOEOT> ();
} }
else if (comparatorParam == std::string("DiversityThenFitness")) else if (comparatorParam == std::string("DiversityThenFitness"))
{ {
comparator = new moeoDiversityThenFitnessComparator < MOEOT> (); comparator = new moeoDiversityThenFitnessComparator < MOEOT> ();
} }
else if (comparatorParam == std::string("Aggregative")) else if (comparatorParam == std::string("Aggregative"))
{ {
comparator = new moeoAggregativeComparator < MOEOT> (); comparator = new moeoAggregativeComparator < MOEOT> ();
} }
else else
{ {
std::string stmp = std::string("Invalid comparator strategy: ") + comparatorParam; std::string stmp = std::string("Invalid comparator strategy: ") + comparatorParam;
throw std::runtime_error(stmp.c_str()); throw std::runtime_error(stmp.c_str());
} }
_state.storeFunctor(comparator); _state.storeFunctor(comparator);
/* the selection strategy */ /* the selection strategy */
eoValueParam < eoParamParamType > & selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", eoValueParam < eoParamParamType > & selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection",
"Selection scheme: DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine"); "Selection scheme: DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine");
eoParamParamType & ppSelect = selectionParam.value(); eoParamParamType & ppSelect = selectionParam.value();
moeoSelectOne < MOEOT > * select; moeoSelectOne < MOEOT > * select;
if (ppSelect.first == std::string("DetTour")) if (ppSelect.first == std::string("DetTour"))
{ {
unsigned int tSize; unsigned int tSize;
if (!ppSelect.second.size()) // no parameter added if (!ppSelect.second.size()) // no parameter added
{ {
std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl; std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl;
tSize = 2; tSize = 2;
// put back 2 in parameter for consistency (and status file) // put back 2 in parameter for consistency (and status file)
ppSelect.second.push_back(std::string("2")); ppSelect.second.push_back(std::string("2"));
} }
else // parameter passed by user as DetTour(T) else // parameter passed by user as DetTour(T)
{ {
tSize = atoi(ppSelect.second[0].c_str()); tSize = atoi(ppSelect.second[0].c_str());
} }
select = new moeoDetTournamentSelect < MOEOT > (*comparator, tSize); select = new moeoDetTournamentSelect < MOEOT > (*comparator, tSize);
} }
else if (ppSelect.first == std::string("StochTour")) else if (ppSelect.first == std::string("StochTour"))
{ {
double tRate; double tRate;
if (!ppSelect.second.size()) // no parameter added if (!ppSelect.second.size()) // no parameter added
{ {
std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl; std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl;
tRate = 1; tRate = 1;
// put back 1 in parameter for consistency (and status file) // put back 1 in parameter for consistency (and status file)
ppSelect.second.push_back(std::string("1")); ppSelect.second.push_back(std::string("1"));
} }
else // parameter passed by user as StochTour(T) else // parameter passed by user as StochTour(T)
{ {
tRate = atof(ppSelect.second[0].c_str()); tRate = atof(ppSelect.second[0].c_str());
} }
select = new moeoStochTournamentSelect < MOEOT > (*comparator, tRate); select = new moeoStochTournamentSelect < MOEOT > (*comparator, tRate);
} }
/* /*
else if (ppSelect.first == string("Roulette")) else if (ppSelect.first == string("Roulette"))
{
// TO DO !
// ...
}
*/
else if (ppSelect.first == std::string("Random"))
{ {
// TO DO ! select = new moeoRandomSelect <MOEOT > ();
// ...
} }
*/ else
else if (ppSelect.first == std::string("Random"))
{ {
select = new moeoRandomSelect <MOEOT > (); std::string stmp = std::string("Invalid selection strategy: ") + ppSelect.first;
throw std::runtime_error(stmp.c_str());
} }
else _state.storeFunctor(select);
{
std::string stmp = std::string("Invalid selection strategy: ") + ppSelect.first;
throw std::runtime_error(stmp.c_str());
}
_state.storeFunctor(select);
/* the replacement strategy */ /* the replacement strategy */
std::string & replacementParam = _parser.createParam(std::string("Elitist"), "replacement", std::string & replacementParam = _parser.createParam(std::string("Elitist"), "replacement",
"Replacement scheme: Elitist, Environmental or Generational", 'R', "Evolution Engine").value(); "Replacement scheme: Elitist, Environmental or Generational", 'R', "Evolution Engine").value();
moeoReplacement < MOEOT > * replace; moeoReplacement < MOEOT > * replace;
if (replacementParam == std::string("Elitist")) if (replacementParam == std::string("Elitist"))
{ {
replace = new moeoElitistReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator); replace = new moeoElitistReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator);
} }
else if (replacementParam == std::string("Environmental")) else if (replacementParam == std::string("Environmental"))
{ {
replace = new moeoEnvironmentalReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator); replace = new moeoEnvironmentalReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator);
} }
else if (replacementParam == std::string("Generational")) else if (replacementParam == std::string("Generational"))
{ {
replace = new moeoGenerationalReplacement < MOEOT> (); replace = new moeoGenerationalReplacement < MOEOT> ();
} }
else else
{ {
std::string stmp = std::string("Invalid replacement strategy: ") + replacementParam; std::string stmp = std::string("Invalid replacement strategy: ") + replacementParam;
throw std::runtime_error(stmp.c_str()); throw std::runtime_error(stmp.c_str());
} }
_state.storeFunctor(replace); _state.storeFunctor(replace);
/* the number of offspring */ /* the number of offspring */
eoValueParam < eoHowMany > & offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring", eoValueParam < eoHowMany > & offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring",
"Number of offspring (percentage or absolute)", 'O', "Evolution Engine"); "Number of offspring (percentage or absolute)", 'O', "Evolution Engine");
// the general breeder // the general breeder
eoGeneralBreeder < MOEOT > * breed = new eoGeneralBreeder < MOEOT > (*select, _op, offspringRateParam.value()); eoGeneralBreeder < MOEOT > * breed = new eoGeneralBreeder < MOEOT > (*select, _op, offspringRateParam.value());
_state.storeFunctor(breed); _state.storeFunctor(breed);
// the eoEasyEA // the eoEasyEA
moeoEA < MOEOT > * algo = new moeoEasyEA < MOEOT > (_continue, _eval, *breed, *replace, *fitnessAssignment, *diversityAssignment); moeoEA < MOEOT > * algo = new moeoEasyEA < MOEOT > (_continue, _eval, *breed, *replace, *fitnessAssignment, *diversityAssignment);
_state.storeFunctor(algo); _state.storeFunctor(algo);
return *algo; return *algo;
} }

View file

@ -1,4 +1,4 @@
/* /*
* <make_ls_moeo.h> * <make_ls_moeo.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
@ -67,80 +67,81 @@
*/ */
template < class MOEOT, class Move > template < class MOEOT, class Move >
moeoLS < MOEOT, eoPop<MOEOT> & > & do_make_ls_moeo ( moeoLS < MOEOT, eoPop<MOEOT> & > & do_make_ls_moeo (
eoParser & _parser, eoParser & _parser,
eoState & _state, eoState & _state,
eoEvalFunc < MOEOT > & _eval, eoEvalFunc < MOEOT > & _eval,
moeoMoveIncrEval < Move > & _moveIncrEval, moeoMoveIncrEval < Move > & _moveIncrEval,
eoContinue < MOEOT > & _continue, eoContinue < MOEOT > & _continue,
eoMonOp < MOEOT > & _op, eoMonOp < MOEOT > & _op,
eoMonOp < MOEOT > & _opInit, eoMonOp < MOEOT > & _opInit,
moMoveInit < Move > & _moveInit, moMoveInit < Move > & _moveInit,
moNextMove < Move > & _nextMove, moNextMove < Move > & _nextMove,
moeoArchive < MOEOT > & _archive moeoArchive < MOEOT > & _archive
) )
{ {
/* the objective vector type */ /* the objective vector type */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/* the fitness assignment strategy */ /* the fitness assignment strategy */
std::string & fitnessParam = _parser.getORcreateParam(std::string("IndicatorBased"), "fitness", std::string & fitnessParam = _parser.getORcreateParam(std::string("IndicatorBased"), "fitness",
"Fitness assignment strategy parameter: IndicatorBased...", 'F', "Fitness assignment strategy parameter: IndicatorBased...", 'F',
"Evolution Engine").value(); "Evolution Engine").value();
std::string & indicatorParam = _parser.getORcreateParam(std::string("Epsilon"), "indicator", std::string & indicatorParam = _parser.getORcreateParam(std::string("Epsilon"), "indicator",
"Binary indicator to use with the IndicatorBased assignment: Epsilon, Hypervolume", 'i', "Binary indicator to use with the IndicatorBased assignment: Epsilon, Hypervolume", 'i',
"Evolution Engine").value(); "Evolution Engine").value();
double rho = _parser.getORcreateParam(1.1, "rho", "reference point for the hypervolume indicator", double rho = _parser.getORcreateParam(1.1, "rho", "reference point for the hypervolume indicator",
'r', "Evolution Engine").value(); 'r', "Evolution Engine").value();
double kappa = _parser.getORcreateParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", double kappa = _parser.getORcreateParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased",
'k', "Evolution Engine").value(); 'k', "Evolution Engine").value();
moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > * fitnessAssignment; moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > * fitnessAssignment;
if (fitnessParam == std::string("IndicatorBased")) if (fitnessParam == std::string("IndicatorBased"))
{ {
// metric // metric
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric; moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric;
if (indicatorParam == std::string("Epsilon")) if (indicatorParam == std::string("Epsilon"))
{ {
metric = new moeoAdditiveEpsilonBinaryMetric < ObjectiveVector >; metric = new moeoAdditiveEpsilonBinaryMetric < ObjectiveVector >;
} }
else if (indicatorParam == std::string("Hypervolume")) else if (indicatorParam == std::string("Hypervolume"))
{ {
metric = new moeoHypervolumeBinaryMetric < ObjectiveVector > (rho); metric = new moeoHypervolumeBinaryMetric < ObjectiveVector > (rho);
} }
else else
{ {
std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam; std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam;
throw std::runtime_error(stmp.c_str()); throw std::runtime_error(stmp.c_str());
} }
fitnessAssignment = new moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT> (*metric, kappa); fitnessAssignment = new moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT> (*metric, kappa);
} }
else else
{ {
std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam; std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam;
throw std::runtime_error(stmp.c_str()); throw std::runtime_error(stmp.c_str());
} }
_state.storeFunctor(fitnessAssignment); _state.storeFunctor(fitnessAssignment);
// number of iterations // number of iterations
unsigned int n = _parser.getORcreateParam(1, "n", "Number of iterations for population Initialization", 'n', "Evolution Engine").value(); unsigned int n = _parser.getORcreateParam(1, "n", "Number of iterations for population Initialization", 'n', "Evolution Engine").value();
// LS // LS
std::string & lsParam = _parser.getORcreateParam(std::string("I-IBMOLS"), "ls", std::string & lsParam = _parser.getORcreateParam(std::string("I-IBMOLS"), "ls",
"Local Search: IBMOLS, I-IBMOLS (Iterated-IBMOLS)...", 'L', "Local Search: IBMOLS, I-IBMOLS (Iterated-IBMOLS)...", 'L',
"Evolution Engine").value(); "Evolution Engine").value();
moeoLS < MOEOT, eoPop<MOEOT> & > * ls; moeoLS < MOEOT, eoPop<MOEOT> & > * ls;
if (lsParam == std::string("IBMOLS")) if (lsParam == std::string("IBMOLS"))
{ {
ls = new moeoIBMOLS < MOEOT, Move > (_moveInit, _nextMove, _eval, _moveIncrEval, *fitnessAssignment, _continue);; ls = new moeoIBMOLS < MOEOT, Move > (_moveInit, _nextMove, _eval, _moveIncrEval, *fitnessAssignment, _continue);
;
} }
else if (lsParam == std::string("I-IBMOLS")) else if (lsParam == std::string("I-IBMOLS"))
{ {
ls = new moeoIteratedIBMOLS < MOEOT, Move > (_moveInit, _nextMove, _eval, _moveIncrEval, *fitnessAssignment, _continue, _op, _opInit, n); ls = new moeoIteratedIBMOLS < MOEOT, Move > (_moveInit, _nextMove, _eval, _moveIncrEval, *fitnessAssignment, _continue, _op, _opInit, n);
} }
else else
{ {
std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam; std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam;
throw std::runtime_error(stmp.c_str()); throw std::runtime_error(stmp.c_str());
} }
_state.storeFunctor(ls); _state.storeFunctor(ls);
// that's it ! // that's it !
return *ls; return *ls;
} }
#endif /*MAKE_LS_MOEO_H_*/ #endif /*MAKE_LS_MOEO_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoAchievementFitnessAssignment.h> * <moeoAchievementFitnessAssignment.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 moeoAchievementFitnessAssignment : public moeoScalarFitnessAssignment < MOEOT > class moeoAchievementFitnessAssignment : public moeoScalarFitnessAssignment < MOEOT >
{ {
public: public:
/** the objective vector type of the solutions */ /** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -62,11 +62,11 @@ public:
*/ */
moeoAchievementFitnessAssignment(ObjectiveVector & _reference, std::vector < double > & _lambdas, double _spn=0.0001) : reference(_reference), lambdas(_lambdas), spn(_spn) moeoAchievementFitnessAssignment(ObjectiveVector & _reference, std::vector < double > & _lambdas, double _spn=0.0001) : reference(_reference), lambdas(_lambdas), spn(_spn)
{ {
// consistency check // consistency check
if ((spn < 0.0) || (spn > 1.0)) if ((spn < 0.0) || (spn > 1.0))
{ {
std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n"; std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n";
spn = 0.0001; spn = 0.0001;
} }
} }
@ -78,17 +78,17 @@ public:
*/ */
moeoAchievementFitnessAssignment(ObjectiveVector & _reference, double _spn=0.0001) : reference(_reference), spn(_spn) moeoAchievementFitnessAssignment(ObjectiveVector & _reference, double _spn=0.0001) : reference(_reference), spn(_spn)
{ {
// compute the default values for lambdas // compute the default values for lambdas
lambdas = std::vector < double > (ObjectiveVector::nObjectives()); lambdas = std::vector < double > (ObjectiveVector::nObjectives());
for (unsigned int i=0 ; i<lambdas.size(); i++) for (unsigned int i=0 ; i<lambdas.size(); i++)
{ {
lambdas[i] = 1.0 / ObjectiveVector::nObjectives(); lambdas[i] = 1.0 / ObjectiveVector::nObjectives();
} }
// consistency check // consistency check
if ((spn < 0.0) || (spn > 1.0)) if ((spn < 0.0) || (spn > 1.0))
{ {
std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n"; std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n";
spn = 0.0001; spn = 0.0001;
} }
} }
@ -99,9 +99,9 @@ public:
*/ */
virtual void operator()(eoPop < MOEOT > & _pop) virtual void operator()(eoPop < MOEOT > & _pop)
{ {
for (unsigned int i=0; i<_pop.size() ; i++) for (unsigned int i=0; i<_pop.size() ; i++)
{ {
compute(_pop[i]); compute(_pop[i]);
} }
} }
@ -113,7 +113,7 @@ public:
*/ */
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
// nothing to do ;-) // nothing to do ;-)
} }
@ -123,11 +123,11 @@ public:
*/ */
void setReference(const ObjectiveVector & _reference) void setReference(const ObjectiveVector & _reference)
{ {
reference = _reference; reference = _reference;
} }
private: private:
/** the reference point */ /** the reference point */
ObjectiveVector reference; ObjectiveVector reference;
@ -141,9 +141,9 @@ private:
* Returns a big value (regarded as infinite) * Returns a big value (regarded as infinite)
*/ */
double inf() const double inf() const
{ {
return std::numeric_limits<double>::max(); return std::numeric_limits<double>::max();
} }
/** /**
@ -152,19 +152,19 @@ private:
*/ */
void compute(MOEOT & _moeo) void compute(MOEOT & _moeo)
{ {
unsigned int nobj = MOEOT::ObjectiveVector::nObjectives(); unsigned int nobj = MOEOT::ObjectiveVector::nObjectives();
double temp; double temp;
double min = inf(); double min = inf();
double sum = 0; double sum = 0;
for (unsigned int obj=0; obj<nobj; obj++) for (unsigned int obj=0; obj<nobj; obj++)
{ {
temp = lambdas[obj] * (reference[obj] - _moeo.objectiveVector()[obj]); temp = lambdas[obj] * (reference[obj] - _moeo.objectiveVector()[obj]);
min = std::min(min, temp); min = std::min(min, temp);
sum += temp; sum += temp;
} }
_moeo.fitness(min + spn*sum); _moeo.fitness(min + spn*sum);
} }
}; };
#endif /*MOEOACHIEVEMENTFITNESSASSIGNMENT_H_*/ #endif /*MOEOACHIEVEMENTFITNESSASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoBinaryIndicatorBasedFitnessAssignment.h> * <moeoBinaryIndicatorBasedFitnessAssignment.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 moeoBinaryIndicatorBasedFitnessAssignment : public moeoIndicatorBasedFitnessAssignment < MOEOT > class moeoBinaryIndicatorBasedFitnessAssignment : public moeoIndicatorBasedFitnessAssignment < MOEOT >
{ {
public: public:
/** The type for objective vector */ /** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -60,6 +60,6 @@ public:
*/ */
virtual double updateByAdding(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) = 0; virtual double updateByAdding(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) = 0;
}; };
#endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/ #endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoCriterionBasedFitnessAssignment.h> * <moeoCriterionBasedFitnessAssignment.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 @@
* moeoCriterionBasedFitnessAssignment is a moeoFitnessAssignment for criterion-based strategies. * moeoCriterionBasedFitnessAssignment is a moeoFitnessAssignment for criterion-based strategies.
*/ */
template < class MOEOT > template < class MOEOT >
class moeoCriterionBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > {}; class moeoCriterionBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
{};
#endif /*MOEOCRITERIONBASEDFITNESSASSIGNMENT_H_*/ #endif /*MOEOCRITERIONBASEDFITNESSASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoDummyFitnessAssignment.h> * <moeoDummyFitnessAssignment.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 moeoDummyFitnessAssignment : public moeoFitnessAssignment < MOEOT > class moeoDummyFitnessAssignment : public moeoFitnessAssignment < MOEOT >
{ {
public: public:
/** The type for objective vector */ /** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -58,12 +58,12 @@ public:
*/ */
void operator () (eoPop < MOEOT > & _pop) void operator () (eoPop < MOEOT > & _pop)
{ {
for (unsigned int idx = 0; idx<_pop.size (); idx++) for (unsigned int idx = 0; idx<_pop.size (); idx++)
{ {
if (_pop[idx].invalidFitness()) if (_pop[idx].invalidFitness())
{ {
// set the diversity to 0 // set the diversity to 0
_pop[idx].fitness(0.0); _pop[idx].fitness(0.0);
} }
} }
} }
@ -76,9 +76,9 @@ public:
*/ */
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
// nothing to do... ;-) // nothing to do... ;-)
} }
}; };
#endif /*MOEODUMMYFITNESSASSIGNMENT_H_*/ #endif /*MOEODUMMYFITNESSASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoExpBinaryIndicatorBasedFitnessAssignment.h> * <moeoExpBinaryIndicatorBasedFitnessAssignment.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
@ -52,8 +52,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorBasedFitnessAssignment < MOEOT >
{ {
public: public:
/** The type of objective vector */ /** The type of objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -74,12 +74,12 @@ public:
*/ */
void operator()(eoPop < MOEOT > & _pop) void operator()(eoPop < MOEOT > & _pop)
{ {
// 1 - setting of the bounds // 1 - setting of the bounds
setup(_pop); setup(_pop);
// 2 - computing every indicator values // 2 - computing every indicator values
computeValues(_pop); computeValues(_pop);
// 3 - setting fitnesses // 3 - setting fitnesses
setFitnesses(_pop); setFitnesses(_pop);
} }
@ -90,15 +90,15 @@ public:
*/ */
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
std::vector < double > v; std::vector < double > v;
v.resize(_pop.size()); v.resize(_pop.size());
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
v[i] = metric(_objVec, _pop[i].objectiveVector()); v[i] = metric(_objVec, _pop[i].objectiveVector());
} }
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
_pop[i].fitness( _pop[i].fitness() + exp(-v[i]/kappa) ); _pop[i].fitness( _pop[i].fitness() + exp(-v[i]/kappa) );
} }
} }
@ -111,34 +111,34 @@ public:
*/ */
double updateByAdding(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) double updateByAdding(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
std::vector < double > v; std::vector < double > v;
// update every fitness values to take the new individual into account // update every fitness values to take the new individual into account
v.resize(_pop.size()); v.resize(_pop.size());
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
v[i] = metric(_objVec, _pop[i].objectiveVector()); v[i] = metric(_objVec, _pop[i].objectiveVector());
} }
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
_pop[i].fitness( _pop[i].fitness() - exp(-v[i]/kappa) ); _pop[i].fitness( _pop[i].fitness() - exp(-v[i]/kappa) );
} }
// compute the fitness of the new individual // compute the fitness of the new individual
v.clear(); v.clear();
v.resize(_pop.size()); v.resize(_pop.size());
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
v[i] = metric(_pop[i].objectiveVector(), _objVec); v[i] = metric(_pop[i].objectiveVector(), _objVec);
} }
double result = 0; double result = 0;
for (unsigned int i=0; i<v.size(); i++) for (unsigned int i=0; i<v.size(); i++)
{ {
result -= exp(-v[i]/kappa); result -= exp(-v[i]/kappa);
} }
return result; return result;
} }
protected: protected:
/** the quality indicator */ /** the quality indicator */
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & metric; moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & metric;
@ -154,18 +154,18 @@ protected:
*/ */
void setup(const eoPop < MOEOT > & _pop) void setup(const eoPop < MOEOT > & _pop)
{ {
double min, max; double min, max;
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++) for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{ {
min = _pop[0].objectiveVector()[i]; min = _pop[0].objectiveVector()[i];
max = _pop[0].objectiveVector()[i]; max = _pop[0].objectiveVector()[i];
for (unsigned int j=1; j<_pop.size(); j++) for (unsigned int j=1; j<_pop.size(); j++)
{ {
min = std::min(min, _pop[j].objectiveVector()[i]); min = std::min(min, _pop[j].objectiveVector()[i]);
max = std::max(max, _pop[j].objectiveVector()[i]); max = std::max(max, _pop[j].objectiveVector()[i]);
} }
// setting of the bounds for the objective i // setting of the bounds for the objective i
metric.setup(min, max, i); metric.setup(min, max, i);
} }
} }
@ -176,16 +176,16 @@ protected:
*/ */
void computeValues(const eoPop < MOEOT > & _pop) void computeValues(const eoPop < MOEOT > & _pop)
{ {
values.clear(); values.clear();
values.resize(_pop.size()); values.resize(_pop.size());
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
values[i].resize(_pop.size()); values[i].resize(_pop.size());
for (unsigned int j=0; j<_pop.size(); j++) for (unsigned int j=0; j<_pop.size(); j++)
{ {
if (i != j) if (i != j)
{ {
values[i][j] = metric(_pop[i].objectiveVector(), _pop[j].objectiveVector()); values[i][j] = metric(_pop[i].objectiveVector(), _pop[j].objectiveVector());
} }
} }
} }
@ -198,9 +198,9 @@ protected:
*/ */
void setFitnesses(eoPop < MOEOT > & _pop) void setFitnesses(eoPop < MOEOT > & _pop)
{ {
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
_pop[i].fitness(computeFitness(i)); _pop[i].fitness(computeFitness(i));
} }
} }
@ -211,17 +211,17 @@ protected:
*/ */
double computeFitness(const unsigned int _idx) double computeFitness(const unsigned int _idx)
{ {
double result = 0; double result = 0;
for (unsigned int i=0; i<values.size(); i++) for (unsigned int i=0; i<values.size(); i++)
{ {
if (i != _idx) if (i != _idx)
{ {
result -= exp(-values[i][_idx]/kappa); result -= exp(-values[i][_idx]/kappa);
} }
} }
return result; return result;
} }
}; };
#endif /*MOEOEXPBINARYINDICATORBASEDFITNESSASSIGNMENT_H_*/ #endif /*MOEOEXPBINARYINDICATORBASEDFITNESSASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoFastNonDominatedSortingFitnessAssignment.h> * <moeoFastNonDominatedSortingFitnessAssignment.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
@ -55,8 +55,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoFastNonDominatedSortingFitnessAssignment : public moeoParetoBasedFitnessAssignment < MOEOT > class moeoFastNonDominatedSortingFitnessAssignment : public moeoParetoBasedFitnessAssignment < MOEOT >
{ {
public: public:
/** the objective vector type of the solutions */ /** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -83,37 +83,37 @@ public:
*/ */
void operator()(eoPop < MOEOT > & _pop) void operator()(eoPop < MOEOT > & _pop)
{ {
// number of objectives for the problem under consideration // number of objectives for the problem under consideration
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives(); unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
if (nObjectives == 1) if (nObjectives == 1)
{ {
// one objective // one objective
oneObjective(_pop); oneObjective(_pop);
} }
else if (nObjectives == 2) else if (nObjectives == 2)
{ {
// two objectives (the two objectives function is still to implement) // two objectives (the two objectives function is still to implement)
mObjectives(_pop); mObjectives(_pop);
} }
else if (nObjectives > 2) else if (nObjectives > 2)
{ {
// more than two objectives // more than two objectives
mObjectives(_pop); mObjectives(_pop);
} }
else else
{ {
// problem with the number of objectives // problem with the number of objectives
throw std::runtime_error("Problem with the number of objectives in moeoNonDominatedSortingFitnessAssignment"); throw std::runtime_error("Problem with the number of objectives in moeoNonDominatedSortingFitnessAssignment");
} }
// a higher fitness is better, so the values need to be inverted // a higher fitness is better, so the values need to be inverted
double max = _pop[0].fitness(); double max = _pop[0].fitness();
for (unsigned int i=1 ; i<_pop.size() ; i++) for (unsigned int i=1 ; i<_pop.size() ; i++)
{ {
max = std::max(max, _pop[i].fitness()); max = std::max(max, _pop[i].fitness());
} }
for (unsigned int i=0 ; i<_pop.size() ; i++) for (unsigned int i=0 ; i<_pop.size() ; i++)
{ {
_pop[i].fitness(max - _pop[i].fitness()); _pop[i].fitness(max - _pop[i].fitness());
} }
} }
@ -125,40 +125,41 @@ public:
*/ */
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
// if _pop[i] is dominated by _objVec // if _pop[i] is dominated by _objVec
if ( comparator(_pop[i].objectiveVector(), _objVec) ) if ( comparator(_pop[i].objectiveVector(), _objVec) )
{ {
_pop[i].fitness(_pop[i].fitness()+1); _pop[i].fitness(_pop[i].fitness()+1);
} }
} }
} }
private: private:
/** Functor to compare two objective vectors */ /** Functor to compare two objective vectors */
moeoObjectiveVectorComparator < ObjectiveVector > & comparator; moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
/** Functor to compare two objective vectors according to Pareto dominance relation */ /** Functor to compare two objective vectors according to Pareto dominance relation */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator; moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/** Functor allowing to compare two solutions according to their first objective value, then their second, and so on. */ /** Functor allowing to compare two solutions according to their first objective value, then their second, and so on. */
class ObjectiveComparator : public moeoComparator < MOEOT > class ObjectiveComparator : public moeoComparator < MOEOT >
{ {
public: public:
/** /**
* Returns true if _moeo1 < _moeo2 on the first objective, then on the second, and so on * Returns true if _moeo1 < _moeo2 on the first objective, then on the second, and so on
* @param _moeo1 the first solution * @param _moeo1 the first solution
* @param _moeo2 the second solution * @param _moeo2 the second solution
*/ */
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{ {
return cmp(_moeo1.objectiveVector(), _moeo2.objectiveVector()); return cmp(_moeo1.objectiveVector(), _moeo2.objectiveVector());
} }
private: private:
/** the corresponding comparator for objective vectors */ /** the corresponding comparator for objective vectors */
moeoObjectiveObjectiveVectorComparator < ObjectiveVector > cmp; moeoObjectiveObjectiveVectorComparator < ObjectiveVector > cmp;
} objComparator; }
objComparator;
/** /**
@ -167,18 +168,18 @@ private:
*/ */
void oneObjective (eoPop < MOEOT > & _pop) void oneObjective (eoPop < MOEOT > & _pop)
{ {
// sorts the population in the ascending order // sorts the population in the ascending order
std::sort(_pop.begin(), _pop.end(), objComparator); std::sort(_pop.begin(), _pop.end(), objComparator);
// assign fitness values // assign fitness values
unsigned int rank = 1; unsigned int rank = 1;
_pop[_pop.size()-1].fitness(rank); _pop[_pop.size()-1].fitness(rank);
for (unsigned int i=_pop.size()-2; i>=0; i--) for (unsigned int i=_pop.size()-2; i>=0; i--)
{ {
if (_pop[i].objectiveVector() != _pop[i+1].objectiveVector()) if (_pop[i].objectiveVector() != _pop[i+1].objectiveVector())
{ {
rank++; rank++;
} }
_pop[i].fitness(rank); _pop[i].fitness(rank);
} }
} }
@ -189,7 +190,7 @@ private:
*/ */
void twoObjectives (eoPop < MOEOT > & _pop) void twoObjectives (eoPop < MOEOT > & _pop)
{ {
//... TO DO ! //... TO DO !
} }
@ -199,66 +200,66 @@ private:
*/ */
void mObjectives (eoPop < MOEOT > & _pop) void mObjectives (eoPop < MOEOT > & _pop)
{ {
// S[i] = indexes of the individuals dominated by _pop[i] // S[i] = indexes of the individuals dominated by _pop[i]
std::vector < std::vector<unsigned int> > S(_pop.size()); std::vector < std::vector<unsigned int> > S(_pop.size());
// n[i] = number of individuals that dominate the individual _pop[i] // n[i] = number of individuals that dominate the individual _pop[i]
std::vector < unsigned int > n(_pop.size(), 0); std::vector < unsigned int > n(_pop.size(), 0);
// fronts: F[i] = indexes of the individuals contained in the ith front // fronts: F[i] = indexes of the individuals contained in the ith front
std::vector < std::vector<unsigned int> > F(_pop.size()+2); std::vector < std::vector<unsigned int> > F(_pop.size()+2);
// used to store the number of the first front // used to store the number of the first front
F[1].reserve(_pop.size()); F[1].reserve(_pop.size());
for (unsigned int p=0; p<_pop.size(); p++) for (unsigned int p=0; p<_pop.size(); p++)
{ {
for (unsigned int q=0; q<_pop.size(); q++) for (unsigned int q=0; q<_pop.size(); q++)
{ {
// if q is dominated by p // if q is dominated by p
if ( comparator(_pop[q].objectiveVector(), _pop[p].objectiveVector()) ) if ( comparator(_pop[q].objectiveVector(), _pop[p].objectiveVector()) )
{ {
// add q to the set of solutions dominated by p // add q to the set of solutions dominated by p
S[p].push_back(q); S[p].push_back(q);
} }
// if p is dominated by q // if p is dominated by q
else if ( comparator(_pop[p].objectiveVector(), _pop[q].objectiveVector()) ) else if ( comparator(_pop[p].objectiveVector(), _pop[q].objectiveVector()) )
{ {
// increment the domination counter of p // increment the domination counter of p
n[p]++; n[p]++;
} }
} }
// if no individual dominates p // if no individual dominates p
if (n[p] == 0) if (n[p] == 0)
{ {
// p belongs to the first front // p belongs to the first front
_pop[p].fitness(1); _pop[p].fitness(1);
F[1].push_back(p); F[1].push_back(p);
} }
} }
// front counter // front counter
unsigned int counter=1; unsigned int counter=1;
unsigned int p,q; unsigned int p,q;
while (! F[counter].empty()) while (! F[counter].empty())
{ {
// used to store the number of the next front // used to store the number of the next front
F[counter+1].reserve(_pop.size()); F[counter+1].reserve(_pop.size());
for (unsigned int i=0; i<F[counter].size(); i++) for (unsigned int i=0; i<F[counter].size(); i++)
{ {
p = F[counter][i]; p = F[counter][i];
for (unsigned int j=0; j<S[p].size(); j++) for (unsigned int j=0; j<S[p].size(); j++)
{ {
q = S[p][j]; q = S[p][j];
n[q]--; n[q]--;
// if no individual dominates q anymore // if no individual dominates q anymore
if (n[q] == 0) if (n[q] == 0)
{ {
// q belongs to the next front // q belongs to the next front
_pop[q].fitness(counter+1); _pop[q].fitness(counter+1);
F[counter+1].push_back(q); F[counter+1].push_back(q);
} }
} }
} }
counter++; counter++;
} }
} }
}; };
#endif /*MOEOFASTNONDOMINATEDSORTINGFITNESSASSIGNMENT_H_*/ #endif /*MOEOFASTNONDOMINATEDSORTINGFITNESSASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoFitnessAssignment.h> * <moeoFitnessAssignment.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,8 +46,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoFitnessAssignment : public eoUF < eoPop < MOEOT > &, void > class moeoFitnessAssignment : public eoUF < eoPop < MOEOT > &, void >
{ {
public: public:
/** The type for objective vector */ /** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -68,9 +68,9 @@ public:
*/ */
void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo) void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo)
{ {
updateByDeleting(_pop, _moeo.objectiveVector()); updateByDeleting(_pop, _moeo.objectiveVector());
} }
}; };
#endif /*MOEOFITNESSASSIGNMENT_H_*/ #endif /*MOEOFITNESSASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoIndicatorBasedFitnessAssignment.h> * <moeoIndicatorBasedFitnessAssignment.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 @@
* moeoIndicatorBasedFitnessAssignment is a moeoFitnessAssignment for Indicator-based strategies. * moeoIndicatorBasedFitnessAssignment is a moeoFitnessAssignment for Indicator-based strategies.
*/ */
template < class MOEOT > template < class MOEOT >
class moeoIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > {}; class moeoIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
{};
#endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/ #endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoParetoBasedFitnessAssignment.h> * <moeoParetoBasedFitnessAssignment.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 @@
* moeoParetoBasedFitnessAssignment is a moeoFitnessAssignment for Pareto-based strategies. * moeoParetoBasedFitnessAssignment is a moeoFitnessAssignment for Pareto-based strategies.
*/ */
template < class MOEOT > template < class MOEOT >
class moeoParetoBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > {}; class moeoParetoBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
{};
#endif /*MOEOPARETOBASEDFITNESSASSIGNMENT_H_*/ #endif /*MOEOPARETOBASEDFITNESSASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoReferencePointIndicatorBasedFitnessAssignment.h> * <moeoReferencePointIndicatorBasedFitnessAssignment.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 > template < class MOEOT >
class moeoReferencePointIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > class moeoReferencePointIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
{ {
public: public:
/** The type of objective vector */ /** The type of objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -60,7 +60,7 @@ public:
* @param _metric the quality indicator * @param _metric the quality indicator
*/ */
moeoReferencePointIndicatorBasedFitnessAssignment (ObjectiveVector & _refPoint, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric) : moeoReferencePointIndicatorBasedFitnessAssignment (ObjectiveVector & _refPoint, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric) :
refPoint(_refPoint), metric(_metric) refPoint(_refPoint), metric(_metric)
{} {}
@ -70,10 +70,10 @@ public:
*/ */
void operator()(eoPop < MOEOT > & _pop) void operator()(eoPop < MOEOT > & _pop)
{ {
// 1 - setting of the bounds // 1 - setting of the bounds
setup(_pop); setup(_pop);
// 2 - setting fitnesses // 2 - setting fitnesses
setFitnesses(_pop); setFitnesses(_pop);
} }
@ -84,11 +84,11 @@ public:
*/ */
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
// nothing to do ;-) // nothing to do ;-)
} }
protected: protected:
/** the reference point */ /** the reference point */
ObjectiveVector & refPoint; ObjectiveVector & refPoint;
@ -102,18 +102,18 @@ protected:
*/ */
void setup(const eoPop < MOEOT > & _pop) void setup(const eoPop < MOEOT > & _pop)
{ {
double min, max; double min, max;
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++) for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{ {
min = refPoint[i]; min = refPoint[i];
max = refPoint[i]; max = refPoint[i];
for (unsigned int j=0; j<_pop.size(); j++) for (unsigned int j=0; j<_pop.size(); j++)
{ {
min = std::min(min, _pop[j].objectiveVector()[i]); min = std::min(min, _pop[j].objectiveVector()[i]);
max = std::max(max, _pop[j].objectiveVector()[i]); max = std::max(max, _pop[j].objectiveVector()[i]);
} }
// setting of the bounds for the objective i // setting of the bounds for the objective i
metric.setup(min, max, i); metric.setup(min, max, i);
} }
} }
@ -123,12 +123,12 @@ protected:
*/ */
void setFitnesses(eoPop < MOEOT > & _pop) void setFitnesses(eoPop < MOEOT > & _pop)
{ {
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
_pop[i].fitness(- metric(_pop[i].objectiveVector(), refPoint) ); _pop[i].fitness(- metric(_pop[i].objectiveVector(), refPoint) );
} }
} }
}; };
#endif /*MOEOREFERENCEPOINTINDICATORBASEDFITNESSASSIGNMENT_H_*/ #endif /*MOEOREFERENCEPOINTINDICATORBASEDFITNESSASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoScalarFitnessAssignment.h> * <moeoScalarFitnessAssignment.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 @@
* moeoScalarFitnessAssignment is a moeoFitnessAssignment for scalar strategies. * moeoScalarFitnessAssignment is a moeoFitnessAssignment for scalar strategies.
*/ */
template < class MOEOT > template < class MOEOT >
class moeoScalarFitnessAssignment : public moeoFitnessAssignment < MOEOT > {}; class moeoScalarFitnessAssignment : public moeoFitnessAssignment < MOEOT >
{};
#endif /*MOEOSCALARFITNESSASSIGNMENT_H_*/ #endif /*MOEOSCALARFITNESSASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoUnaryIndicatorBasedFitnessAssignment.h> * <moeoUnaryIndicatorBasedFitnessAssignment.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 @@
* moeoIndicatorBasedFitnessAssignment for unary indicators. * moeoIndicatorBasedFitnessAssignment for unary indicators.
*/ */
template < class MOEOT > template < class MOEOT >
class moeoUnaryIndicatorBasedFitnessAssignment : public moeoIndicatorBasedFitnessAssignment < MOEOT > {}; class moeoUnaryIndicatorBasedFitnessAssignment : public moeoIndicatorBasedFitnessAssignment < MOEOT >
{};
#endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/ #endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoAdditiveEpsilonBinaryMetric.h> * <moeoAdditiveEpsilonBinaryMetric.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 ObjectiveVector > template < class ObjectiveVector >
class moeoAdditiveEpsilonBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > class moeoAdditiveEpsilonBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double >
{ {
public: public:
/** /**
* Returns the minimal distance by which the objective vector _o1 must be translated in all objectives * Returns the minimal distance by which the objective vector _o1 must be translated in all objectives
@ -59,21 +59,21 @@ public:
*/ */
double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2) double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2)
{ {
// computation of the epsilon value for the first objective // computation of the epsilon value for the first objective
double result = epsilon(_o1, _o2, 0); double result = epsilon(_o1, _o2, 0);
// computation of the epsilon value for the other objectives // computation of the epsilon value for the other objectives
double tmp; double tmp;
for (unsigned int i=1; i<ObjectiveVector::Traits::nObjectives(); i++) for (unsigned int i=1; i<ObjectiveVector::Traits::nObjectives(); i++)
{ {
tmp = epsilon(_o1, _o2, i); tmp = epsilon(_o1, _o2, i);
result = std::max(result, tmp); result = std::max(result, tmp);
} }
// returns the maximum epsilon value // returns the maximum epsilon value
return result; return result;
} }
private: private:
/** the bounds for every objective */ /** the bounds for every objective */
using moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > :: bounds; using moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > :: bounds;
@ -88,22 +88,22 @@ private:
*/ */
double epsilon(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj) double epsilon(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj)
{ {
double result; double result;
// if the objective _obj have to be minimized // if the objective _obj have to be minimized
if (ObjectiveVector::Traits::minimizing(_obj)) if (ObjectiveVector::Traits::minimizing(_obj))
{ {
// _o1[_obj] - _o2[_obj] // _o1[_obj] - _o2[_obj]
result = ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ); result = ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() );
} }
// if the objective _obj have to be maximized // if the objective _obj have to be maximized
else else
{ {
// _o2[_obj] - _o1[_obj] // _o2[_obj] - _o1[_obj]
result = ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ); result = ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() );
} }
return result; return result;
} }
}; };
#endif /*MOEOADDITIVEEPSILONBINARYMETRIC_H_*/ #endif /*MOEOADDITIVEEPSILONBINARYMETRIC_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoContributionMetric.h> * <moeoContributionMetric.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,44 +47,47 @@
*/ */
template < class ObjectiveVector > template < class ObjectiveVector >
class moeoContributionMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > class moeoContributionMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double >
{ {
public: public:
/** /**
* Returns the contribution of the Pareto set '_set1' relatively to the Pareto set '_set2' * Returns the contribution of the Pareto set '_set1' relatively to the Pareto set '_set2'
* @param _set1 the first Pareto set * @param _set1 the first Pareto set
* @param _set2 the second Pareto set * @param _set2 the second Pareto set
*/ */
double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) { double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2)
unsigned int c = card_C(_set1, _set2); {
unsigned int w1 = card_W(_set1, _set2); unsigned int c = card_C(_set1, _set2);
unsigned int n1 = card_N(_set1, _set2); unsigned int w1 = card_W(_set1, _set2);
unsigned int w2 = card_W(_set2, _set1); unsigned int n1 = card_N(_set1, _set2);
unsigned int n2 = card_N(_set2, _set1); unsigned int w2 = card_W(_set2, _set1);
return (double) (c / 2.0 + w1 + n1) / (c + w1 + n1 + w2 + n2); unsigned int n2 = card_N(_set2, _set1);
return (double) (c / 2.0 + w1 + n1) / (c + w1 + n1 + w2 + n2);
} }
private: private:
/** Functor to compare two objective vectors according to Pareto dominance relation */ /** Functor to compare two objective vectors according to Pareto dominance relation */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator; moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/** /**
* Returns the number of solutions both in '_set1' and '_set2' * Returns the number of solutions both in '_set1' and '_set2'
* @param _set1 the first Pareto set * @param _set1 the first Pareto set
* @param _set2 the second Pareto set * @param _set2 the second Pareto set
*/ */
unsigned int card_C (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) { unsigned int card_C (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2)
unsigned int c=0; {
for (unsigned int i=0; i<_set1.size(); i++) unsigned int c=0;
for (unsigned int j=0; j<_set2.size(); j++) for (unsigned int i=0; i<_set1.size(); i++)
if (_set1[i] == _set2[j]) { for (unsigned int j=0; j<_set2.size(); j++)
c++; if (_set1[i] == _set2[j])
break; {
} c++;
return c; break;
}
return c;
} }
@ -93,16 +96,17 @@ private:
* @param _set1 the first Pareto set * @param _set1 the first Pareto set
* @param _set2 the second Pareto set * @param _set2 the second Pareto set
*/ */
unsigned int card_W (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) { unsigned int card_W (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2)
unsigned int w=0; {
for (unsigned int i=0; i<_set1.size(); i++) unsigned int w=0;
for (unsigned int j=0; j<_set2.size(); j++) for (unsigned int i=0; i<_set1.size(); i++)
if (paretoComparator(_set2[j], _set1[i])) for (unsigned int j=0; j<_set2.size(); j++)
{ if (paretoComparator(_set2[j], _set1[i]))
w++; {
break; w++;
} break;
return w; }
return w;
} }
@ -111,22 +115,24 @@ private:
* @param _set1 the first Pareto set * @param _set1 the first Pareto set
* @param _set2 the second Pareto set * @param _set2 the second Pareto set
*/ */
unsigned int card_N (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) { unsigned int card_N (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2)
unsigned int n=0; {
for (unsigned int i=0; i<_set1.size(); i++) { unsigned int n=0;
bool domin_rel = false; for (unsigned int i=0; i<_set1.size(); i++)
for (unsigned int j=0; j<_set2.size(); j++) {
if ( (paretoComparator(_set2[j], _set1[i])) || (paretoComparator(_set1[i], _set2[j])) ) bool domin_rel = false;
{ for (unsigned int j=0; j<_set2.size(); j++)
domin_rel = true; if ( (paretoComparator(_set2[j], _set1[i])) || (paretoComparator(_set1[i], _set2[j])) )
break; {
} domin_rel = true;
if (! domin_rel) break;
n++; }
if (! domin_rel)
n++;
} }
return n; return n;
} }
}; };
#endif /*MOEOCONTRIBUTIONMETRIC_H_*/ #endif /*MOEOCONTRIBUTIONMETRIC_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoEntropyMetric.h> * <moeoEntropyMetric.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,52 +48,55 @@
*/ */
template < class ObjectiveVector > template < class ObjectiveVector >
class moeoEntropyMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > class moeoEntropyMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double >
{ {
public: public:
/** /**
* Returns the entropy of the Pareto set '_set1' relatively to the Pareto set '_set2' * Returns the entropy of the Pareto set '_set1' relatively to the Pareto set '_set2'
* @param _set1 the first Pareto set * @param _set1 the first Pareto set
* @param _set2 the second Pareto set * @param _set2 the second Pareto set
*/ */
double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) { double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2)
// normalization {
std::vector< ObjectiveVector > set1 = _set1; // normalization
std::vector< ObjectiveVector > set2= _set2; std::vector< ObjectiveVector > set1 = _set1;
removeDominated (set1); std::vector< ObjectiveVector > set2= _set2;
removeDominated (set2); removeDominated (set1);
prenormalize (set1); removeDominated (set2);
normalize (set1); prenormalize (set1);
normalize (set2); normalize (set1);
normalize (set2);
// making of PO* // making of PO*
std::vector< ObjectiveVector > star; // rotf :-) std::vector< ObjectiveVector > star; // rotf :-)
computeUnion (set1, set2, star); computeUnion (set1, set2, star);
removeDominated (star); removeDominated (star);
// making of PO1 U PO* // making of PO1 U PO*
std::vector< ObjectiveVector > union_set1_star; // rotf again ... std::vector< ObjectiveVector > union_set1_star; // rotf again ...
computeUnion (set1, star, union_set1_star); computeUnion (set1, star, union_set1_star);
unsigned int C = union_set1_star.size(); unsigned int C = union_set1_star.size();
float omega=0; float omega=0;
float entropy=0; float entropy=0;
for (unsigned int i=0 ; i<C ; i++) { for (unsigned int i=0 ; i<C ; i++)
unsigned int N_i = howManyInNicheOf (union_set1_star, union_set1_star[i], star.size()); {
unsigned int n_i = howManyInNicheOf (set1, union_set1_star[i], star.size()); unsigned int N_i = howManyInNicheOf (union_set1_star, union_set1_star[i], star.size());
if (n_i > 0) { unsigned int n_i = howManyInNicheOf (set1, union_set1_star[i], star.size());
omega += 1.0 / N_i; if (n_i > 0)
entropy += (float) n_i / (N_i * C) * log (((float) n_i / C) / log (2.0)); {
omega += 1.0 / N_i;
entropy += (float) n_i / (N_i * C) * log (((float) n_i / C) / log (2.0));
} }
} }
entropy /= - log (omega); entropy /= - log (omega);
entropy *= log (2.0); entropy *= log (2.0);
return entropy; return entropy;
} }
private: private:
/** vector of min values */ /** vector of min values */
std::vector<double> vect_min_val; std::vector<double> vect_min_val;
@ -107,19 +110,22 @@ private:
* Removes the dominated individuals contained in _f * Removes the dominated individuals contained in _f
* @param _f a Pareto set * @param _f a Pareto set
*/ */
void removeDominated(std::vector < ObjectiveVector > & _f) { void removeDominated(std::vector < ObjectiveVector > & _f)
for (unsigned int i=0 ; i<_f.size(); i++) { {
bool dom = false; for (unsigned int i=0 ; i<_f.size(); i++)
for (unsigned int j=0; j<_f.size(); j++) {
if (i != j && paretoComparator(_f[i],_f[j])) bool dom = false;
{ for (unsigned int j=0; j<_f.size(); j++)
dom = true; if (i != j && paretoComparator(_f[i],_f[j]))
break; {
} dom = true;
if (dom) { break;
_f[i] = _f.back(); }
_f.pop_back(); if (dom)
i--; {
_f[i] = _f.back();
_f.pop_back();
i--;
} }
} }
} }
@ -129,20 +135,23 @@ private:
* Prenormalization * Prenormalization
* @param _f a Pareto set * @param _f a Pareto set
*/ */
void prenormalize (const std::vector< ObjectiveVector > & _f) { void prenormalize (const std::vector< ObjectiveVector > & _f)
vect_min_val.clear(); {
vect_max_val.clear(); vect_min_val.clear();
vect_max_val.clear();
for (unsigned int i=0 ; i<ObjectiveVector::nObjectives(); i++) { for (unsigned int i=0 ; i<ObjectiveVector::nObjectives(); i++)
float min_val = _f.front()[i], max_val = min_val; {
for (unsigned int j=1 ; j<_f.size(); j++) { float min_val = _f.front()[i], max_val = min_val;
if (_f[j][i] < min_val) for (unsigned int j=1 ; j<_f.size(); j++)
min_val = _f[j][i]; {
if (_f[j][i]>max_val) if (_f[j][i] < min_val)
max_val = _f[j][i]; min_val = _f[j][i];
if (_f[j][i]>max_val)
max_val = _f[j][i];
} }
vect_min_val.push_back(min_val); vect_min_val.push_back(min_val);
vect_max_val.push_back (max_val); vect_max_val.push_back (max_val);
} }
} }
@ -151,10 +160,11 @@ private:
* Normalization * Normalization
* @param _f a Pareto set * @param _f a Pareto set
*/ */
void normalize (std::vector< ObjectiveVector > & _f) { void normalize (std::vector< ObjectiveVector > & _f)
for (unsigned int i=0 ; i<ObjectiveVector::nObjectives(); i++) {
for (unsigned int j=0; j<_f.size(); j++) for (unsigned int i=0 ; i<ObjectiveVector::nObjectives(); i++)
_f[j][i] = (_f[j][i] - vect_min_val[i]) / (vect_max_val[i] - vect_min_val[i]); for (unsigned int j=0; j<_f.size(); j++)
_f[j][i] = (_f[j][i] - vect_min_val[i]) / (vect_max_val[i] - vect_min_val[i]);
} }
@ -164,17 +174,20 @@ private:
* @param _f2 the second Pareto set * @param _f2 the second Pareto set
* @param _f the final Pareto set * @param _f the final Pareto set
*/ */
void computeUnion(const std::vector< ObjectiveVector > & _f1, const std::vector< ObjectiveVector > & _f2, std::vector< ObjectiveVector > & _f) { void computeUnion(const std::vector< ObjectiveVector > & _f1, const std::vector< ObjectiveVector > & _f2, std::vector< ObjectiveVector > & _f)
_f = _f1 ; {
for (unsigned int i=0; i<_f2.size(); i++) { _f = _f1 ;
bool b = false; for (unsigned int i=0; i<_f2.size(); i++)
for (unsigned int j=0; j<_f1.size(); j ++) {
if (_f1[j] == _f2[i]) { bool b = false;
b = true; for (unsigned int j=0; j<_f1.size(); j ++)
break; if (_f1[j] == _f2[i])
} {
if (! b) b = true;
_f.push_back(_f2[i]); break;
}
if (! b)
_f.push_back(_f2[i]);
} }
} }
@ -182,26 +195,29 @@ private:
/** /**
* How many in niche * How many in niche
*/ */
unsigned int howManyInNicheOf (const std::vector< ObjectiveVector > & _f, const ObjectiveVector & _s, unsigned int _size) { unsigned int howManyInNicheOf (const std::vector< ObjectiveVector > & _f, const ObjectiveVector & _s, unsigned int _size)
unsigned int n=0; {
for (unsigned int i=0 ; i<_f.size(); i++) { unsigned int n=0;
if (euclidianDistance(_f[i], _s) < (_s.size() / (double) _size)) for (unsigned int i=0 ; i<_f.size(); i++)
n++; {
if (euclidianDistance(_f[i], _s) < (_s.size() / (double) _size))
n++;
} }
return n; return n;
} }
/** /**
* Euclidian distance * Euclidian distance
*/ */
double euclidianDistance (const ObjectiveVector & _set1, const ObjectiveVector & _to, unsigned int _deg = 2) { double euclidianDistance (const ObjectiveVector & _set1, const ObjectiveVector & _to, unsigned int _deg = 2)
double dist=0; {
for (unsigned int i=0; i<_set1.size(); i++) double dist=0;
dist += pow(fabs(_set1[i] - _to[i]), (int)_deg); for (unsigned int i=0; i<_set1.size(); i++)
return pow(dist, 1.0 / _deg); dist += pow(fabs(_set1[i] - _to[i]), (int)_deg);
return pow(dist, 1.0 / _deg);
} }
}; };
#endif /*MOEOENTROPYMETRIC_H_*/ #endif /*MOEOENTROPYMETRIC_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoHypervolumeBinaryMetric.h> * <moeoHypervolumeBinaryMetric.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
@ -52,8 +52,8 @@
*/ */
template < class ObjectiveVector > template < class ObjectiveVector >
class moeoHypervolumeBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > class moeoHypervolumeBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double >
{ {
public: public:
/** /**
* Ctor * Ctor
@ -61,20 +61,20 @@ public:
*/ */
moeoHypervolumeBinaryMetric(double _rho = 1.1) : rho(_rho) moeoHypervolumeBinaryMetric(double _rho = 1.1) : rho(_rho)
{ {
// not-a-maximization problem check // not-a-maximization problem check
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++) for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{ {
if (ObjectiveVector::Traits::maximizing(i)) if (ObjectiveVector::Traits::maximizing(i))
{ {
throw std::runtime_error("Hypervolume binary metric not yet implemented for a maximization problem in moeoHypervolumeBinaryMetric"); throw std::runtime_error("Hypervolume binary metric not yet implemented for a maximization problem in moeoHypervolumeBinaryMetric");
} }
} }
// consistency check // consistency check
if (rho < 1) if (rho < 1)
{ {
std::cout << "Warning, value used to compute the reference point rho for the hypervolume calculation must not be smaller than 1" << std::endl; std::cout << "Warning, value used to compute the reference point rho for the hypervolume calculation must not be smaller than 1" << std::endl;
std::cout << "Adjusted to 1" << std::endl; std::cout << "Adjusted to 1" << std::endl;
rho = 1; rho = 1;
} }
} }
@ -87,21 +87,21 @@ public:
*/ */
double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2) double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2)
{ {
double result; double result;
// if _o2 is dominated by _o1 // if _o2 is dominated by _o1
if ( paretoComparator(_o2,_o1) ) if ( paretoComparator(_o2,_o1) )
{ {
result = - hypervolume(_o1, _o2, ObjectiveVector::Traits::nObjectives()-1); result = - hypervolume(_o1, _o2, ObjectiveVector::Traits::nObjectives()-1);
} }
else else
{ {
result = hypervolume(_o2, _o1, ObjectiveVector::Traits::nObjectives()-1); result = hypervolume(_o2, _o1, ObjectiveVector::Traits::nObjectives()-1);
} }
return result; return result;
} }
private: private:
/** value used to compute the reference point from the worst values for each objective */ /** value used to compute the reference point from the worst values for each objective */
double rho; double rho;
@ -120,47 +120,47 @@ private:
*/ */
double hypervolume(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj, const bool _flag = false) double hypervolume(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj, const bool _flag = false)
{ {
double result; double result;
double range = rho * bounds[_obj].range(); double range = rho * bounds[_obj].range();
double max = bounds[_obj].minimum() + range; double max = bounds[_obj].minimum() + range;
// value of _1 for the objective _obj // value of _1 for the objective _obj
double v1 = _o1[_obj]; double v1 = _o1[_obj];
// value of _2 for the objective _obj (if _flag=true, v2=max) // value of _2 for the objective _obj (if _flag=true, v2=max)
double v2; double v2;
if (_flag) if (_flag)
{ {
v2 = max; v2 = max;
} }
else else
{ {
v2 = _o2[_obj]; v2 = _o2[_obj];
} }
// computation of the volume // computation of the volume
if (_obj == 0) if (_obj == 0)
{ {
if (v1 < v2) if (v1 < v2)
{ {
result = (v2 - v1) / range; result = (v2 - v1) / range;
} }
else else
{ {
result = 0; result = 0;
} }
} }
else else
{ {
if (v1 < v2) if (v1 < v2)
{ {
result = ( hypervolume(_o1, _o2, _obj-1, true) * (v2 - v1) / range ) + ( hypervolume(_o1, _o2, _obj-1) * (max - v2) / range ); result = ( hypervolume(_o1, _o2, _obj-1, true) * (v2 - v1) / range ) + ( hypervolume(_o1, _o2, _obj-1) * (max - v2) / range );
} }
else else
{ {
result = hypervolume(_o1, _o2, _obj-1) * (max - v2) / range; result = hypervolume(_o1, _o2, _obj-1) * (max - v2) / range;
} }
} }
return result; return result;
} }
}; };
#endif /*MOEOHYPERVOLUMEBINARYMETRIC_H_*/ #endif /*MOEOHYPERVOLUMEBINARYMETRIC_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoMetric.h> * <moeoMetric.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,49 +44,56 @@
/** /**
* Base class for performance metrics (also known as quality indicators). * Base class for performance metrics (also known as quality indicators).
*/ */
class moeoMetric : public eoFunctorBase {}; class moeoMetric : public eoFunctorBase
{};
/** /**
* Base class for unary metrics. * Base class for unary metrics.
*/ */
template < class A, class R > template < class A, class R >
class moeoUnaryMetric : public eoUF < A, R >, public moeoMetric {}; class moeoUnaryMetric : public eoUF < A, R >, public moeoMetric
{};
/** /**
* Base class for binary metrics. * Base class for binary metrics.
*/ */
template < class A1, class A2, class R > template < class A1, class A2, class R >
class moeoBinaryMetric : public eoBF < A1, A2, R >, public moeoMetric {}; class moeoBinaryMetric : public eoBF < A1, A2, R >, public moeoMetric
{};
/** /**
* Base class for unary metrics dedicated to the performance evaluation of a single solution's objective vector. * Base class for unary metrics dedicated to the performance evaluation of a single solution's objective vector.
*/ */
template < class ObjectiveVector, class R > template < class ObjectiveVector, class R >
class moeoSolutionUnaryMetric : public moeoUnaryMetric < const ObjectiveVector &, R > {}; class moeoSolutionUnaryMetric : public moeoUnaryMetric < const ObjectiveVector &, R >
{};
/** /**
* Base class for unary metrics dedicated to the performance evaluation of a Pareto set (a vector of objective vectors) * Base class for unary metrics dedicated to the performance evaluation of a Pareto set (a vector of objective vectors)
*/ */
template < class ObjectiveVector, class R > template < class ObjectiveVector, class R >
class moeoVectorUnaryMetric : public moeoUnaryMetric < const std::vector < ObjectiveVector > &, R > {}; class moeoVectorUnaryMetric : public moeoUnaryMetric < const std::vector < ObjectiveVector > &, R >
{};
/** /**
* Base class for binary metrics dedicated to the performance comparison between two solutions's objective vectors. * Base class for binary metrics dedicated to the performance comparison between two solutions's objective vectors.
*/ */
template < class ObjectiveVector, class R > template < class ObjectiveVector, class R >
class moeoSolutionVsSolutionBinaryMetric : public moeoBinaryMetric < const ObjectiveVector &, const ObjectiveVector &, R > {}; class moeoSolutionVsSolutionBinaryMetric : public moeoBinaryMetric < const ObjectiveVector &, const ObjectiveVector &, R >
{};
/** /**
* Base class for binary metrics dedicated to the performance comparison between two Pareto sets (two vectors of objective vectors) * Base class for binary metrics dedicated to the performance comparison between two Pareto sets (two vectors of objective vectors)
*/ */
template < class ObjectiveVector, class R > template < class ObjectiveVector, class R >
class moeoVectorVsVectorBinaryMetric : public moeoBinaryMetric < const std::vector < ObjectiveVector > &, const std::vector < ObjectiveVector > &, R > {}; class moeoVectorVsVectorBinaryMetric : public moeoBinaryMetric < const std::vector < ObjectiveVector > &, const std::vector < ObjectiveVector > &, R >
{};
#endif /*MOEOMETRIC_H_*/ #endif /*MOEOMETRIC_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoNormalizedSolutionVsSolutionBinaryMetric.h> * <moeoNormalizedSolutionVsSolutionBinaryMetric.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
@ -49,19 +49,19 @@
*/ */
template < class ObjectiveVector, class R > template < class ObjectiveVector, class R >
class moeoNormalizedSolutionVsSolutionBinaryMetric : public moeoSolutionVsSolutionBinaryMetric < ObjectiveVector, R > class moeoNormalizedSolutionVsSolutionBinaryMetric : public moeoSolutionVsSolutionBinaryMetric < ObjectiveVector, R >
{ {
public: public:
/** /**
* Default ctr for any moeoNormalizedSolutionVsSolutionBinaryMetric object * Default ctr for any moeoNormalizedSolutionVsSolutionBinaryMetric object
*/ */
moeoNormalizedSolutionVsSolutionBinaryMetric() moeoNormalizedSolutionVsSolutionBinaryMetric()
{ {
bounds.resize(ObjectiveVector::Traits::nObjectives()); bounds.resize(ObjectiveVector::Traits::nObjectives());
// initialize bounds in case someone does not want to use them // initialize bounds in case someone does not want to use them
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++) for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{ {
bounds[i] = eoRealInterval(0,1); bounds[i] = eoRealInterval(0,1);
} }
} }
@ -74,12 +74,12 @@ public:
*/ */
void setup(double _min, double _max, unsigned int _obj) void setup(double _min, double _max, unsigned int _obj)
{ {
if (_min == _max) if (_min == _max)
{ {
_min -= tiny(); _min -= tiny();
_max += tiny(); _max += tiny();
} }
bounds[_obj] = eoRealInterval(_min, _max); bounds[_obj] = eoRealInterval(_min, _max);
} }
@ -90,7 +90,7 @@ public:
*/ */
virtual void setup(eoRealInterval _realInterval, unsigned int _obj) virtual void setup(eoRealInterval _realInterval, unsigned int _obj)
{ {
bounds[_obj] = _realInterval; bounds[_obj] = _realInterval;
} }
@ -99,15 +99,15 @@ public:
*/ */
static double tiny() static double tiny()
{ {
return 1e-6; return 1e-6;
} }
protected: protected:
/** the bounds for every objective (bounds[i] = bounds for the objective i) */ /** the bounds for every objective (bounds[i] = bounds for the objective i) */
std::vector < eoRealInterval > bounds; std::vector < eoRealInterval > bounds;
}; };
#endif /*MOEONORMALIZEDSOLUTIONVSSOLUTIONBINARYMETRIC_H_*/ #endif /*MOEONORMALIZEDSOLUTIONVSSOLUTIONBINARYMETRIC_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoMoveIncrEval.h> * <moeoMoveIncrEval.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 @@
#include <eoFunctor.h> #include <eoFunctor.h>
template < class Move > template < class Move >
class moeoMoveIncrEval : public eoBF < const Move &, const typename Move::EOType &, typename Move::EOType::ObjectiveVector > {}; class moeoMoveIncrEval : public eoBF < const Move &, const typename Move::EOType &, typename Move::EOType::ObjectiveVector >
{};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moeoElitistReplacement.h> * <moeoElitistReplacement.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
@ -49,8 +49,8 @@
* Elitist replacement strategy that consists in keeping the N best individuals. * Elitist replacement strategy that consists in keeping the N best individuals.
*/ */
template < class MOEOT > class moeoElitistReplacement:public moeoReplacement < MOEOT > template < class MOEOT > class moeoElitistReplacement:public moeoReplacement < MOEOT >
{ {
public: public:
/** /**
* Full constructor. * Full constructor.
@ -59,7 +59,7 @@ public:
* @param _comparator the comparator (used to compare 2 individuals) * @param _comparator the comparator (used to compare 2 individuals)
*/ */
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment, moeoComparator < MOEOT > & _comparator) : moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment, moeoComparator < MOEOT > & _comparator) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (_comparator) fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (_comparator)
{} {}
@ -69,7 +69,7 @@ public:
* @param _diversityAssignment the diversity assignment strategy * @param _diversityAssignment the diversity assignment strategy
*/ */
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment) : moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (defaultComparator) fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (defaultComparator)
{} {}
@ -79,7 +79,7 @@ public:
* @param _comparator the comparator (used to compare 2 individuals) * @param _comparator the comparator (used to compare 2 individuals)
*/ */
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoComparator < MOEOT > & _comparator) : moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoComparator < MOEOT > & _comparator) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (_comparator) fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (_comparator)
{} {}
@ -89,7 +89,7 @@ public:
* @param _fitnessAssignment the fitness assignment strategy * @param _fitnessAssignment the fitness assignment strategy
*/ */
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment) : moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (defaultComparator) fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (defaultComparator)
{} {}
@ -100,23 +100,23 @@ public:
*/ */
void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring) void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring)
{ {
unsigned int sz = _parents.size (); unsigned int sz = _parents.size ();
// merges offspring and parents into a global population // merges offspring and parents into a global population
_parents.reserve (_parents.size () + _offspring.size ()); _parents.reserve (_parents.size () + _offspring.size ());
std::copy (_offspring.begin (), _offspring.end (), back_inserter (_parents)); std::copy (_offspring.begin (), _offspring.end (), back_inserter (_parents));
// evaluates the fitness and the diversity of this global population // evaluates the fitness and the diversity of this global population
fitnessAssignment (_parents); fitnessAssignment (_parents);
diversityAssignment (_parents); diversityAssignment (_parents);
// sorts the whole population according to the comparator // sorts the whole population according to the comparator
std::sort(_parents.begin(), _parents.end(), comparator); std::sort(_parents.begin(), _parents.end(), comparator);
// finally, resize this global population // finally, resize this global population
_parents.resize (sz); _parents.resize (sz);
// and clear the offspring population // and clear the offspring population
_offspring.clear (); _offspring.clear ();
} }
protected: protected:
/** the fitness assignment strategy */ /** the fitness assignment strategy */
moeoFitnessAssignment < MOEOT > & fitnessAssignment; moeoFitnessAssignment < MOEOT > & fitnessAssignment;
@ -128,8 +128,8 @@ protected:
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator; moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
/** this object is used to compare solutions in order to sort the population */ /** this object is used to compare solutions in order to sort the population */
class Cmp class Cmp
{ {
public: public:
/** /**
* Ctor. * Ctor.
* @param _comp the comparator * @param _comp the comparator
@ -143,13 +143,14 @@ protected:
*/ */
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{ {
return comp(_moeo2,_moeo1); return comp(_moeo2,_moeo1);
} }
private: private:
/** the comparator */ /** the comparator */
moeoComparator < MOEOT > & comp; moeoComparator < MOEOT > & comp;
} comparator; }
comparator;
}; };
#endif /*MOEOELITISTREPLACEMENT_H_ */ #endif /*MOEOELITISTREPLACEMENT_H_ */

View file

@ -1,4 +1,4 @@
/* /*
* <moeoEnvironmentalReplacement.h> * <moeoEnvironmentalReplacement.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
@ -49,8 +49,8 @@
* and by updating the fitness and diversity values after each deletion. * and by updating the fitness and diversity values after each deletion.
*/ */
template < class MOEOT > class moeoEnvironmentalReplacement:public moeoReplacement < MOEOT > template < class MOEOT > class moeoEnvironmentalReplacement:public moeoReplacement < MOEOT >
{ {
public: public:
/** The type for objective vector */ /** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -63,7 +63,7 @@ public:
* @param _comparator the comparator (used to compare 2 individuals) * @param _comparator the comparator (used to compare 2 individuals)
*/ */
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment, moeoComparator < MOEOT > & _comparator) : moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment, moeoComparator < MOEOT > & _comparator) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (_comparator) fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (_comparator)
{} {}
@ -73,7 +73,7 @@ public:
* @param _diversityAssignment the diversity assignment strategy * @param _diversityAssignment the diversity assignment strategy
*/ */
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment) : moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (defaultComparator) fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (defaultComparator)
{} {}
@ -83,7 +83,7 @@ public:
* @param _comparator the comparator (used to compare 2 individuals) * @param _comparator the comparator (used to compare 2 individuals)
*/ */
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoComparator < MOEOT > & _comparator) : moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoComparator < MOEOT > & _comparator) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (_comparator) fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (_comparator)
{} {}
@ -93,7 +93,7 @@ public:
* @param _fitnessAssignment the fitness assignment strategy * @param _fitnessAssignment the fitness assignment strategy
*/ */
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment) : moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (defaultComparator) fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (defaultComparator)
{} {}
@ -104,35 +104,35 @@ public:
*/ */
void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring) void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring)
{ {
unsigned int sz = _parents.size(); unsigned int sz = _parents.size();
// merges offspring and parents into a global population // merges offspring and parents into a global population
_parents.reserve (_parents.size() + _offspring.size()); _parents.reserve (_parents.size() + _offspring.size());
std::copy (_offspring.begin(), _offspring.end(), back_inserter(_parents)); std::copy (_offspring.begin(), _offspring.end(), back_inserter(_parents));
// evaluates the fitness and the diversity of this global population // evaluates the fitness and the diversity of this global population
fitnessAssignment (_parents); fitnessAssignment (_parents);
diversityAssignment (_parents); diversityAssignment (_parents);
// remove individuals 1 by 1 and update the fitness values // remove individuals 1 by 1 and update the fitness values
unsigned int worstIdx; unsigned int worstIdx;
ObjectiveVector worstObjVec; ObjectiveVector worstObjVec;
while (_parents.size() > sz) while (_parents.size() > sz)
{ {
// the individual to delete // the individual to delete
worstIdx = std::min_element(_parents.begin(), _parents.end(), comparator) - _parents.begin(); worstIdx = std::min_element(_parents.begin(), _parents.end(), comparator) - _parents.begin();
worstObjVec = _parents[worstIdx].objectiveVector(); worstObjVec = _parents[worstIdx].objectiveVector();
// remove the woorst individual // remove the woorst individual
_parents[worstIdx] = _parents.back(); _parents[worstIdx] = _parents.back();
_parents.pop_back(); _parents.pop_back();
// update of the fitness and diversity values // update of the fitness and diversity values
fitnessAssignment.updateByDeleting(_parents, worstObjVec); fitnessAssignment.updateByDeleting(_parents, worstObjVec);
diversityAssignment.updateByDeleting(_parents, worstObjVec); diversityAssignment.updateByDeleting(_parents, worstObjVec);
} }
// clear the offspring population // clear the offspring population
_offspring.clear (); _offspring.clear ();
} }
protected: protected:
/** the fitness assignment strategy */ /** the fitness assignment strategy */
moeoFitnessAssignment < MOEOT > & fitnessAssignment; moeoFitnessAssignment < MOEOT > & fitnessAssignment;
@ -144,8 +144,8 @@ protected:
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator; moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
/** this object is used to compare solutions in order to sort the population */ /** this object is used to compare solutions in order to sort the population */
class Cmp class Cmp
{ {
public: public:
/** /**
* Ctor. * Ctor.
* @param _comp the comparator * @param _comp the comparator
@ -159,13 +159,14 @@ protected:
*/ */
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{ {
return comp(_moeo1,_moeo2); return comp(_moeo1,_moeo2);
} }
private: private:
/** the comparator */ /** the comparator */
moeoComparator < MOEOT > & comp; moeoComparator < MOEOT > & comp;
} comparator; }
comparator;
}; };
#endif /*MOEOENVIRONMENTALREPLACEMENT_H_ */ #endif /*MOEOENVIRONMENTALREPLACEMENT_H_ */

View file

@ -1,4 +1,4 @@
/* /*
* <moeoGenerationalReplacement.h> * <moeoGenerationalReplacement.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,8 +46,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoGenerationalReplacement : public moeoReplacement < MOEOT >, public eoGenerationalReplacement < MOEOT > class moeoGenerationalReplacement : public moeoReplacement < MOEOT >, public eoGenerationalReplacement < MOEOT >
{ {
public: public:
/** /**
* Swaps _parents and _offspring * Swaps _parents and _offspring
@ -56,9 +56,9 @@ public:
*/ */
void operator()(eoPop < MOEOT > & _parents, eoPop < MOEOT > & _offspring) void operator()(eoPop < MOEOT > & _parents, eoPop < MOEOT > & _offspring)
{ {
eoGenerationalReplacement < MOEOT >::operator ()(_parents, _offspring); eoGenerationalReplacement < MOEOT >::operator ()(_parents, _offspring);
} }
}; };
#endif /*MOEOGENERATIONALREPLACEMENT_H_*/ #endif /*MOEOGENERATIONALREPLACEMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoReplacement.h> * <moeoReplacement.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 @@
* Replacement strategy for multi-objective optimization. * Replacement strategy for multi-objective optimization.
*/ */
template < class MOEOT > template < class MOEOT >
class moeoReplacement : public eoReplacement < MOEOT > {}; class moeoReplacement : public eoReplacement < MOEOT >
{};
#endif /*MOEOREPLACEMENT_H_*/ #endif /*MOEOREPLACEMENT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoDetTournamentSelect.h> * <moeoDetTournamentSelect.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 @@
* Selection strategy that selects ONE individual by deterministic tournament. * Selection strategy that selects ONE individual by deterministic tournament.
*/ */
template < class MOEOT > class moeoDetTournamentSelect:public moeoSelectOne < MOEOT > template < class MOEOT > class moeoDetTournamentSelect:public moeoSelectOne < MOEOT >
{ {
public: public:
/** /**
* Full Ctor. * Full Ctor.
@ -57,12 +57,12 @@ public:
*/ */
moeoDetTournamentSelect (moeoComparator < MOEOT > & _comparator, unsigned int _tSize = 2) : comparator (_comparator), tSize (_tSize) moeoDetTournamentSelect (moeoComparator < MOEOT > & _comparator, unsigned int _tSize = 2) : comparator (_comparator), tSize (_tSize)
{ {
// consistency check // consistency check
if (tSize < 2) if (tSize < 2)
{ {
std:: std::
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n"; cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
tSize = 2; tSize = 2;
} }
} }
@ -73,12 +73,12 @@ public:
*/ */
moeoDetTournamentSelect (unsigned int _tSize = 2) : comparator (defaultComparator), tSize (_tSize) moeoDetTournamentSelect (unsigned int _tSize = 2) : comparator (defaultComparator), tSize (_tSize)
{ {
// consistency check // consistency check
if (tSize < 2) if (tSize < 2)
{ {
std:: std::
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n"; cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
tSize = 2; tSize = 2;
} }
} }
@ -89,12 +89,12 @@ public:
*/ */
const MOEOT & operator() (const eoPop < MOEOT > &_pop) const MOEOT & operator() (const eoPop < MOEOT > &_pop)
{ {
// use the selector // use the selector
return mo_deterministic_tournament (_pop, tSize, comparator); return mo_deterministic_tournament (_pop, tSize, comparator);
} }
protected: protected:
/** the comparator (used to compare 2 individuals) */ /** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > & comparator; moeoComparator < MOEOT > & comparator;
@ -103,6 +103,6 @@ protected:
/** the number of individuals in the tournament */ /** the number of individuals in the tournament */
unsigned int tSize; unsigned int tSize;
}; };
#endif /*MOEODETTOURNAMENTSELECT_H_ */ #endif /*MOEODETTOURNAMENTSELECT_H_ */

View file

@ -1,4 +1,4 @@
/* /*
* <moeoRandomSelect.h> * <moeoRandomSelect.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,13 +46,14 @@
* Selection strategy that selects only one element randomly from a whole population. * Selection strategy that selects only one element randomly from a whole population.
*/ */
template < class MOEOT > class moeoRandomSelect:public moeoSelectOne < MOEOT >, public eoRandomSelect <MOEOT > template < class MOEOT > class moeoRandomSelect:public moeoSelectOne < MOEOT >, public eoRandomSelect <MOEOT >
{ {
public: public:
/** /**
* Ctor. * Ctor.
*/ */
moeoRandomSelect(){} moeoRandomSelect()
{}
/** /**
@ -60,9 +61,9 @@ public:
*/ */
const MOEOT & operator () (const eoPop < MOEOT > &_pop) const MOEOT & operator () (const eoPop < MOEOT > &_pop)
{ {
return eoRandomSelect < MOEOT >::operator ()(_pop); return eoRandomSelect < MOEOT >::operator ()(_pop);
} }
}; };
#endif /*MOEORANDOMSELECT_H_ */ #endif /*MOEORANDOMSELECT_H_ */

View file

@ -1,4 +1,4 @@
/* /*
* <moeoRouletteSelect.h> * <moeoRouletteSelect.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 moeoRouletteSelect:public moeoSelectOne < MOEOT > class moeoRouletteSelect:public moeoSelectOne < MOEOT >
{ {
public: public:
/** /**
* Ctor. * Ctor.
@ -56,12 +56,12 @@ public:
*/ */
moeoRouletteSelect (unsigned int _tSize = 2) : tSize (_tSize) moeoRouletteSelect (unsigned int _tSize = 2) : tSize (_tSize)
{ {
// consistency check // consistency check
if (tSize < 2) if (tSize < 2)
{ {
std:: std::
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n"; cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
tSize = 2; tSize = 2;
} }
} }
@ -72,16 +72,16 @@ public:
*/ */
const MOEOT & operator () (const eoPop < MOEOT > & _pop) const MOEOT & operator () (const eoPop < MOEOT > & _pop)
{ {
// use the selector // use the selector
return mo_roulette_wheel(_pop,tSize); return mo_roulette_wheel(_pop,tSize);
} }
protected: protected:
/** size */ /** size */
double & tSize; double & tSize;
}; };
#endif /*MOEOROULETTESELECT_H_ */ #endif /*MOEOROULETTESELECT_H_ */

View file

@ -1,4 +1,4 @@
/* /*
* <moeoSelectFromPopAndArch.h> * <moeoSelectFromPopAndArch.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
@ -49,8 +49,8 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoSelectFromPopAndArch : public moeoSelectOne < MOEOT > class moeoSelectFromPopAndArch : public moeoSelectOne < MOEOT >
{ {
public: public:
/** /**
* Ctor * Ctor
@ -60,7 +60,7 @@ public:
* @param _ratioFromPop the ratio of selected individuals from the population * @param _ratioFromPop the ratio of selected individuals from the population
*/ */
moeoSelectFromPopAndArch (moeoSelectOne < MOEOT > & _popSelectOne, moeoSelectOne < MOEOT > _archSelectOne, moeoArchive < MOEOT > & _arch, double _ratioFromPop=0.5) moeoSelectFromPopAndArch (moeoSelectOne < MOEOT > & _popSelectOne, moeoSelectOne < MOEOT > _archSelectOne, moeoArchive < MOEOT > & _arch, double _ratioFromPop=0.5)
: popSelectOne(_popSelectOne), archSelectOne(_archSelectOne), arch(_arch), ratioFromPop(_ratioFromPop) : popSelectOne(_popSelectOne), archSelectOne(_archSelectOne), arch(_arch), ratioFromPop(_ratioFromPop)
{} {}
@ -71,7 +71,7 @@ public:
* @param _ratioFromPop the ratio of selected individuals from the population * @param _ratioFromPop the ratio of selected individuals from the population
*/ */
moeoSelectFromPopAndArch (moeoSelectOne < MOEOT > & _popSelectOne, moeoArchive < MOEOT > & _arch, double _ratioFromPop=0.5) moeoSelectFromPopAndArch (moeoSelectOne < MOEOT > & _popSelectOne, moeoArchive < MOEOT > & _arch, double _ratioFromPop=0.5)
: popSelectOne(_popSelectOne), archSelectOne(randomSelectOne), arch(_arch), ratioFromPop(_ratioFromPop) : popSelectOne(_popSelectOne), archSelectOne(randomSelectOne), arch(_arch), ratioFromPop(_ratioFromPop)
{} {}
@ -80,13 +80,13 @@ public:
*/ */
virtual const MOEOT & operator () (const eoPop < MOEOT > & pop) virtual const MOEOT & operator () (const eoPop < MOEOT > & pop)
{ {
if (arch.size() > 0) if (arch.size() > 0)
if (rng.flip(ratioFromPop)) if (rng.flip(ratioFromPop))
return popSelectOne(pop); return popSelectOne(pop);
else
return archSelectOne(arch);
else else
return popSelectOne(pop); return archSelectOne(arch);
else
return popSelectOne(pop);
} }
@ -95,11 +95,11 @@ public:
*/ */
virtual void setup (const eoPop < MOEOT > & _pop) virtual void setup (const eoPop < MOEOT > & _pop)
{ {
popSelectOne.setup(_pop); popSelectOne.setup(_pop);
} }
private: private:
/** The population's selection operator */ /** The population's selection operator */
moeoSelectOne < MOEOT > & popSelectOne; moeoSelectOne < MOEOT > & popSelectOne;
@ -112,6 +112,6 @@ private:
/** A random selection operator (used as default for archSelectOne) */ /** A random selection operator (used as default for archSelectOne) */
moeoRandomSelect < MOEOT > randomSelectOne; moeoRandomSelect < MOEOT > randomSelectOne;
}; };
#endif /*MOEOSELECTONEFROMPOPANDARCH_H_*/ #endif /*MOEOSELECTONEFROMPOPANDARCH_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoSelectOne.h> * <moeoSelectOne.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 @@
* Selection strategy for multi-objective optimization that selects only one element from a whole population. * Selection strategy for multi-objective optimization that selects only one element from a whole population.
*/ */
template < class MOEOT > template < class MOEOT >
class moeoSelectOne : public eoSelectOne < MOEOT > {}; class moeoSelectOne : public eoSelectOne < MOEOT >
{};
#endif /*MOEOSELECTONE_H_*/ #endif /*MOEOSELECTONE_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoSelectors.h> * <moeoSelectors.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,71 +44,71 @@
template <class It,class MOEOT> template <class It,class MOEOT>
It mo_deterministic_tournament(It _begin, It _end, unsigned int _t_size,moeoComparator<MOEOT>& _comparator ,eoRng& _gen = rng) It mo_deterministic_tournament(It _begin, It _end, unsigned int _t_size,moeoComparator<MOEOT>& _comparator ,eoRng& _gen = rng)
{ {
It best = _begin + _gen.random(_end - _begin); It best = _begin + _gen.random(_end - _begin);
for (unsigned int i = 0; i < _t_size - 1; ++i) for (unsigned int i = 0; i < _t_size - 1; ++i)
{ {
It competitor = _begin + _gen.random(_end - _begin); It competitor = _begin + _gen.random(_end - _begin);
// compare the two individuals by using the comparator // compare the two individuals by using the comparator
if (_comparator(*best, *competitor)) if (_comparator(*best, *competitor))
// best "better" than competitor // best "better" than competitor
best=competitor; best=competitor;
} }
return best; return best;
} }
template <class MOEOT> template <class MOEOT>
const MOEOT& mo_deterministic_tournament(const eoPop<MOEOT>& _pop, unsigned int _t_size,moeoComparator<MOEOT>& _comparator, eoRng& _gen = rng) const MOEOT& mo_deterministic_tournament(const eoPop<MOEOT>& _pop, unsigned int _t_size,moeoComparator<MOEOT>& _comparator, eoRng& _gen = rng)
{ {
return *mo_deterministic_tournament(_pop.begin(), _pop.end(),_t_size,_comparator, _gen); return *mo_deterministic_tournament(_pop.begin(), _pop.end(),_t_size,_comparator, _gen);
} }
template <class MOEOT> template <class MOEOT>
MOEOT& mo_deterministic_tournament(eoPop<MOEOT>& _pop, unsigned int _t_size,moeoComparator<MOEOT>& _comparator,eoRng& _gen = rng) MOEOT& mo_deterministic_tournament(eoPop<MOEOT>& _pop, unsigned int _t_size,moeoComparator<MOEOT>& _comparator,eoRng& _gen = rng)
{ {
return *mo_deterministic_tournament(_pop.begin(), _pop.end(), _t_size,_comparator, _gen); return *mo_deterministic_tournament(_pop.begin(), _pop.end(), _t_size,_comparator, _gen);
} }
template <class It,class MOEOT> template <class It,class MOEOT>
It mo_stochastic_tournament(It _begin, It _end, double _t_rate,moeoComparator<MOEOT>& _comparator ,eoRng& _gen = rng) It mo_stochastic_tournament(It _begin, It _end, double _t_rate,moeoComparator<MOEOT>& _comparator ,eoRng& _gen = rng)
{ {
It i1 = _begin + _gen.random(_end - _begin); It i1 = _begin + _gen.random(_end - _begin);
It i2 = _begin + _gen.random(_end - _begin); It i2 = _begin + _gen.random(_end - _begin);
bool return_better = _gen.flip(_t_rate); bool return_better = _gen.flip(_t_rate);
if (_comparator(*i1, *i2)) if (_comparator(*i1, *i2))
{ {
if (return_better) return i2; if (return_better) return i2;
// else // else
return i1; return i1;
} }
else else
{ {
if (return_better) return i1; if (return_better) return i1;
// else // else
} }
// else // else
return i2; return i2;
} }
template <class MOEOT> template <class MOEOT>
const MOEOT& mo_stochastic_tournament(const eoPop<MOEOT>& _pop, double _t_rate,moeoComparator<MOEOT>& _comparator, eoRng& _gen = rng) const MOEOT& mo_stochastic_tournament(const eoPop<MOEOT>& _pop, double _t_rate,moeoComparator<MOEOT>& _comparator, eoRng& _gen = rng)
{ {
return *mo_stochastic_tournament(_pop.begin(), _pop.end(), _t_rate,_comparator, _gen); return *mo_stochastic_tournament(_pop.begin(), _pop.end(), _t_rate,_comparator, _gen);
} }
template <class MOEOT> template <class MOEOT>
MOEOT& mo_stochastic_tournament(eoPop<MOEOT>& _pop, double _t_rate, eoRng& _gen = rng) MOEOT& mo_stochastic_tournament(eoPop<MOEOT>& _pop, double _t_rate, eoRng& _gen = rng)
{ {
return *mo_stochastic_tournament(_pop.begin(), _pop.end(), _t_rate, _gen); return *mo_stochastic_tournament(_pop.begin(), _pop.end(), _t_rate, _gen);
} }
@ -116,58 +116,58 @@ template <class It>
It mo_roulette_wheel(It _begin, It _end, double total, eoRng& _gen = rng) It mo_roulette_wheel(It _begin, It _end, double total, eoRng& _gen = rng)
{ {
float roulette = _gen.uniform(total); float roulette = _gen.uniform(total);
if (roulette == 0.0) // covers the case where total==0.0 if (roulette == 0.0) // covers the case where total==0.0
return _begin + _gen.random(_end - _begin); // uniform choice return _begin + _gen.random(_end - _begin); // uniform choice
It i = _begin; It i = _begin;
while (roulette > 0.0) while (roulette > 0.0)
{ {
roulette -= static_cast<double>(*(i++)); roulette -= static_cast<double>(*(i++));
} }
return --i; return --i;
} }
template <class MOEOT> template <class MOEOT>
const MOEOT& mo_roulette_wheel(const eoPop<MOEOT>& _pop, double total, eoRng& _gen = rng) const MOEOT& mo_roulette_wheel(const eoPop<MOEOT>& _pop, double total, eoRng& _gen = rng)
{ {
float roulette = _gen.uniform(total); float roulette = _gen.uniform(total);
if (roulette == 0.0) // covers the case where total==0.0 if (roulette == 0.0) // covers the case where total==0.0
return _pop[_gen.random(_pop.size())]; // uniform choice return _pop[_gen.random(_pop.size())]; // uniform choice
typename eoPop<MOEOT>::const_iterator i = _pop.begin(); typename eoPop<MOEOT>::const_iterator i = _pop.begin();
while (roulette > 0.0) while (roulette > 0.0)
{ {
roulette -= static_cast<double>((i++)->fitness()); roulette -= static_cast<double>((i++)->fitness());
} }
return *--i; return *--i;
} }
template <class MOEOT> template <class MOEOT>
MOEOT& mo_roulette_wheel(eoPop<MOEOT>& _pop, double total, eoRng& _gen = rng) MOEOT& mo_roulette_wheel(eoPop<MOEOT>& _pop, double total, eoRng& _gen = rng)
{ {
float roulette = _gen.uniform(total); float roulette = _gen.uniform(total);
if (roulette == 0.0) // covers the case where total==0.0 if (roulette == 0.0) // covers the case where total==0.0
return _pop[_gen.random(_pop.size())]; // uniform choice return _pop[_gen.random(_pop.size())]; // uniform choice
typename eoPop<MOEOT>::iterator i = _pop.begin(); typename eoPop<MOEOT>::iterator i = _pop.begin();
while (roulette > 0.0) while (roulette > 0.0)
{ {
// fitness only // fitness only
roulette -= static_cast<double>((i++)->fitness()); roulette -= static_cast<double>((i++)->fitness());
} }
return *--i; return *--i;
} }

View file

@ -1,4 +1,4 @@
/* /*
* <moeoStochTournamentSelect.h> * <moeoStochTournamentSelect.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 @@
* Selection strategy that selects ONE individual by stochastic tournament. * Selection strategy that selects ONE individual by stochastic tournament.
*/ */
template < class MOEOT > class moeoStochTournamentSelect:public moeoSelectOne <MOEOT> template < class MOEOT > class moeoStochTournamentSelect:public moeoSelectOne <MOEOT>
{ {
public: public:
/** /**
* Full Ctor * Full Ctor
@ -57,19 +57,19 @@ public:
*/ */
moeoStochTournamentSelect (moeoComparator < MOEOT > & _comparator, double _tRate = 1.0) : comparator (_comparator), tRate (_tRate) moeoStochTournamentSelect (moeoComparator < MOEOT > & _comparator, double _tRate = 1.0) : comparator (_comparator), tRate (_tRate)
{ {
// consistency checks // consistency checks
if (tRate < 0.5) if (tRate < 0.5)
{ {
std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n"; std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
tRate = 0.55; tRate = 0.55;
} }
if (tRate > 1) if (tRate > 1)
{ {
std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n"; std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
tRate = 1; tRate = 1;
} }
} }
/** /**
* Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default. * Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default.
@ -77,16 +77,16 @@ public:
*/ */
moeoStochTournamentSelect (double _tRate = 1.0) : comparator (defaultComparator), tRate (_tRate) moeoStochTournamentSelect (double _tRate = 1.0) : comparator (defaultComparator), tRate (_tRate)
{ {
// consistency checks // consistency checks
if (tRate < 0.5) if (tRate < 0.5)
{ {
std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n"; std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
tRate = 0.55; tRate = 0.55;
} }
if (tRate > 1) if (tRate > 1)
{ {
std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n"; std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
tRate = 1; tRate = 1;
} }
} }
@ -97,12 +97,12 @@ public:
*/ */
const MOEOT & operator() (const eoPop < MOEOT > &_pop) const MOEOT & operator() (const eoPop < MOEOT > &_pop)
{ {
// use the selector // use the selector
return mo_stochastic_tournament(_pop,tRate,comparator); return mo_stochastic_tournament(_pop,tRate,comparator);
} }
protected: protected:
/** the comparator (used to compare 2 individuals) */ /** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > & comparator; moeoComparator < MOEOT > & comparator;
@ -111,6 +111,6 @@ protected:
/** the tournament rate */ /** the tournament rate */
double tRate; double tRate;
}; };
#endif /*MOEOSTOCHTOURNAMENTSELECT_H_ */ #endif /*MOEOSTOCHTOURNAMENTSELECT_H_ */

View file

@ -1,4 +1,4 @@
/* /*
* <moeoArchiveObjectiveVectorSavingUpdater.h> * <moeoArchiveObjectiveVectorSavingUpdater.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 moeoArchiveObjectiveVectorSavingUpdater : public eoUpdater class moeoArchiveObjectiveVectorSavingUpdater : public eoUpdater
{ {
public: public:
/** /**
* Ctor * Ctor
@ -62,46 +62,47 @@ public:
* @param _id own ID * @param _id own ID
*/ */
moeoArchiveObjectiveVectorSavingUpdater (moeoArchive<MOEOT> & _arch, const std::string & _filename, bool _count = false, int _id = -1) : moeoArchiveObjectiveVectorSavingUpdater (moeoArchive<MOEOT> & _arch, const std::string & _filename, bool _count = false, int _id = -1) :
arch(_arch), filename(_filename), count(_count), counter(0), id(_id) arch(_arch), filename(_filename), count(_count), counter(0), id(_id)
{} {}
/** /**
* Saves the fitness of the archive's members into the file * Saves the fitness of the archive's members into the file
*/ */
void operator()() { void operator()()
char buff[MAX_BUFFER_SIZE]; {
if (count) char buff[MAX_BUFFER_SIZE];
if (count)
{ {
if (id == -1) if (id == -1)
{ {
sprintf (buff, "%s.%u", filename.c_str(), counter ++); sprintf (buff, "%s.%u", filename.c_str(), counter ++);
} }
else else
{ {
sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++); sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++);
} }
} }
else else
{ {
if (id == -1) if (id == -1)
{ {
sprintf (buff, "%s", filename.c_str()); sprintf (buff, "%s", filename.c_str());
} }
else else
{ {
sprintf (buff, "%s.%u", filename.c_str(), id); sprintf (buff, "%s.%u", filename.c_str(), id);
} }
counter ++; counter ++;
} }
std::ofstream f(buff); std::ofstream f(buff);
for (unsigned int i = 0; i < arch.size (); i++) for (unsigned int i = 0; i < arch.size (); i++)
f << arch[i].objectiveVector() << std::endl; f << arch[i].objectiveVector() << std::endl;
f.close (); f.close ();
} }
private: private:
/** local archive */ /** local archive */
moeoArchive<MOEOT> & arch; moeoArchive<MOEOT> & arch;
@ -114,6 +115,6 @@ private:
/** own ID */ /** own ID */
int id; int id;
}; };
#endif /*MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_*/ #endif /*MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoArchiveUpdater.h> * <moeoArchiveUpdater.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 moeoArchiveUpdater : public eoUpdater class moeoArchiveUpdater : public eoUpdater
{ {
public: public:
/** /**
* Ctor * Ctor
@ -62,18 +62,19 @@ public:
/** /**
* Updates the archive with newly found non-dominated solutions contained in the main population * Updates the archive with newly found non-dominated solutions contained in the main population
*/ */
void operator()() { void operator()()
arch.update(pop); {
arch.update(pop);
} }
private: private:
/** the archive of non-dominated solutions */ /** the archive of non-dominated solutions */
moeoArchive < MOEOT > & arch; moeoArchive < MOEOT > & arch;
/** the main population */ /** the main population */
const eoPop < MOEOT > & pop; const eoPop < MOEOT > & pop;
}; };
#endif /*MOEOARCHIVEUPDATER_H_*/ #endif /*MOEOARCHIVEUPDATER_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoBinaryMetricSavingUpdater.h> * <moeoBinaryMetricSavingUpdater.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 moeoBinaryMetricSavingUpdater : public eoUpdater class moeoBinaryMetricSavingUpdater : public eoUpdater
{ {
public: public:
/** The objective vector type of a solution */ /** The objective vector type of a solution */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -65,37 +65,41 @@ public:
* @param _filename the target filename * @param _filename the target filename
*/ */
moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & _metric, const eoPop < MOEOT > & _pop, std::string _filename) : moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & _metric, const eoPop < MOEOT > & _pop, std::string _filename) :
metric(_metric), pop(_pop), filename(_filename), counter(1) metric(_metric), pop(_pop), filename(_filename), counter(1)
{} {}
/** /**
* Saves the metric's value for the current generation * Saves the metric's value for the current generation
*/ */
void operator()() { void operator()()
if (pop.size()) { {
if (firstGen) { if (pop.size())
firstGen = false; {
if (firstGen)
{
firstGen = false;
} }
else { else
// creation of the two Pareto sets {
std::vector < ObjectiveVector > from; // creation of the two Pareto sets
std::vector < ObjectiveVector > to; std::vector < ObjectiveVector > from;
for (unsigned int i=0; i<pop.size(); i++) std::vector < ObjectiveVector > to;
from.push_back(pop[i].objectiveVector()); for (unsigned int i=0; i<pop.size(); i++)
for (unsigned int i=0 ; i<oldPop.size(); i++) from.push_back(pop[i].objectiveVector());
to.push_back(oldPop[i].objectiveVector()); for (unsigned int i=0 ; i<oldPop.size(); i++)
// writing the result into the file to.push_back(oldPop[i].objectiveVector());
std::ofstream f (filename.c_str(), std::ios::app); // writing the result into the file
f << counter++ << ' ' << metric(from,to) << std::endl; std::ofstream f (filename.c_str(), std::ios::app);
f.close(); f << counter++ << ' ' << metric(from,to) << std::endl;
f.close();
} }
oldPop = pop; oldPop = pop;
} }
} }
private: private:
/** binary metric comparing two Pareto sets */ /** binary metric comparing two Pareto sets */
moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & metric; moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & metric;
@ -110,6 +114,6 @@ private:
/** counter */ /** counter */
unsigned int counter; unsigned int counter;
}; };
#endif /*MOEOBINARYMETRICSAVINGUPDATER_H_*/ #endif /*MOEOBINARYMETRICSAVINGUPDATER_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <moeoConvertPopToObjectiveVectors.h> * <moeoConvertPopToObjectiveVectors.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,8 +46,8 @@
*/ */
template < class MOEOT, class ObjectiveVector = typename MOEOT::ObjectiveVector > template < class MOEOT, class ObjectiveVector = typename MOEOT::ObjectiveVector >
class moeoConvertPopToObjectiveVectors : public eoUF < const eoPop < MOEOT >, const std::vector < ObjectiveVector > > class moeoConvertPopToObjectiveVectors : public eoUF < const eoPop < MOEOT >, const std::vector < ObjectiveVector > >
{ {
public: public:
/** /**
* Returns a vector of the objective vectors from the population _pop * Returns a vector of the objective vectors from the population _pop
@ -55,15 +55,15 @@ public:
*/ */
const std::vector < ObjectiveVector > operator()(const eoPop < MOEOT > _pop) const std::vector < ObjectiveVector > operator()(const eoPop < MOEOT > _pop)
{ {
std::vector < ObjectiveVector > result; std::vector < ObjectiveVector > result;
result.resize(_pop.size()); result.resize(_pop.size());
for (unsigned int i=0; i<_pop.size(); i++) for (unsigned int i=0; i<_pop.size(); i++)
{ {
result.push_back(_pop[i].objectiveVector()); result.push_back(_pop[i].objectiveVector());
} }
return result; return result;
} }
}; };
#endif /*MOEOPOPTOOBJECTIVEVECTORS_H_*/ #endif /*MOEOPOPTOOBJECTIVEVECTORS_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <t-moeo.cpp> * <t-moeo.cpp>
* 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

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopEA.cpp> * <FlowShopEA.cpp>
* 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
@ -65,68 +65,68 @@ using namespace std;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
try try
{ {
eoParser parser(argc, argv); // for user-parameter reading eoParser parser(argc, argv); // for user-parameter reading
eoState state; // to keep all things allocated eoState state; // to keep all things allocated
/*** the representation-dependent things ***/ /*** the representation-dependent things ***/
// The fitness evaluation // The fitness evaluation
eoEvalFuncCounter<FlowShop>& eval = do_make_eval(parser, state); eoEvalFuncCounter<FlowShop>& eval = do_make_eval(parser, state);
// the genotype (through a genotype initializer) // the genotype (through a genotype initializer)
eoInit<FlowShop>& init = do_make_genotype(parser, state); eoInit<FlowShop>& init = do_make_genotype(parser, state);
// the variation operators // the variation operators
eoGenOp<FlowShop>& op = do_make_op(parser, state); eoGenOp<FlowShop>& op = do_make_op(parser, state);
/*** the representation-independent things ***/ /*** the representation-independent things ***/
// initialization of the population // initialization of the population
eoPop<FlowShop>& pop = do_make_pop(parser, state, init); eoPop<FlowShop>& pop = do_make_pop(parser, state, init);
// definition of the archive // definition of the archive
moeoArchive<FlowShop> arch; moeoArchive<FlowShop> arch;
// stopping criteria // stopping criteria
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval); eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
// output // output
eoCheckPoint<FlowShop>& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch); eoCheckPoint<FlowShop>& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch);
// algorithm // algorithm
eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch); eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch);
/*** Go ! ***/ /*** Go ! ***/
// help ? // help ?
make_help(parser); make_help(parser);
// first evalution // first evalution
apply<FlowShop>(eval, pop); apply<FlowShop>(eval, pop);
// printing of the initial population // printing of the initial population
cout << "Initial Population\n"; cout << "Initial Population\n";
pop.sortedPrintOn(cout); pop.sortedPrintOn(cout);
cout << endl; cout << endl;
// run the algo // run the algo
do_run(algo, pop); do_run(algo, pop);
// printing of the final population // printing of the final population
cout << "Final Population\n"; cout << "Final Population\n";
pop.sortedPrintOn(cout); pop.sortedPrintOn(cout);
cout << endl; cout << endl;
// printing of the final archive // printing of the final archive
cout << "Final Archive\n"; cout << "Final Archive\n";
arch.sortedPrintOn(cout); arch.sortedPrintOn(cout);
cout << endl; cout << endl;
} }
catch (exception& e) catch (exception& e)
{ {
cout << e.what() << endl; cout << e.what() << endl;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -1,4 +1,4 @@
/* /*
* <Sch1.cpp> * <Sch1.cpp>
* 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,21 +44,21 @@ using namespace std;
// the moeoObjectiveVectorTraits : minimizing 2 objectives // the moeoObjectiveVectorTraits : minimizing 2 objectives
class Sch1ObjectiveVectorTraits : public moeoObjectiveVectorTraits class Sch1ObjectiveVectorTraits : public moeoObjectiveVectorTraits
{ {
public: public:
static bool minimizing (int i) static bool minimizing (int i)
{ {
return true; return true;
} }
static bool maximizing (int i) static bool maximizing (int i)
{ {
return false; return false;
} }
static unsigned int nObjectives () static unsigned int nObjectives ()
{ {
return 2; return 2;
} }
}; };
// objective vector of real values // objective vector of real values
@ -67,66 +67,67 @@ typedef moeoRealObjectiveVector < Sch1ObjectiveVectorTraits > Sch1ObjectiveVecto
// multi-objective evolving object for the Sch1 problem // multi-objective evolving object for the Sch1 problem
class Sch1 : public moeoRealVector < Sch1ObjectiveVector, double, double > class Sch1 : public moeoRealVector < Sch1ObjectiveVector, double, double >
{ {
public: public:
Sch1() : moeoRealVector < Sch1ObjectiveVector, double, double > (1) {} Sch1() : moeoRealVector < Sch1ObjectiveVector, double, double > (1)
}; {}
};
// evaluation of objective functions // evaluation of objective functions
class Sch1Eval : public moeoEvalFunc < Sch1 > class Sch1Eval : public moeoEvalFunc < Sch1 >
{ {
public: public:
void operator () (Sch1 & _sch1) void operator () (Sch1 & _sch1)
{ {
if (_sch1.invalidObjectiveVector()) if (_sch1.invalidObjectiveVector())
{ {
Sch1ObjectiveVector objVec; Sch1ObjectiveVector objVec;
double x = _sch1[0]; double x = _sch1[0];
objVec[0] = x * x; objVec[0] = x * x;
objVec[1] = (x - 2.0) * (x - 2.0); objVec[1] = (x - 2.0) * (x - 2.0);
_sch1.objectiveVector(objVec); _sch1.objectiveVector(objVec);
} }
} }
}; };
// main // main
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
// parameters // parameters
unsigned int POP_SIZE = 20; unsigned int POP_SIZE = 20;
unsigned int MAX_GEN = 100; unsigned int MAX_GEN = 100;
double M_EPSILON = 0.01; double M_EPSILON = 0.01;
double P_CROSS = 0.25; double P_CROSS = 0.25;
double P_MUT = 0.35; double P_MUT = 0.35;
// objective functions evaluation // objective functions evaluation
Sch1Eval eval; Sch1Eval eval;
// crossover and mutation // crossover and mutation
eoQuadCloneOp < Sch1 > xover; eoQuadCloneOp < Sch1 > xover;
eoUniformMutation < Sch1 > mutation (M_EPSILON); eoUniformMutation < Sch1 > mutation (M_EPSILON);
// generate initial population // generate initial population
eoRealVectorBounds bounds (1, 0.0, 2.0); // [0, 2] eoRealVectorBounds bounds (1, 0.0, 2.0); // [0, 2]
eoRealInitBounded < Sch1 > init (bounds); eoRealInitBounded < Sch1 > init (bounds);
eoPop < Sch1 > pop (POP_SIZE, init); eoPop < Sch1 > pop (POP_SIZE, init);
// build NSGA-II // build NSGA-II
moeoNSGAII < Sch1 > nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT); moeoNSGAII < Sch1 > nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT);
// run the algo // run the algo
nsgaII (pop); nsgaII (pop);
// extract first front of the final population using an moeoArchive (this is the output of nsgaII) // extract first front of the final population using an moeoArchive (this is the output of nsgaII)
moeoArchive < Sch1 > arch; moeoArchive < Sch1 > arch;
arch.update (pop); arch.update (pop);
// printing of the final archive // printing of the final archive
cout << "Final Archive" << endl; cout << "Final Archive" << endl;
arch.sortedPrintOn (cout); arch.sortedPrintOn (cout);
cout << endl; cout << endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShop.cpp> * <FlowShop.cpp>
* 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
@ -38,6 +38,6 @@
#include <FlowShop.h> #include <FlowShop.h>
std::string FlowShop::className() const std::string FlowShop::className() const
{ {
return "FlowShop"; return "FlowShop";
} }

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShop.h> * <FlowShop.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,14 +45,14 @@
* Structure of the genotype for the flow-shop scheduling problem: a vector of unsigned int int. * Structure of the genotype for the flow-shop scheduling problem: a vector of unsigned int int.
*/ */
class FlowShop: public moeoVector < FlowShopObjectiveVector , double , double , unsigned int > class FlowShop: public moeoVector < FlowShopObjectiveVector , double , double , unsigned int >
{ {
public: public:
/** /**
* class name * class name
*/ */
std::string className() const; std::string className() const;
}; };
#endif /*FLOWSHOP_H_*/ #endif /*FLOWSHOP_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopBenchmarkParser.cpp> * <FlowShopBenchmarkParser.cpp>
* 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
@ -40,87 +40,92 @@
FlowShopBenchmarkParser::FlowShopBenchmarkParser(const std::string _benchmarkFileName) FlowShopBenchmarkParser::FlowShopBenchmarkParser(const std::string _benchmarkFileName)
{ {
init(_benchmarkFileName); init(_benchmarkFileName);
} }
const unsigned int FlowShopBenchmarkParser::getM() const unsigned int FlowShopBenchmarkParser::getM()
{ {
return M; return M;
} }
const unsigned int FlowShopBenchmarkParser::getN() const unsigned int FlowShopBenchmarkParser::getN()
{ {
return N; return N;
} }
const std::vector< std::vector<unsigned int> > FlowShopBenchmarkParser::getP() const std::vector< std::vector<unsigned int> > FlowShopBenchmarkParser::getP()
{ {
return p; return p;
} }
const std::vector<unsigned int> FlowShopBenchmarkParser::getD() const std::vector<unsigned int> FlowShopBenchmarkParser::getD()
{ {
return d; return d;
} }
void FlowShopBenchmarkParser::printOn(std::ostream & _os) const void FlowShopBenchmarkParser::printOn(std::ostream & _os) const
{ {
_os << "M=" << M << " N=" << N << std::endl; _os << "M=" << M << " N=" << N << std::endl;
_os << "*** processing times" << std::endl; _os << "*** processing times" << std::endl;
for (unsigned int i=0; i<M; i++) { for (unsigned int i=0; i<M; i++)
for (unsigned int j=0; j<N; j++) { {
for (unsigned int j=0; j<N; j++)
{
_os << p[i][j] << " "; _os << p[i][j] << " ";
} }
_os << std::endl; _os << std::endl;
} }
_os << "*** due-dates" << std::endl; _os << "*** due-dates" << std::endl;
for (unsigned int j=0; j<N; j++) { for (unsigned int j=0; j<N; j++)
{
_os << d[j] << " "; _os << d[j] << " ";
} }
_os << std::endl << std::endl; _os << std::endl << std::endl;
} }
void FlowShopBenchmarkParser::init(const std::string _benchmarkFileName) void FlowShopBenchmarkParser::init(const std::string _benchmarkFileName)
{ {
std::string buffer; std::string buffer;
std::string::size_type start, end; std::string::size_type start, end;
std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in); std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in);
// opening of the benchmark file // opening of the benchmark file
if (! inputFile) if (! inputFile)
throw std::runtime_error("*** ERROR : Unable to open the benchmark file"); throw std::runtime_error("*** ERROR : Unable to open the benchmark file");
// number of jobs (N) // number of jobs (N)
getline(inputFile, buffer, '\n'); getline(inputFile, buffer, '\n');
N = atoi(buffer.data()); N = atoi(buffer.data());
// number of machines M // number of machines M
getline(inputFile, buffer, '\n'); getline(inputFile, buffer, '\n');
M = atoi(buffer.data()); M = atoi(buffer.data());
// initial and current seeds (not used) // initial and current seeds (not used)
getline(inputFile, buffer, '\n'); getline(inputFile, buffer, '\n');
// processing times and due-dates // processing times and due-dates
p = std::vector< std::vector<unsigned int> > (M,N); p = std::vector< std::vector<unsigned int> > (M,N);
d = std::vector<unsigned int> (N); d = std::vector<unsigned int> (N);
// for each job... // for each job...
for (unsigned int j=0 ; j<N ; j++) { for (unsigned int j=0 ; j<N ; j++)
// index of the job (<=> j) {
getline(inputFile, buffer, '\n'); // index of the job (<=> j)
// due-date of the job j getline(inputFile, buffer, '\n');
getline(inputFile, buffer, '\n'); // due-date of the job j
d[j] = atoi(buffer.data()); getline(inputFile, buffer, '\n');
// processing times of the job j on each machine d[j] = atoi(buffer.data());
getline(inputFile, buffer, '\n'); // processing times of the job j on each machine
start = buffer.find_first_not_of(" "); getline(inputFile, buffer, '\n');
for (unsigned int i=0 ; i<M ; i++) { start = buffer.find_first_not_of(" ");
end = buffer.find_first_of(" ", start); for (unsigned int i=0 ; i<M ; i++)
p[i][j] = atoi(buffer.substr(start, end-start).data()); {
start = buffer.find_first_not_of(" ", end); end = buffer.find_first_of(" ", start);
p[i][j] = atoi(buffer.substr(start, end-start).data());
start = buffer.find_first_not_of(" ", end);
} }
} }
// closing of the input file // closing of the input file
inputFile.close(); inputFile.close();
} }

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopBenchmarkParser.h> * <FlowShopBenchmarkParser.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,8 +46,8 @@
* Class to handle parameters of a flow-shop instance from a benchmark file * Class to handle parameters of a flow-shop instance from a benchmark file
*/ */
class FlowShopBenchmarkParser class FlowShopBenchmarkParser
{ {
public: public:
/** /**
* Ctor * Ctor
@ -86,7 +86,7 @@ public:
void printOn(std::ostream & _os) const; void printOn(std::ostream & _os) const;
private: private:
/** number of machines */ /** number of machines */
unsigned int M; unsigned int M;
@ -104,6 +104,6 @@ private:
*/ */
void init(const std::string _benchmarkFileName); void init(const std::string _benchmarkFileName);
}; };
#endif /*FLOWSHOPBENCHMARKPARSER_H_*/ #endif /*FLOWSHOPBENCHMARKPARSER_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopEval.cpp> * <FlowShopEval.cpp>
* 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
@ -39,51 +39,52 @@
FlowShopEval::FlowShopEval(unsigned int _M, unsigned int _N, const std::vector< std::vector<unsigned int> > & _p, const std::vector<unsigned int> & _d) : FlowShopEval::FlowShopEval(unsigned int _M, unsigned int _N, const std::vector< std::vector<unsigned int> > & _p, const std::vector<unsigned int> & _d) :
M(_M), N (_N), p(_p), d(_d) M(_M), N (_N), p(_p), d(_d)
{} {}
void FlowShopEval::operator()(FlowShop & _flowshop) void FlowShopEval::operator()(FlowShop & _flowshop)
{ {
FlowShopObjectiveVector objVector; FlowShopObjectiveVector objVector;
objVector[0] = makespan(_flowshop); objVector[0] = makespan(_flowshop);
objVector[1] = tardiness(_flowshop); objVector[1] = tardiness(_flowshop);
_flowshop.objectiveVector(objVector); _flowshop.objectiveVector(objVector);
} }
double FlowShopEval::makespan(const FlowShop & _flowshop) double FlowShopEval::makespan(const FlowShop & _flowshop)
{ {
// completion times computation for each job on each machine // completion times computation for each job on each machine
// C[i][j] = completion of the jth job of the scheduling on the ith machine // C[i][j] = completion of the jth job of the scheduling on the ith machine
std::vector< std::vector<unsigned int> > C = completionTime(_flowshop); std::vector< std::vector<unsigned int> > C = completionTime(_flowshop);
return C[M-1][_flowshop[N-1]]; return C[M-1][_flowshop[N-1]];
} }
double FlowShopEval::tardiness(const FlowShop & _flowshop) double FlowShopEval::tardiness(const FlowShop & _flowshop)
{ {
// completion times computation for each job on each machine // completion times computation for each job on each machine
// C[i][j] = completion of the jth job of the scheduling on the ith machine // C[i][j] = completion of the jth job of the scheduling on the ith machine
std::vector< std::vector<unsigned int> > C = completionTime(_flowshop); std::vector< std::vector<unsigned int> > C = completionTime(_flowshop);
// tardiness computation // tardiness computation
unsigned int long sum = 0; unsigned int long sum = 0;
for (unsigned int j=0 ; j<N ; j++) for (unsigned int j=0 ; j<N ; j++)
sum += (unsigned int) std::max (0, (int) (C[M-1][_flowshop[j]] - d[_flowshop[j]])); sum += (unsigned int) std::max (0, (int) (C[M-1][_flowshop[j]] - d[_flowshop[j]]));
return sum; return sum;
} }
std::vector< std::vector<unsigned int> > FlowShopEval::completionTime(const FlowShop & _flowshop) { std::vector< std::vector<unsigned int> > FlowShopEval::completionTime(const FlowShop & _flowshop)
std::vector< std::vector<unsigned int> > C(M,N); {
C[0][_flowshop[0]] = p[0][_flowshop[0]]; std::vector< std::vector<unsigned int> > C(M,N);
C[0][_flowshop[0]] = p[0][_flowshop[0]];
for (unsigned int j=1; j<N; j++)
C[0][_flowshop[j]] = C[0][_flowshop[j-1]] + p[0][_flowshop[j]];
for (unsigned int i=1; i<M; i++)
C[i][_flowshop[0]] = C[i-1][_flowshop[0]] + p[i][_flowshop[0]];
for (unsigned int i=1; i<M; i++)
for (unsigned int j=1; j<N; j++) for (unsigned int j=1; j<N; j++)
C[0][_flowshop[j]] = C[0][_flowshop[j-1]] + p[0][_flowshop[j]]; C[i][_flowshop[j]] = std::max(C[i][_flowshop[j-1]], C[i-1][_flowshop[j]]) + p[i][_flowshop[j]];
for (unsigned int i=1; i<M; i++) return C;
C[i][_flowshop[0]] = C[i-1][_flowshop[0]] + p[i][_flowshop[0]];
for (unsigned int i=1; i<M; i++)
for (unsigned int j=1; j<N; j++)
C[i][_flowshop[j]] = std::max(C[i][_flowshop[j-1]], C[i-1][_flowshop[j]]) + p[i][_flowshop[j]];
return C;
} }

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopEval.h> * <FlowShopEval.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,8 +46,8 @@
* Evaluation of the objective vector a (multi-objective) FlowShop object * Evaluation of the objective vector a (multi-objective) FlowShop object
*/ */
class FlowShopEval : public moeoEvalFunc<FlowShop> class FlowShopEval : public moeoEvalFunc<FlowShop>
{ {
public: public:
/** /**
* Ctor * Ctor
@ -66,7 +66,7 @@ public:
void operator()(FlowShop & _flowshop); void operator()(FlowShop & _flowshop);
private: private:
/** number of machines */ /** number of machines */
unsigned int M; unsigned int M;
@ -99,6 +99,6 @@ private:
*/ */
std::vector< std::vector<unsigned int> > completionTime (const FlowShop & _flowshop); std::vector< std::vector<unsigned int> > completionTime (const FlowShop & _flowshop);
}; };
#endif /*FLOWSHOPEVAL_H_*/ #endif /*FLOWSHOPEVAL_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopInit.cpp> * <FlowShopInit.cpp>
* 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,21 +44,21 @@ FlowShopInit::FlowShopInit(unsigned int _N) : N(_N)
void FlowShopInit::operator()(FlowShop & _flowshop) void FlowShopInit::operator()(FlowShop & _flowshop)
{ {
// scheduling vector // scheduling vector
std::vector<unsigned int> scheduling(N); std::vector<unsigned int> scheduling(N);
// initialisation of possible values // initialisation of possible values
std::vector<unsigned int> possibles(N); std::vector<unsigned int> possibles(N);
for (unsigned int i=0 ; i<N ; i++) for (unsigned int i=0 ; i<N ; i++)
possibles[i] = i; possibles[i] = i;
// random initialization // random initialization
unsigned int rInd; // random index unsigned int rInd; // random index
for (unsigned int i=0; i<N; i++) for (unsigned int i=0; i<N; i++)
{ {
rInd = (unsigned int) rng.uniform(N-i); rInd = (unsigned int) rng.uniform(N-i);
scheduling[i] = possibles[rInd]; scheduling[i] = possibles[rInd];
possibles[rInd] = possibles[N-i-1]; possibles[rInd] = possibles[N-i-1];
} }
_flowshop.resize(N); _flowshop.resize(N);
_flowshop.value(scheduling); _flowshop.value(scheduling);
_flowshop.invalidate(); // IMPORTANT in case the _genotype is old _flowshop.invalidate(); // IMPORTANT in case the _genotype is old
} }

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopInit.h> * <FlowShopInit.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 @@
* Initialization of a random genotype built by the default constructor of the FlowShop class * Initialization of a random genotype built by the default constructor of the FlowShop class
*/ */
class FlowShopInit : public eoInit<FlowShop> class FlowShopInit : public eoInit<FlowShop>
{ {
public: public:
/** /**
* Ctor * Ctor
@ -62,11 +62,11 @@ public:
void operator()(FlowShop & _flowshop); void operator()(FlowShop & _flowshop);
private: private:
/** the number of jobs (size of a scheduling vector) */ /** the number of jobs (size of a scheduling vector) */
unsigned int N; unsigned int N;
}; };
#endif /*FLOWSHOPINIT_H_*/ #endif /*FLOWSHOPINIT_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopObjectiveVector.h> * <FlowShopObjectiveVector.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

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopObjectiveVectorTraits.cpp> * <FlowShopObjectiveVectorTraits.cpp>
* 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
@ -40,18 +40,18 @@
bool FlowShopObjectiveVectorTraits::minimizing (int _i) bool FlowShopObjectiveVectorTraits::minimizing (int _i)
{ {
// minimizing both // minimizing both
return true; return true;
} }
bool FlowShopObjectiveVectorTraits::maximizing (int _i) bool FlowShopObjectiveVectorTraits::maximizing (int _i)
{ {
// minimizing both // minimizing both
return false; return false;
} }
unsigned int FlowShopObjectiveVectorTraits::nObjectives () unsigned int FlowShopObjectiveVectorTraits::nObjectives ()
{ {
// 2 objectives // 2 objectives
return 2; return 2;
} }

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopObjectiveVectorTraits.h> * <FlowShopObjectiveVectorTraits.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,8 +44,8 @@
* Definition of the objective vector traits for multi-objective flow-shop problems * Definition of the objective vector traits for multi-objective flow-shop problems
*/ */
class FlowShopObjectiveVectorTraits : public moeoObjectiveVectorTraits class FlowShopObjectiveVectorTraits : public moeoObjectiveVectorTraits
{ {
public: public:
/** /**
* Returns true if the _ith objective have to be minimzed * Returns true if the _ith objective have to be minimzed
@ -66,6 +66,6 @@ public:
*/ */
static unsigned int nObjectives (); static unsigned int nObjectives ();
}; };
#endif /*FLOWSHOPOBJECTIVEVECTORTRAITS_H_*/ #endif /*FLOWSHOPOBJECTIVEVECTORTRAITS_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopOpCrossoverQuad.cpp> * <FlowShopOpCrossoverQuad.cpp>
* 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
@ -39,71 +39,72 @@
std::string FlowShopOpCrossoverQuad::className() const std::string FlowShopOpCrossoverQuad::className() const
{ {
return "FlowShopOpCrossoverQuad"; return "FlowShopOpCrossoverQuad";
} }
bool FlowShopOpCrossoverQuad::operator()(FlowShop & _flowshop1, FlowShop & _flowshop2) bool FlowShopOpCrossoverQuad::operator()(FlowShop & _flowshop1, FlowShop & _flowshop2)
{ {
bool oneAtLeastIsModified; bool oneAtLeastIsModified;
// computation of the 2 random points // computation of the 2 random points
unsigned int point1, point2; unsigned int point1, point2;
do do
{ {
point1 = rng.random(std::min(_flowshop1.size(), _flowshop2.size())); point1 = rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
point2 = rng.random(std::min(_flowshop1.size(), _flowshop2.size())); point2 = rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
} while (fabs((double) point1-point2) <= 2);
// computation of the offspring
FlowShop offspring1 = generateOffspring(_flowshop1, _flowshop2, point1, point2);
FlowShop offspring2 = generateOffspring(_flowshop2, _flowshop1, point1, point2);
// does at least one genotype has been modified ?
if ((_flowshop1 != offspring1) || (_flowshop2 != offspring2))
{
// update
_flowshop1.value(offspring1);
_flowshop2.value(offspring2);
// at least one genotype has been modified
oneAtLeastIsModified = true;
} }
else while (fabs((double) point1-point2) <= 2);
// computation of the offspring
FlowShop offspring1 = generateOffspring(_flowshop1, _flowshop2, point1, point2);
FlowShop offspring2 = generateOffspring(_flowshop2, _flowshop1, point1, point2);
// does at least one genotype has been modified ?
if ((_flowshop1 != offspring1) || (_flowshop2 != offspring2))
{ {
// no genotype has been modified // update
oneAtLeastIsModified = false; _flowshop1.value(offspring1);
_flowshop2.value(offspring2);
// at least one genotype has been modified
oneAtLeastIsModified = true;
} }
// return 'true' if at least one genotype has been modified else
return oneAtLeastIsModified; {
// no genotype has been modified
oneAtLeastIsModified = false;
}
// return 'true' if at least one genotype has been modified
return oneAtLeastIsModified;
} }
FlowShop FlowShopOpCrossoverQuad::generateOffspring(const FlowShop & _parent1, const FlowShop & _parent2, unsigned int _point1, unsigned int _point2) FlowShop FlowShopOpCrossoverQuad::generateOffspring(const FlowShop & _parent1, const FlowShop & _parent2, unsigned int _point1, unsigned int _point2)
{ {
FlowShop result = _parent1; FlowShop result = _parent1;
std::vector<bool> taken_values(result.size(), false); std::vector<bool> taken_values(result.size(), false);
if (_point1 > _point2) if (_point1 > _point2)
std::swap(_point1, _point2); std::swap(_point1, _point2);
/* first parent */ /* first parent */
for (unsigned int i=0 ; i<=_point1 ; i++) for (unsigned int i=0 ; i<=_point1 ; i++)
{ {
// result[i] == _parent1[i] // result[i] == _parent1[i]
taken_values[_parent1[i]] = true; taken_values[_parent1[i]] = true;
} }
for (unsigned int i=_point2 ; i<result.size() ; i++) for (unsigned int i=_point2 ; i<result.size() ; i++)
{ {
// result[i] == _parent1[i] // result[i] == _parent1[i]
taken_values[_parent1[i]] = true; taken_values[_parent1[i]] = true;
} }
/* second parent */ /* second parent */
unsigned int i = _point1+1; unsigned int i = _point1+1;
unsigned int j = 0; unsigned int j = 0;
while (i<_point2 && j<_parent2.size()) while (i<_point2 && j<_parent2.size())
{ {
if (! taken_values[_parent2[j]]) if (! taken_values[_parent2[j]])
{ {
result[i] = _parent2[j]; result[i] = _parent2[j];
i++; i++;
} }
j++; j++;
} }
return result; return result;
} }

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopOpCrossoverQuad.h> * <FlowShopOpCrossoverQuad.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 @@
* Quadratic crossover operator for flow-shop (modify the both genotypes) * Quadratic crossover operator for flow-shop (modify the both genotypes)
*/ */
class FlowShopOpCrossoverQuad : public eoQuadOp < FlowShop > class FlowShopOpCrossoverQuad : public eoQuadOp < FlowShop >
{ {
public: public:
/** /**
* the class name (used to display statistics) * the class name (used to display statistics)
@ -62,7 +62,7 @@ public:
bool operator()(FlowShop & _flowshop1, FlowShop & _flowshop2); bool operator()(FlowShop & _flowshop1, FlowShop & _flowshop2);
private: private:
/** /**
* generation of an offspring by a 2 points crossover * generation of an offspring by a 2 points crossover
@ -73,6 +73,6 @@ private:
*/ */
FlowShop generateOffspring(const FlowShop & _parent1, const FlowShop & _parent2, unsigned int _point1, unsigned int _point2); FlowShop generateOffspring(const FlowShop & _parent1, const FlowShop & _parent2, unsigned int _point1, unsigned int _point2);
}; };
#endif /*FLOWSHOPOPCROSSOVERQUAD_H_*/ #endif /*FLOWSHOPOPCROSSOVERQUAD_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopOpMutationExchange.cpp> * <FlowShopOpMutationExchange.cpp>
* 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
@ -39,37 +39,38 @@
std::string FlowShopOpMutationExchange::className() const std::string FlowShopOpMutationExchange::className() const
{ {
return "FlowShopOpMutationExchange"; return "FlowShopOpMutationExchange";
} }
bool FlowShopOpMutationExchange::operator()(FlowShop & _flowshop) bool FlowShopOpMutationExchange::operator()(FlowShop & _flowshop)
{ {
bool isModified; bool isModified;
FlowShop result = _flowshop; FlowShop result = _flowshop;
// computation of the 2 random points // computation of the 2 random points
unsigned int point1, point2; unsigned int point1, point2;
do do
{ {
point1 = rng.random(result.size()); point1 = rng.random(result.size());
point2 = rng.random(result.size()); point2 = rng.random(result.size());
} while (point1 == point2);
// swap
std::swap (result[point1], result[point2]);
// update (if necessary)
if (result != _flowshop)
{
// update
_flowshop.value(result);
// the genotype has been modified
isModified = true;
} }
else while (point1 == point2);
// swap
std::swap (result[point1], result[point2]);
// update (if necessary)
if (result != _flowshop)
{ {
// the genotype has not been modified // update
isModified = false; _flowshop.value(result);
// the genotype has been modified
isModified = true;
} }
// return 'true' if the genotype has been modified else
return isModified; {
// the genotype has not been modified
isModified = false;
}
// return 'true' if the genotype has been modified
return isModified;
} }

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopOpMutationExchange.h> * <FlowShopOpMutationExchange.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 @@
* Exchange mutation operator for the flow-shop * Exchange mutation operator for the flow-shop
*/ */
class FlowShopOpMutationExchange : public eoMonOp<FlowShop> class FlowShopOpMutationExchange : public eoMonOp<FlowShop>
{ {
public: public:
/** /**
* the class name (used to display statistics) * the class name (used to display statistics)
@ -60,6 +60,6 @@ public:
*/ */
bool operator()(FlowShop & _flowshop); bool operator()(FlowShop & _flowshop);
}; };
#endif /*FLOWSHOPOPMUTATIONEXCHANGE_H_*/ #endif /*FLOWSHOPOPMUTATIONEXCHANGE_H_*/

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopOpMutationShift.cpp> * <FlowShopOpMutationShift.cpp>
* 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
@ -39,47 +39,48 @@
std::string FlowShopOpMutationShift::className() const std::string FlowShopOpMutationShift::className() const
{ {
return "FlowShopOpMutationShift"; return "FlowShopOpMutationShift";
} }
bool FlowShopOpMutationShift::operator()(FlowShop & _flowshop) bool FlowShopOpMutationShift::operator()(FlowShop & _flowshop)
{ {
bool isModified; bool isModified;
int direction; int direction;
unsigned int tmp; unsigned int tmp;
FlowShop result = _flowshop; FlowShop result = _flowshop;
// computation of the 2 random points // computation of the 2 random points
unsigned int point1, point2; unsigned int point1, point2;
do do
{ {
point1 = rng.random(result.size()); point1 = rng.random(result.size());
point2 = rng.random(result.size()); point2 = rng.random(result.size());
} while (point1 == point2);
// direction
if (point1 < point2)
direction = 1;
else
direction = -1;
// mutation
tmp = result[point1];
for (unsigned int i=point1 ; i!=point2 ; i+=direction)
result[i] = result[i+direction];
result[point2] = tmp;
// update (if necessary)
if (result != _flowshop)
{
// update
_flowshop.value(result);
// the genotype has been modified
isModified = true;
} }
else while (point1 == point2);
// direction
if (point1 < point2)
direction = 1;
else
direction = -1;
// mutation
tmp = result[point1];
for (unsigned int i=point1 ; i!=point2 ; i+=direction)
result[i] = result[i+direction];
result[point2] = tmp;
// update (if necessary)
if (result != _flowshop)
{ {
// the genotype has not been modified // update
isModified = false; _flowshop.value(result);
// the genotype has been modified
isModified = true;
} }
// return 'true' if the genotype has been modified else
return isModified; {
// the genotype has not been modified
isModified = false;
}
// return 'true' if the genotype has been modified
return isModified;
} }

View file

@ -1,4 +1,4 @@
/* /*
* <FlowShopOpMutationShift.h> * <FlowShopOpMutationShift.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 @@
* Shift mutation operator for flow-shop * Shift mutation operator for flow-shop
*/ */
class FlowShopOpMutationShift : public eoMonOp < FlowShop > class FlowShopOpMutationShift : public eoMonOp < FlowShop >
{ {
public: public:
/** /**
* the class name (used to display statistics) * the class name (used to display statistics)
@ -60,6 +60,6 @@ public:
*/ */
bool operator()(FlowShop & _flowshop); bool operator()(FlowShop & _flowshop);
}; };
#endif /*FLOWSHOPOPMUTATIONSHIFT_H_*/ #endif /*FLOWSHOPOPMUTATIONSHIFT_H_*/

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