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:
parent
7161febf9c
commit
39709d3d12
103 changed files with 2607 additions and 2521 deletions
|
|
@ -3,11 +3,11 @@
|
|||
@section Introduction
|
||||
|
||||
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.
|
||||
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.
|
||||
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).
|
||||
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.
|
||||
|
|
@ -29,7 +29,7 @@ href="../../README">README</a> file in the top-directory of the source-tree.
|
|||
|
||||
@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>.
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoAlgo.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,6 +41,7 @@
|
|||
/**
|
||||
* Abstract class for multi-objective algorithms.
|
||||
*/
|
||||
class moeoAlgo {};
|
||||
class moeoAlgo
|
||||
{};
|
||||
|
||||
#endif /*MOEOALGO_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoCombinedLS.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -48,8 +48,8 @@
|
|||
*/
|
||||
template < class MOEOT, class Type >
|
||||
class moeoCombinedLS : public moeoLS < MOEOT, Type >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
|
|
@ -57,7 +57,7 @@ public:
|
|||
*/
|
||||
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
|
||||
*/
|
||||
void add(moeoLS < MOEOT, Type > & _mols)
|
||||
{
|
||||
{
|
||||
combinedLS.push_back(& _mols);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives a new solution in order to explore the neigborhood.
|
||||
|
|
@ -77,16 +77,16 @@ public:
|
|||
*/
|
||||
void operator () (Type _type, moeoArchive < MOEOT > & _arch)
|
||||
{
|
||||
for (unsigned int i=0; i<combinedLS.size(); i++)
|
||||
combinedLS[i] -> operator()(_type, _arch);
|
||||
for (unsigned int i=0; i<combinedLS.size(); i++)
|
||||
combinedLS[i] -> operator()(_type, _arch);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the vector that contains the combined LS */
|
||||
std::vector< moeoLS < MOEOT, Type > * > combinedLS;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOCOMBINEDLS_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoEA.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,6 +45,7 @@
|
|||
* Abstract class for multi-objective evolutionary algorithms.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoEA : public moeoAlgo, public eoAlgo < MOEOT > {};
|
||||
class moeoEA : public moeoAlgo, public eoAlgo < MOEOT >
|
||||
{};
|
||||
|
||||
#endif /*MOEOEA_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoEasyEA.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -56,8 +56,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoEasyEA: public moeoEA < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor taking a breed and merge.
|
||||
|
|
@ -71,9 +71,9 @@ public:
|
|||
*/
|
||||
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace,
|
||||
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),
|
||||
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
|
||||
:
|
||||
continuator(_continuator), eval (_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
|
||||
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -89,9 +89,9 @@ public:
|
|||
*/
|
||||
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace,
|
||||
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),
|
||||
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
|
||||
:
|
||||
continuator(_continuator), eval (dummyEval), loopEval(dummyEval), popEval(_popEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
|
||||
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,
|
||||
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),
|
||||
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
|
||||
:
|
||||
continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(_merge,_reduce), replace(mergeReduce),
|
||||
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,
|
||||
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),
|
||||
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
|
||||
:
|
||||
continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
|
||||
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,
|
||||
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),
|
||||
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
|
||||
:
|
||||
continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(_merge,_reduce), replace(mergeReduce),
|
||||
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -159,45 +159,46 @@ public:
|
|||
*/
|
||||
virtual void operator()(eoPop < MOEOT > & _pop)
|
||||
{
|
||||
eoPop < MOEOT > offspring, empty_pop;
|
||||
popEval(empty_pop, _pop); // A first eval of pop.
|
||||
bool firstTime = true;
|
||||
do
|
||||
eoPop < MOEOT > offspring, empty_pop;
|
||||
popEval(empty_pop, _pop); // A first eval of pop.
|
||||
bool firstTime = true;
|
||||
do
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
unsigned int pSize = _pop.size();
|
||||
offspring.clear(); // new offspring
|
||||
// fitness and diversity assignment (if you want to or if it is the first generation)
|
||||
if (evalFitAndDivBeforeSelection || firstTime)
|
||||
unsigned int pSize = _pop.size();
|
||||
offspring.clear(); // new offspring
|
||||
// fitness and diversity assignment (if you want to or if it is the first generation)
|
||||
if (evalFitAndDivBeforeSelection || firstTime)
|
||||
{
|
||||
firstTime = false;
|
||||
fitnessEval(_pop);
|
||||
diversityEval(_pop);
|
||||
firstTime = false;
|
||||
fitnessEval(_pop);
|
||||
diversityEval(_pop);
|
||||
}
|
||||
breed(_pop, offspring);
|
||||
popEval(_pop, offspring); // eval of parents + offspring if necessary
|
||||
replace(_pop, offspring); // after replace, the new pop. is in _pop
|
||||
if (pSize > _pop.size())
|
||||
breed(_pop, offspring);
|
||||
popEval(_pop, offspring); // eval of parents + offspring if necessary
|
||||
replace(_pop, offspring); // after replace, the new pop. is in _pop
|
||||
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();
|
||||
s.append( " in moeoEasyEA");
|
||||
throw std::runtime_error( s );
|
||||
std::string s = e.what();
|
||||
s.append( " in moeoEasyEA");
|
||||
throw std::runtime_error( s );
|
||||
}
|
||||
} while (continuator(_pop));
|
||||
}
|
||||
while (continuator(_pop));
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** the stopping criteria */
|
||||
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 */
|
||||
bool evalFitAndDivBeforeSelection;
|
||||
/** a dummy eval */
|
||||
class eoDummyEval : public eoEvalFunc < MOEOT >
|
||||
{ public: /** the dummy functor */
|
||||
void operator()(MOEOT &) {}} dummyEval;
|
||||
class eoDummyEval : public eoEvalFunc < MOEOT >
|
||||
{
|
||||
public: /** the dummy functor */
|
||||
void operator()(MOEOT &)
|
||||
{}
|
||||
}
|
||||
dummyEval;
|
||||
/** a dummy select */
|
||||
class eoDummySelect : public eoSelect < MOEOT >
|
||||
{ public: /** the dummy functor */
|
||||
void operator()(const eoPop < MOEOT > &, eoPop < MOEOT > &) {} } dummySelect;
|
||||
class eoDummySelect : public eoSelect < MOEOT >
|
||||
{
|
||||
public: /** the dummy functor */
|
||||
void operator()(const eoPop < MOEOT > &, eoPop < MOEOT > &)
|
||||
{}
|
||||
}
|
||||
dummySelect;
|
||||
/** a dummy transform */
|
||||
class eoDummyTransform : public eoTransform < MOEOT >
|
||||
{ public: /** the dummy functor */
|
||||
void operator()(eoPop < MOEOT > &) {} } dummyTransform;
|
||||
class eoDummyTransform : public eoTransform < MOEOT >
|
||||
{
|
||||
public: /** the dummy functor */
|
||||
void operator()(eoPop < MOEOT > &)
|
||||
{}
|
||||
}
|
||||
dummyTransform;
|
||||
/** a dummy merge */
|
||||
eoNoElitism < MOEOT > dummyMerge;
|
||||
/** a dummy reduce */
|
||||
eoTruncate < MOEOT > dummyReduce;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOEASYEA_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoHybridLS.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -51,8 +51,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoHybridLS : public eoUpdater
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
|
|
@ -62,7 +62,7 @@ public:
|
|||
* @param _arch the archive
|
||||
*/
|
||||
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 () ()
|
||||
{
|
||||
if (! term (arch))
|
||||
if (! term (arch))
|
||||
{
|
||||
// selection of solutions
|
||||
eoPop < MOEOT > selectedSolutions;
|
||||
select(arch, selectedSolutions);
|
||||
// apply the local search to every selected solution
|
||||
for (unsigned int i=0; i<selectedSolutions.size(); i++)
|
||||
// selection of solutions
|
||||
eoPop < MOEOT > selectedSolutions;
|
||||
select(arch, selectedSolutions);
|
||||
// apply the local search to every selected solution
|
||||
for (unsigned int i=0; i<selectedSolutions.size(); i++)
|
||||
{
|
||||
mols(selectedSolutions[i], arch);
|
||||
mols(selectedSolutions[i], arch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** stopping criteria */
|
||||
eoContinue < MOEOT > & term;
|
||||
|
|
@ -96,6 +96,6 @@ private:
|
|||
/** archive */
|
||||
moeoArchive < MOEOT > & arch;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOHYBRIDLS_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoIBEA.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -61,8 +61,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoIBEA : public moeoEA < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type of objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -77,8 +77,8 @@ public:
|
|||
* @param _kappa scaling factor kappa
|
||||
*/
|
||||
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),
|
||||
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
||||
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -91,8 +91,8 @@ public:
|
|||
* @param _kappa scaling factor kappa
|
||||
*/
|
||||
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),
|
||||
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
||||
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -108,9 +108,9 @@ public:
|
|||
* @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) :
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2),
|
||||
fitnessAssignment(_metric, _kappa), replace (fitnessAssignment, dummyDiversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut),
|
||||
genBreed (select, defaultSGAGenOp), breed (genBreed)
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2),
|
||||
fitnessAssignment(_metric, _kappa), replace (fitnessAssignment, dummyDiversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut),
|
||||
genBreed (select, defaultSGAGenOp), breed (genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -123,8 +123,8 @@ public:
|
|||
* @param _kappa scaling factor kappa
|
||||
*/
|
||||
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),
|
||||
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
continuator(_continuator), popEval(_eval), select(2),
|
||||
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -137,8 +137,8 @@ public:
|
|||
* @param _kappa scaling factor kappa
|
||||
*/
|
||||
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),
|
||||
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
continuator(_continuator), popEval(_eval), select(2),
|
||||
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -148,24 +148,25 @@ public:
|
|||
*/
|
||||
virtual void operator () (eoPop < MOEOT > &_pop)
|
||||
{
|
||||
eoPop < MOEOT > offspring, empty_pop;
|
||||
popEval (empty_pop, _pop); // a first eval of _pop
|
||||
// evaluate fitness and diversity
|
||||
fitnessAssignment(_pop);
|
||||
dummyDiversityAssignment(_pop);
|
||||
do
|
||||
eoPop < MOEOT > offspring, empty_pop;
|
||||
popEval (empty_pop, _pop); // a first eval of _pop
|
||||
// evaluate fitness and diversity
|
||||
fitnessAssignment(_pop);
|
||||
dummyDiversityAssignment(_pop);
|
||||
do
|
||||
{
|
||||
// generate offspring, worths are recalculated if necessary
|
||||
breed (_pop, offspring);
|
||||
// eval of offspring
|
||||
popEval (_pop, offspring);
|
||||
// after replace, the new pop is in _pop. Worths are recalculated if necessary
|
||||
replace (_pop, offspring);
|
||||
} while (continuator (_pop));
|
||||
// generate offspring, worths are recalculated if necessary
|
||||
breed (_pop, offspring);
|
||||
// eval of offspring
|
||||
popEval (_pop, offspring);
|
||||
// after replace, the new pop is in _pop. Worths are recalculated if necessary
|
||||
replace (_pop, offspring);
|
||||
}
|
||||
while (continuator (_pop));
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** a continuator based on the number of generations (used as default) */
|
||||
eoGenContinue < MOEOT > defaultGenContinuator;
|
||||
|
|
@ -188,6 +189,6 @@ protected:
|
|||
/** breeder */
|
||||
eoBreed < MOEOT > & breed;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOIBEA_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoIBMOLS.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -56,8 +56,8 @@
|
|||
*/
|
||||
template < class MOEOT, class Move >
|
||||
class moeoIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type of objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -73,19 +73,19 @@ public:
|
|||
* @param _continuator the stopping criteria
|
||||
*/
|
||||
moeoIBMOLS(
|
||||
moMoveInit < Move > & _moveInit,
|
||||
moNextMove < Move > & _nextMove,
|
||||
eoEvalFunc < MOEOT > & _eval,
|
||||
moeoMoveIncrEval < Move > & _moveIncrEval,
|
||||
moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
|
||||
eoContinue < MOEOT > & _continuator
|
||||
moMoveInit < Move > & _moveInit,
|
||||
moNextMove < Move > & _nextMove,
|
||||
eoEvalFunc < MOEOT > & _eval,
|
||||
moeoMoveIncrEval < Move > & _moveIncrEval,
|
||||
moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
|
||||
eoContinue < MOEOT > & _continuator
|
||||
) :
|
||||
moveInit(_moveInit),
|
||||
nextMove(_nextMove),
|
||||
eval(_eval),
|
||||
moveIncrEval(_moveIncrEval),
|
||||
fitnessAssignment (_fitnessAssignment),
|
||||
continuator (_continuator)
|
||||
moveInit(_moveInit),
|
||||
nextMove(_nextMove),
|
||||
eval(_eval),
|
||||
moveIncrEval(_moveIncrEval),
|
||||
fitnessAssignment (_fitnessAssignment),
|
||||
continuator (_continuator)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -97,32 +97,33 @@ public:
|
|||
*/
|
||||
void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _arch)
|
||||
{
|
||||
// evaluation of the objective values
|
||||
/*
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
{
|
||||
eval(_pop[i]);
|
||||
}
|
||||
*/
|
||||
// fitness assignment for the whole population
|
||||
fitnessAssignment(_pop);
|
||||
// creation of a local archive
|
||||
moeoArchive < MOEOT > archive;
|
||||
// creation of another local archive (for the stopping criteria)
|
||||
moeoArchive < MOEOT > previousArchive;
|
||||
// update the archive with the initial population
|
||||
archive.update(_pop);
|
||||
do
|
||||
// evaluation of the objective values
|
||||
/*
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
{
|
||||
eval(_pop[i]);
|
||||
}
|
||||
*/
|
||||
// fitness assignment for the whole population
|
||||
fitnessAssignment(_pop);
|
||||
// creation of a local archive
|
||||
moeoArchive < MOEOT > archive;
|
||||
// creation of another local archive (for the stopping criteria)
|
||||
moeoArchive < MOEOT > previousArchive;
|
||||
// update the archive with the initial population
|
||||
archive.update(_pop);
|
||||
do
|
||||
{
|
||||
previousArchive.update(archive);
|
||||
oneStep(_pop);
|
||||
archive.update(_pop);
|
||||
} while ( (! archive.equals(previousArchive)) && (continuator(_arch)) );
|
||||
_arch.update(archive);
|
||||
previousArchive.update(archive);
|
||||
oneStep(_pop);
|
||||
archive.update(_pop);
|
||||
}
|
||||
while ( (! archive.equals(previousArchive)) && (continuator(_arch)) );
|
||||
_arch.update(archive);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the move initializer */
|
||||
moMoveInit < Move > & moveInit;
|
||||
|
|
@ -144,162 +145,162 @@ private:
|
|||
*/
|
||||
void oneStep (eoPop < MOEOT > & _pop)
|
||||
{
|
||||
// the move
|
||||
Move move;
|
||||
// the objective vector and the fitness of the current solution
|
||||
ObjectiveVector x_objVec;
|
||||
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)
|
||||
int worst_idx;
|
||||
ObjectiveVector worst_objVec;
|
||||
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 move
|
||||
Move move;
|
||||
// the objective vector and the fitness of the current solution
|
||||
ObjectiveVector x_objVec;
|
||||
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)
|
||||
int worst_idx;
|
||||
ObjectiveVector worst_objVec;
|
||||
double worst_fitness;
|
||||
////////////////////////////////////////////
|
||||
// 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))
|
||||
// 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
|
||||
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]
|
||||
// evaluate x in the objective space
|
||||
x_objVec = moveIncrEval(move, _pop[i]);
|
||||
// update every fitness values to take x into account and compute the fitness of x
|
||||
x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec);
|
||||
// x = one neigbour of pop[i]
|
||||
// evaluate x in the objective space
|
||||
x_objVec = moveIncrEval(move, _pop[i]);
|
||||
// update every fitness values to take x into account and compute the fitness of x
|
||||
x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// extreme solutions (min only!)
|
||||
ext_0_idx = -1;
|
||||
ext_0_objVec = x_objVec;
|
||||
ext_1_idx = -1;
|
||||
ext_1_objVec = x_objVec;
|
||||
for (unsigned int k=0; k<_pop.size(); k++)
|
||||
// extreme solutions (min only!)
|
||||
ext_0_idx = -1;
|
||||
ext_0_objVec = x_objVec;
|
||||
ext_1_idx = -1;
|
||||
ext_1_objVec = x_objVec;
|
||||
for (unsigned int k=0; k<_pop.size(); k++)
|
||||
{
|
||||
// ext_0
|
||||
if (_pop[k].objectiveVector()[0] < ext_0_objVec[0])
|
||||
// ext_0
|
||||
if (_pop[k].objectiveVector()[0] < ext_0_objVec[0])
|
||||
{
|
||||
ext_0_idx = k;
|
||||
ext_0_objVec = _pop[k].objectiveVector();
|
||||
ext_0_idx = k;
|
||||
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_objVec = _pop[k].objectiveVector();
|
||||
ext_0_idx = k;
|
||||
ext_0_objVec = _pop[k].objectiveVector();
|
||||
}
|
||||
// ext_1
|
||||
else if (_pop[k].objectiveVector()[1] < ext_1_objVec[1])
|
||||
// ext_1
|
||||
else if (_pop[k].objectiveVector()[1] < ext_1_objVec[1])
|
||||
{
|
||||
ext_1_idx = k;
|
||||
ext_1_objVec = _pop[k].objectiveVector();
|
||||
ext_1_idx = k;
|
||||
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_objVec = _pop[k].objectiveVector();
|
||||
ext_1_idx = k;
|
||||
ext_1_objVec = _pop[k].objectiveVector();
|
||||
}
|
||||
}
|
||||
// worst init
|
||||
if (ext_0_idx == -1)
|
||||
// worst init
|
||||
if (ext_0_idx == -1)
|
||||
{
|
||||
ind = 0;
|
||||
while (ind == ext_1_idx)
|
||||
ind = 0;
|
||||
while (ind == ext_1_idx)
|
||||
{
|
||||
ind++;
|
||||
ind++;
|
||||
}
|
||||
worst_idx = ind;
|
||||
worst_objVec = _pop[ind].objectiveVector();
|
||||
worst_fitness = _pop[ind].fitness();
|
||||
worst_idx = ind;
|
||||
worst_objVec = _pop[ind].objectiveVector();
|
||||
worst_fitness = _pop[ind].fitness();
|
||||
}
|
||||
else if (ext_1_idx == -1)
|
||||
else if (ext_1_idx == -1)
|
||||
{
|
||||
ind = 0;
|
||||
while (ind == ext_0_idx)
|
||||
ind = 0;
|
||||
while (ind == ext_0_idx)
|
||||
{
|
||||
ind++;
|
||||
ind++;
|
||||
}
|
||||
worst_idx = ind;
|
||||
worst_objVec = _pop[ind].objectiveVector();
|
||||
worst_fitness = _pop[ind].fitness();
|
||||
worst_idx = ind;
|
||||
worst_objVec = _pop[ind].objectiveVector();
|
||||
worst_fitness = _pop[ind].fitness();
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
worst_idx = -1;
|
||||
worst_objVec = x_objVec;
|
||||
worst_fitness = x_fitness;
|
||||
worst_idx = -1;
|
||||
worst_objVec = x_objVec;
|
||||
worst_fitness = x_fitness;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// who is the worst ?
|
||||
for (unsigned int j=0; j<_pop.size(); j++)
|
||||
// who is the worst ?
|
||||
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_objVec = _pop[j].objectiveVector();
|
||||
worst_fitness = _pop[j].fitness();
|
||||
worst_idx = j;
|
||||
worst_objVec = _pop[j].objectiveVector();
|
||||
worst_fitness = _pop[j].fitness();
|
||||
}
|
||||
}
|
||||
}
|
||||
// if the worst solution is the new one
|
||||
if (worst_idx == -1)
|
||||
// if the worst solution is the new one
|
||||
if (worst_idx == -1)
|
||||
{
|
||||
// if all its neighbours have been explored,
|
||||
// let's explore the neighborhoud of the next individual
|
||||
if (! nextMove(move, _pop[i]))
|
||||
// if all its neighbours have been explored,
|
||||
// let's explore the neighborhoud of the next individual
|
||||
if (! nextMove(move, _pop[i]))
|
||||
{
|
||||
i++;
|
||||
if (i<_pop.size())
|
||||
i++;
|
||||
if (i<_pop.size())
|
||||
{
|
||||
// initilization of the move for the next individual
|
||||
moveInit(move, _pop[i]);
|
||||
// initilization of the move for the next individual
|
||||
moveInit(move, _pop[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if the worst solution is located before _pop[i]
|
||||
else if (worst_idx <= i)
|
||||
// if the worst solution is located before _pop[i]
|
||||
else if (worst_idx <= i)
|
||||
{
|
||||
// the new solution takes place insteed of _pop[worst_idx]
|
||||
_pop[worst_idx] = _pop[i];
|
||||
move(_pop[worst_idx]);
|
||||
_pop[worst_idx].objectiveVector(x_objVec);
|
||||
_pop[worst_idx].fitness(x_fitness);
|
||||
// let's explore the neighborhoud of the next individual
|
||||
i++;
|
||||
if (i<_pop.size())
|
||||
// the new solution takes place insteed of _pop[worst_idx]
|
||||
_pop[worst_idx] = _pop[i];
|
||||
move(_pop[worst_idx]);
|
||||
_pop[worst_idx].objectiveVector(x_objVec);
|
||||
_pop[worst_idx].fitness(x_fitness);
|
||||
// let's explore the neighborhoud of the next individual
|
||||
i++;
|
||||
if (i<_pop.size())
|
||||
{
|
||||
// initilization of the move for the next individual
|
||||
moveInit(move, _pop[i]);
|
||||
// initilization of the move for the next individual
|
||||
moveInit(move, _pop[i]);
|
||||
}
|
||||
}
|
||||
// if the worst solution is located after _pop[i]
|
||||
else if (worst_idx > i)
|
||||
// if the worst solution is located after _pop[i]
|
||||
else if (worst_idx > i)
|
||||
{
|
||||
// the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted
|
||||
_pop[worst_idx] = _pop[i+1];
|
||||
_pop[i+1] = _pop[i];
|
||||
move(_pop[i+1]);
|
||||
_pop[i+1].objectiveVector(x_objVec);
|
||||
_pop[i+1].fitness(x_fitness);
|
||||
// let's explore the neighborhoud of the individual _pop[i+2]
|
||||
i += 2;
|
||||
if (i<_pop.size())
|
||||
// the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted
|
||||
_pop[worst_idx] = _pop[i+1];
|
||||
_pop[i+1] = _pop[i];
|
||||
move(_pop[i+1]);
|
||||
_pop[i+1].objectiveVector(x_objVec);
|
||||
_pop[i+1].fitness(x_fitness);
|
||||
// let's explore the neighborhoud of the individual _pop[i+2]
|
||||
i += 2;
|
||||
if (i<_pop.size())
|
||||
{
|
||||
// initilization of the move for the next individual
|
||||
moveInit(move, _pop[i]);
|
||||
// initilization of the move for the next individual
|
||||
moveInit(move, _pop[i]);
|
||||
}
|
||||
}
|
||||
// update fitness values
|
||||
fitnessAssignment.updateByDeleting(_pop, worst_objVec);
|
||||
// update fitness values
|
||||
fitnessAssignment.updateByDeleting(_pop, worst_objVec);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -328,153 +329,153 @@ private:
|
|||
*/
|
||||
void new_oneStep (eoPop < MOEOT > & _pop)
|
||||
{
|
||||
// the move
|
||||
Move move;
|
||||
// the objective vector and the fitness of the current solution
|
||||
ObjectiveVector x_objVec;
|
||||
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)
|
||||
int worst_idx;
|
||||
ObjectiveVector worst_objVec;
|
||||
double worst_fitness;
|
||||
////////////////////////////////////////////
|
||||
// the index of the extreme non-dominated points
|
||||
int ext_0_idx, ext_1_idx;
|
||||
unsigned int ind;
|
||||
// the move
|
||||
Move move;
|
||||
// the objective vector and the fitness of the current solution
|
||||
ObjectiveVector x_objVec;
|
||||
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)
|
||||
int worst_idx;
|
||||
ObjectiveVector worst_objVec;
|
||||
double worst_fitness;
|
||||
////////////////////////////////////////////
|
||||
// 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))
|
||||
// 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
|
||||
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]
|
||||
// evaluate x in the objective space
|
||||
x_objVec = moveIncrEval(move, _pop[i]);
|
||||
// update every fitness values to take x into account and compute the fitness of x
|
||||
x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec);
|
||||
// x = one neigbour of pop[i]
|
||||
// evaluate x in the objective space
|
||||
x_objVec = moveIncrEval(move, _pop[i]);
|
||||
// update every fitness values to take x into account and compute the fitness of x
|
||||
x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// extremes solutions
|
||||
OneObjectiveComparator comp0(0);
|
||||
ext_0_idx = std::min_element(_pop.begin(), _pop.end(), comp0) - _pop.begin();
|
||||
OneObjectiveComparator comp1(1);
|
||||
ext_1_idx = std::min_element(_pop.begin(), _pop.end(), comp1) - _pop.begin();
|
||||
// new = extreme ?
|
||||
if (x_objVec[0] < _pop[ext_0_idx].objectiveVector()[0])
|
||||
// extremes solutions
|
||||
OneObjectiveComparator comp0(0);
|
||||
ext_0_idx = std::min_element(_pop.begin(), _pop.end(), comp0) - _pop.begin();
|
||||
OneObjectiveComparator comp1(1);
|
||||
ext_1_idx = std::min_element(_pop.begin(), _pop.end(), comp1) - _pop.begin();
|
||||
// new = extreme ?
|
||||
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
|
||||
if (ext_0_idx == -1)
|
||||
// worst init
|
||||
if (ext_0_idx == -1)
|
||||
{
|
||||
ind = 0;
|
||||
while (ind == ext_1_idx)
|
||||
ind = 0;
|
||||
while (ind == ext_1_idx)
|
||||
{
|
||||
ind++;
|
||||
ind++;
|
||||
}
|
||||
worst_idx = ind;
|
||||
worst_objVec = _pop[ind].objectiveVector();
|
||||
worst_fitness = _pop[ind].fitness();
|
||||
worst_idx = ind;
|
||||
worst_objVec = _pop[ind].objectiveVector();
|
||||
worst_fitness = _pop[ind].fitness();
|
||||
}
|
||||
else if (ext_1_idx == -1)
|
||||
else if (ext_1_idx == -1)
|
||||
{
|
||||
ind = 0;
|
||||
while (ind == ext_0_idx)
|
||||
ind = 0;
|
||||
while (ind == ext_0_idx)
|
||||
{
|
||||
ind++;
|
||||
ind++;
|
||||
}
|
||||
worst_idx = ind;
|
||||
worst_objVec = _pop[ind].objectiveVector();
|
||||
worst_fitness = _pop[ind].fitness();
|
||||
worst_idx = ind;
|
||||
worst_objVec = _pop[ind].objectiveVector();
|
||||
worst_fitness = _pop[ind].fitness();
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
worst_idx = -1;
|
||||
worst_objVec = x_objVec;
|
||||
worst_fitness = x_fitness;
|
||||
worst_idx = -1;
|
||||
worst_objVec = x_objVec;
|
||||
worst_fitness = x_fitness;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// who is the worst ?
|
||||
for (unsigned int j=0; j<_pop.size(); j++)
|
||||
// who is the worst ?
|
||||
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_objVec = _pop[j].objectiveVector();
|
||||
worst_fitness = _pop[j].fitness();
|
||||
worst_idx = j;
|
||||
worst_objVec = _pop[j].objectiveVector();
|
||||
worst_fitness = _pop[j].fitness();
|
||||
}
|
||||
}
|
||||
}
|
||||
// if the worst solution is the new one
|
||||
if (worst_idx == -1)
|
||||
// if the worst solution is the new one
|
||||
if (worst_idx == -1)
|
||||
{
|
||||
// if all its neighbours have been explored,
|
||||
// let's explore the neighborhoud of the next individual
|
||||
if (! nextMove(move, _pop[i]))
|
||||
// if all its neighbours have been explored,
|
||||
// let's explore the neighborhoud of the next individual
|
||||
if (! nextMove(move, _pop[i]))
|
||||
{
|
||||
i++;
|
||||
if (i<_pop.size())
|
||||
i++;
|
||||
if (i<_pop.size())
|
||||
{
|
||||
// initilization of the move for the next individual
|
||||
moveInit(move, _pop[i]);
|
||||
// initilization of the move for the next individual
|
||||
moveInit(move, _pop[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if the worst solution is located before _pop[i]
|
||||
else if (worst_idx <= i)
|
||||
// if the worst solution is located before _pop[i]
|
||||
else if (worst_idx <= i)
|
||||
{
|
||||
// the new solution takes place insteed of _pop[worst_idx]
|
||||
_pop[worst_idx] = _pop[i];
|
||||
move(_pop[worst_idx]);
|
||||
_pop[worst_idx].objectiveVector(x_objVec);
|
||||
_pop[worst_idx].fitness(x_fitness);
|
||||
// let's explore the neighborhoud of the next individual
|
||||
i++;
|
||||
if (i<_pop.size())
|
||||
// the new solution takes place insteed of _pop[worst_idx]
|
||||
_pop[worst_idx] = _pop[i];
|
||||
move(_pop[worst_idx]);
|
||||
_pop[worst_idx].objectiveVector(x_objVec);
|
||||
_pop[worst_idx].fitness(x_fitness);
|
||||
// let's explore the neighborhoud of the next individual
|
||||
i++;
|
||||
if (i<_pop.size())
|
||||
{
|
||||
// initilization of the move for the next individual
|
||||
moveInit(move, _pop[i]);
|
||||
// initilization of the move for the next individual
|
||||
moveInit(move, _pop[i]);
|
||||
}
|
||||
}
|
||||
// if the worst solution is located after _pop[i]
|
||||
else if (worst_idx > i)
|
||||
// if the worst solution is located after _pop[i]
|
||||
else if (worst_idx > i)
|
||||
{
|
||||
// the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted
|
||||
_pop[worst_idx] = _pop[i+1];
|
||||
_pop[i+1] = _pop[i];
|
||||
move(_pop[i+1]);
|
||||
_pop[i+1].objectiveVector(x_objVec);
|
||||
_pop[i+1].fitness(x_fitness);
|
||||
// let's explore the neighborhoud of the individual _pop[i+2]
|
||||
i += 2;
|
||||
if (i<_pop.size())
|
||||
// the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted
|
||||
_pop[worst_idx] = _pop[i+1];
|
||||
_pop[i+1] = _pop[i];
|
||||
move(_pop[i+1]);
|
||||
_pop[i+1].objectiveVector(x_objVec);
|
||||
_pop[i+1].fitness(x_fitness);
|
||||
// let's explore the neighborhoud of the individual _pop[i+2]
|
||||
i += 2;
|
||||
if (i<_pop.size())
|
||||
{
|
||||
// initilization of the move for the next individual
|
||||
moveInit(move, _pop[i]);
|
||||
// initilization of the move for the next individual
|
||||
moveInit(move, _pop[i]);
|
||||
}
|
||||
}
|
||||
// update fitness values
|
||||
fitnessAssignment.updateByDeleting(_pop, worst_objVec);
|
||||
// update fitness values
|
||||
fitnessAssignment.updateByDeleting(_pop, worst_objVec);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -484,35 +485,35 @@ private:
|
|||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
class OneObjectiveComparator : public moeoComparator < MOEOT >
|
||||
{
|
||||
public:
|
||||
class OneObjectiveComparator : public moeoComparator < MOEOT >
|
||||
{
|
||||
public:
|
||||
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)
|
||||
{
|
||||
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;
|
||||
};
|
||||
};
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOIBMOLS_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoIteratedIBMOLS.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -64,8 +64,8 @@
|
|||
*/
|
||||
template < class MOEOT, class Move >
|
||||
class moeoIteratedIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type of objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -84,22 +84,22 @@ public:
|
|||
* @param _nNoiseIterations the number of iterations to apply the random noise
|
||||
*/
|
||||
moeoIteratedIBMOLS(
|
||||
moMoveInit < Move > & _moveInit,
|
||||
moNextMove < Move > & _nextMove,
|
||||
eoEvalFunc < MOEOT > & _eval,
|
||||
moeoMoveIncrEval < Move > & _moveIncrEval,
|
||||
moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
|
||||
eoContinue < MOEOT > & _continuator,
|
||||
eoMonOp < MOEOT > & _monOp,
|
||||
eoMonOp < MOEOT > & _randomMonOp,
|
||||
unsigned int _nNoiseIterations=1
|
||||
moMoveInit < Move > & _moveInit,
|
||||
moNextMove < Move > & _nextMove,
|
||||
eoEvalFunc < MOEOT > & _eval,
|
||||
moeoMoveIncrEval < Move > & _moveIncrEval,
|
||||
moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
|
||||
eoContinue < MOEOT > & _continuator,
|
||||
eoMonOp < MOEOT > & _monOp,
|
||||
eoMonOp < MOEOT > & _randomMonOp,
|
||||
unsigned int _nNoiseIterations=1
|
||||
) :
|
||||
ibmols(_moveInit, _nextMove, _eval, _moveIncrEval, _fitnessAssignment, _continuator),
|
||||
eval(_eval),
|
||||
continuator(_continuator),
|
||||
monOp(_monOp),
|
||||
randomMonOp(_randomMonOp),
|
||||
nNoiseIterations(_nNoiseIterations)
|
||||
ibmols(_moveInit, _nextMove, _eval, _moveIncrEval, _fitnessAssignment, _continuator),
|
||||
eval(_eval),
|
||||
continuator(_continuator),
|
||||
monOp(_monOp),
|
||||
randomMonOp(_randomMonOp),
|
||||
nNoiseIterations(_nNoiseIterations)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -110,19 +110,19 @@ public:
|
|||
*/
|
||||
void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _arch)
|
||||
{
|
||||
_arch.update(_pop);
|
||||
ibmols(_pop, _arch);
|
||||
while (continuator(_arch))
|
||||
_arch.update(_pop);
|
||||
ibmols(_pop, _arch);
|
||||
while (continuator(_arch))
|
||||
{
|
||||
// generate new solutions from the archive
|
||||
generateNewSolutions(_pop, _arch);
|
||||
// apply the local search (the global archive is updated in the sub-function)
|
||||
ibmols(_pop, _arch);
|
||||
// generate new solutions from the archive
|
||||
generateNewSolutions(_pop, _arch);
|
||||
// apply the local search (the global archive is updated in the sub-function)
|
||||
ibmols(_pop, _arch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the local search to iterate */
|
||||
moeoIBMOLS < MOEOT, Move > ibmols;
|
||||
|
|
@ -145,38 +145,38 @@ private:
|
|||
*/
|
||||
void generateNewSolutions(eoPop < MOEOT > & _pop, const moeoArchive < MOEOT > & _arch)
|
||||
{
|
||||
// shuffle vector for the random selection of individuals
|
||||
vector<unsigned int> shuffle;
|
||||
shuffle.resize(std::max(_pop.size(), _arch.size()));
|
||||
// init shuffle
|
||||
for (unsigned int i=0; i<shuffle.size(); i++)
|
||||
// shuffle vector for the random selection of individuals
|
||||
vector<unsigned int> shuffle;
|
||||
shuffle.resize(std::max(_pop.size(), _arch.size()));
|
||||
// init shuffle
|
||||
for (unsigned int i=0; i<shuffle.size(); i++)
|
||||
{
|
||||
shuffle[i] = i;
|
||||
shuffle[i] = i;
|
||||
}
|
||||
// randomize shuffle
|
||||
UF_random_generator <unsigned int> gen;
|
||||
std::random_shuffle(shuffle.begin(), shuffle.end(), gen);
|
||||
// start the creation of new solutions
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
// randomize shuffle
|
||||
UF_random_generator <unsigned int> gen;
|
||||
std::random_shuffle(shuffle.begin(), shuffle.end(), gen);
|
||||
// start the creation of new solutions
|
||||
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
|
||||
_pop[i] = _arch[shuffle[i]];
|
||||
// apply noise
|
||||
for (unsigned int j=0; j<nNoiseIterations; j++)
|
||||
// add it to the resulting pop
|
||||
_pop[i] = _arch[shuffle[i]];
|
||||
// apply noise
|
||||
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
|
||||
randomMonOp(_pop[i]);
|
||||
// random initialization
|
||||
randomMonOp(_pop[i]);
|
||||
}
|
||||
// evaluation of the new individual
|
||||
_pop[i].invalidate();
|
||||
eval(_pop[i]);
|
||||
// evaluation of the new individual
|
||||
_pop[i].invalidate();
|
||||
eval(_pop[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,6 +233,6 @@ private:
|
|||
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOITERATEDIBMOLS_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoLS.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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.
|
||||
*/
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoNSGA.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -60,8 +60,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoNSGA: public moeoEA < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Simple ctor with a eoGenOp.
|
||||
|
|
@ -71,8 +71,8 @@ public:
|
|||
* @param _nicheSize niche size
|
||||
*/
|
||||
moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, double _nicheSize = 0.5) :
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
||||
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
||||
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -84,8 +84,8 @@ public:
|
|||
* @param _nicheSize niche size
|
||||
*/
|
||||
moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, double _nicheSize = 0.5) :
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
||||
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
||||
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -100,9 +100,9 @@ public:
|
|||
* @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) :
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2),
|
||||
diversityAssignment(_nicheSize), replace (fitnessAssignment, diversityAssignment),
|
||||
defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), genBreed (select, defaultSGAGenOp), breed (genBreed)
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2),
|
||||
diversityAssignment(_nicheSize), replace (fitnessAssignment, diversityAssignment),
|
||||
defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), genBreed (select, defaultSGAGenOp), breed (genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -114,8 +114,8 @@ public:
|
|||
* @param _nicheSize niche size
|
||||
*/
|
||||
moeoNSGA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, double _nicheSize = 0.5) :
|
||||
continuator(_continuator), popEval(_eval), select(2),
|
||||
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
continuator(_continuator), popEval(_eval), select(2),
|
||||
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -127,8 +127,8 @@ public:
|
|||
* @param _nicheSize niche size
|
||||
*/
|
||||
moeoNSGA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, double _nicheSize = 0.5) :
|
||||
continuator(_continuator), popEval(_eval), select(2),
|
||||
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
continuator(_continuator), popEval(_eval), select(2),
|
||||
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -138,24 +138,25 @@ public:
|
|||
*/
|
||||
virtual void operator () (eoPop < MOEOT > &_pop)
|
||||
{
|
||||
eoPop < MOEOT > offspring, empty_pop;
|
||||
popEval (empty_pop, _pop); // a first eval of _pop
|
||||
// evaluate fitness and diversity
|
||||
fitnessAssignment(_pop);
|
||||
diversityAssignment(_pop);
|
||||
do
|
||||
eoPop < MOEOT > offspring, empty_pop;
|
||||
popEval (empty_pop, _pop); // a first eval of _pop
|
||||
// evaluate fitness and diversity
|
||||
fitnessAssignment(_pop);
|
||||
diversityAssignment(_pop);
|
||||
do
|
||||
{
|
||||
// generate offspring, worths are recalculated if necessary
|
||||
breed (_pop, offspring);
|
||||
// eval of offspring
|
||||
popEval (_pop, offspring);
|
||||
// after replace, the new pop is in _pop. Worths are recalculated if necessary
|
||||
replace (_pop, offspring);
|
||||
} while (continuator (_pop));
|
||||
// generate offspring, worths are recalculated if necessary
|
||||
breed (_pop, offspring);
|
||||
// eval of offspring
|
||||
popEval (_pop, offspring);
|
||||
// after replace, the new pop is in _pop. Worths are recalculated if necessary
|
||||
replace (_pop, offspring);
|
||||
}
|
||||
while (continuator (_pop));
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** a continuator based on the number of generations (used as default) */
|
||||
eoGenContinue < MOEOT > defaultGenContinuator;
|
||||
|
|
@ -178,6 +179,6 @@ protected:
|
|||
/** breeder */
|
||||
eoBreed < MOEOT > & breed;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEONSGAII_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoNSGAII.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -63,8 +63,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoNSGAII: public moeoEA < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Simple ctor with a eoGenOp.
|
||||
|
|
@ -73,9 +73,9 @@ public:
|
|||
* @param _op variation operator
|
||||
*/
|
||||
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
||||
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
|
||||
genBreed(select, _op), breed(genBreed)
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
||||
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
|
||||
genBreed(select, _op), breed(genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -86,9 +86,9 @@ public:
|
|||
* @param _op variation operator
|
||||
*/
|
||||
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) :
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
||||
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
|
||||
genBreed(select, _op), breed(genBreed)
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
||||
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
|
||||
genBreed(select, _op), breed(genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -102,9 +102,9 @@ public:
|
|||
* @param _pMut mutation probability
|
||||
*/
|
||||
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),
|
||||
replace (fitnessAssignment, diversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut),
|
||||
genBreed (select, defaultSGAGenOp), breed (genBreed)
|
||||
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2),
|
||||
replace (fitnessAssignment, diversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut),
|
||||
genBreed (select, defaultSGAGenOp), breed (genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -115,9 +115,9 @@ public:
|
|||
* @param _op variation operator
|
||||
*/
|
||||
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
|
||||
defaultGenContinuator(0), continuator(_continuator), popEval(_eval), select(2),
|
||||
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0),
|
||||
genBreed(select, _op), breed(genBreed)
|
||||
defaultGenContinuator(0), continuator(_continuator), popEval(_eval), select(2),
|
||||
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0),
|
||||
genBreed(select, _op), breed(genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -128,9 +128,9 @@ public:
|
|||
* @param _op variation operator
|
||||
*/
|
||||
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) :
|
||||
continuator(_continuator), popEval(_eval), select(2),
|
||||
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
|
||||
genBreed(select, _op), breed(genBreed)
|
||||
continuator(_continuator), popEval(_eval), select(2),
|
||||
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
|
||||
genBreed(select, _op), breed(genBreed)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -140,24 +140,25 @@ public:
|
|||
*/
|
||||
virtual void operator () (eoPop < MOEOT > &_pop)
|
||||
{
|
||||
eoPop < MOEOT > offspring, empty_pop;
|
||||
popEval (empty_pop, _pop); // a first eval of _pop
|
||||
// evaluate fitness and diversity
|
||||
fitnessAssignment(_pop);
|
||||
diversityAssignment(_pop);
|
||||
do
|
||||
eoPop < MOEOT > offspring, empty_pop;
|
||||
popEval (empty_pop, _pop); // a first eval of _pop
|
||||
// evaluate fitness and diversity
|
||||
fitnessAssignment(_pop);
|
||||
diversityAssignment(_pop);
|
||||
do
|
||||
{
|
||||
// generate offspring, worths are recalculated if necessary
|
||||
breed (_pop, offspring);
|
||||
// eval of offspring
|
||||
popEval (_pop, offspring);
|
||||
// after replace, the new pop is in _pop. Worths are recalculated if necessary
|
||||
replace (_pop, offspring);
|
||||
} while (continuator (_pop));
|
||||
// generate offspring, worths are recalculated if necessary
|
||||
breed (_pop, offspring);
|
||||
// eval of offspring
|
||||
popEval (_pop, offspring);
|
||||
// after replace, the new pop is in _pop. Worths are recalculated if necessary
|
||||
replace (_pop, offspring);
|
||||
}
|
||||
while (continuator (_pop));
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** a continuator based on the number of generations (used as default) */
|
||||
eoGenContinue < MOEOT > defaultGenContinuator;
|
||||
|
|
@ -184,6 +185,6 @@ protected:
|
|||
/** breeder */
|
||||
eoBreed < MOEOT > & breed;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEONSGAII_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoArchive.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoArchive : public eoPop < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
using eoPop < MOEOT > :: size;
|
||||
using eoPop < MOEOT > :: operator[];
|
||||
|
|
@ -83,17 +83,17 @@ public:
|
|||
* @param _objectiveVector the objective vector to compare with the current archive
|
||||
*/
|
||||
bool dominates (const ObjectiveVector & _objectiveVector) const
|
||||
{
|
||||
{
|
||||
for (unsigned int i = 0; i<size(); i++)
|
||||
{
|
||||
{
|
||||
// if _objectiveVector is dominated by the ith individual of the archive...
|
||||
if ( comparator(_objectiveVector, operator[](i).objectiveVector()) )
|
||||
{
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -101,16 +101,16 @@ public:
|
|||
* @param _objectiveVector the objective vector to compare with the current archive
|
||||
*/
|
||||
bool contains (const ObjectiveVector & _objectiveVector) const
|
||||
{
|
||||
{
|
||||
for (unsigned int i = 0; i<size(); i++)
|
||||
{
|
||||
{
|
||||
if (operator[](i).objectiveVector() == _objectiveVector)
|
||||
{
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -119,39 +119,39 @@ public:
|
|||
*/
|
||||
void update (const MOEOT & _moeo)
|
||||
{
|
||||
// first step: removing the dominated solutions from the archive
|
||||
for (unsigned int j=0; j<size();)
|
||||
// first step: removing the dominated solutions from the archive
|
||||
for (unsigned int j=0; j<size();)
|
||||
{
|
||||
// if the jth solution contained in the archive is dominated by _moeo
|
||||
if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
|
||||
// if the jth solution contained in the archive is dominated by _moeo
|
||||
if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
|
||||
{
|
||||
operator[](j) = back();
|
||||
pop_back();
|
||||
operator[](j) = back();
|
||||
pop_back();
|
||||
}
|
||||
else if (_moeo.objectiveVector() == operator[](j).objectiveVector())
|
||||
else if (_moeo.objectiveVector() == operator[](j).objectiveVector())
|
||||
{
|
||||
operator[](j) = back();
|
||||
pop_back();
|
||||
operator[](j) = back();
|
||||
pop_back();
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
j++;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
// second step: is _moeo dominated?
|
||||
bool dom = false;
|
||||
for (unsigned int j=0; j<size(); j++)
|
||||
// second step: is _moeo dominated?
|
||||
bool dom = false;
|
||||
for (unsigned int j=0; j<size(); j++)
|
||||
{
|
||||
// if _moeo is dominated by the jth solution contained in the archive
|
||||
if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
|
||||
// if _moeo is dominated by the jth solution contained in the archive
|
||||
if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
|
||||
{
|
||||
dom = true;
|
||||
break;
|
||||
dom = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!dom)
|
||||
if (!dom)
|
||||
{
|
||||
push_back(_moeo);
|
||||
push_back(_moeo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -162,9 +162,9 @@ public:
|
|||
*/
|
||||
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)
|
||||
{
|
||||
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 */
|
||||
moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
|
||||
/** A moeoObjectiveVectorComparator based on Pareto dominance (used as default) */
|
||||
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOARCHIVE_H_ */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoAggregativeComparator.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoAggregativeComparator : public moeoComparator < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor.
|
||||
|
|
@ -64,17 +64,17 @@ public:
|
|||
*/
|
||||
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 */
|
||||
double weightFitness;
|
||||
/** the weight for diversity */
|
||||
double weightDiversity;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOAGGREGATIVECOMPARATOR_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoComparator.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
* Functor allowing to compare two solutions.
|
||||
*/
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoDiversityThenFitnessComparator.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoDiversityThenFitnessComparator : public moeoComparator < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoFitnessThenDiversityComparator.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoFitnessThenDiversityComparator : public moeoComparator < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoGDominanceObjectiveVectorComparator.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -48,8 +48,8 @@
|
|||
*/
|
||||
template < class ObjectiveVector >
|
||||
class moeoGDominanceObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor.
|
||||
|
|
@ -66,27 +66,27 @@ public:
|
|||
*/
|
||||
const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
|
||||
{
|
||||
unsigned int flag1 = flag(_objectiveVector1);
|
||||
unsigned int flag2 = flag(_objectiveVector2);
|
||||
if (flag2==0)
|
||||
unsigned int flag1 = flag(_objectiveVector1);
|
||||
unsigned int flag2 = flag(_objectiveVector2);
|
||||
if (flag2==0)
|
||||
{
|
||||
// cannot dominate
|
||||
return false;
|
||||
// cannot dominate
|
||||
return false;
|
||||
}
|
||||
else if ( (flag2==1) && (flag1==0) )
|
||||
else if ( (flag2==1) && (flag1==0) )
|
||||
{
|
||||
// is dominated
|
||||
return true;
|
||||
// is dominated
|
||||
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
|
||||
return paretoComparator(_objectiveVector1, _objectiveVector2);
|
||||
// both are on the good region, so let's use the classical Pareto dominance
|
||||
return paretoComparator(_objectiveVector1, _objectiveVector2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the reference point */
|
||||
ObjectiveVector & ref;
|
||||
|
|
@ -100,28 +100,28 @@ private:
|
|||
*/
|
||||
unsigned int flag(const ObjectiveVector & _objectiveVector)
|
||||
{
|
||||
unsigned int result=1;
|
||||
for (unsigned int i=0; i<ref.nObjectives(); i++)
|
||||
unsigned int result=1;
|
||||
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;
|
||||
for (unsigned int i=0; i<ref.nObjectives(); i++)
|
||||
result=1;
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoObjectiveObjectiveVectorComparator.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class ObjectiveVector >
|
||||
class moeoObjectiveObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoObjectiveVectorComparator.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -46,6 +46,7 @@
|
|||
* The template argument ObjectiveVector have to be a moeoObjectiveVector.
|
||||
*/
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoOneObjectiveComparator.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoOneObjectiveComparator : public moeoComparator < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor.
|
||||
|
|
@ -54,9 +54,9 @@ public:
|
|||
*/
|
||||
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)
|
||||
{
|
||||
return _moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj];
|
||||
return _moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj];
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the index of objective */
|
||||
unsigned int obj;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOONEOBJECTIVECOMPARATOR_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoParetoObjectiveVectorComparator.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class ObjectiveVector >
|
||||
class moeoParetoObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Returns true if _objectiveVector1 is dominated by _objectiveVector2
|
||||
|
|
@ -55,41 +55,41 @@ public:
|
|||
*/
|
||||
const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
|
||||
{
|
||||
bool dom = false;
|
||||
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
|
||||
bool dom = false;
|
||||
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
|
||||
if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() )
|
||||
// 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 the ith objective have to be minimized...
|
||||
if (ObjectiveVector::minimizing(i))
|
||||
// if the ith objective have to be minimized...
|
||||
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...
|
||||
else if (ObjectiveVector::maximizing(i))
|
||||
// if the ith objective have to be maximized...
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <MOEO.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -57,8 +57,8 @@
|
|||
*/
|
||||
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
|
||||
class MOEO : public EO < MOEOObjectiveVector >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** the objective vector type of a solution */
|
||||
typedef MOEOObjectiveVector ObjectiveVector;
|
||||
|
|
@ -75,32 +75,33 @@ public:
|
|||
*/
|
||||
MOEO()
|
||||
{
|
||||
// default values for every parameters
|
||||
objectiveVectorValue = ObjectiveVector();
|
||||
fitnessValue = Fitness();
|
||||
diversityValue = Diversity();
|
||||
// invalidate all
|
||||
invalidate();
|
||||
// default values for every parameters
|
||||
objectiveVectorValue = ObjectiveVector();
|
||||
fitnessValue = Fitness();
|
||||
diversityValue = Diversity();
|
||||
// invalidate all
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Virtual dtor
|
||||
*/
|
||||
virtual ~MOEO() {};
|
||||
virtual ~MOEO()
|
||||
{};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the objective vector of the current solution
|
||||
*/
|
||||
ObjectiveVector objectiveVector() const
|
||||
{
|
||||
{
|
||||
if ( invalidObjectiveVector() )
|
||||
{
|
||||
{
|
||||
throw std::runtime_error("invalid objective vector in MOEO");
|
||||
}
|
||||
}
|
||||
return objectiveVectorValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -109,8 +110,8 @@ public:
|
|||
*/
|
||||
void objectiveVector(const ObjectiveVector & _objectiveVectorValue)
|
||||
{
|
||||
objectiveVectorValue = _objectiveVectorValue;
|
||||
invalidObjectiveVectorValue = false;
|
||||
objectiveVectorValue = _objectiveVectorValue;
|
||||
invalidObjectiveVectorValue = false;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -119,7 +120,7 @@ public:
|
|||
*/
|
||||
void invalidateObjectiveVector()
|
||||
{
|
||||
invalidObjectiveVectorValue = true;
|
||||
invalidObjectiveVectorValue = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -127,22 +128,22 @@ public:
|
|||
* Returns true if the objective vector is invalid, false otherwise
|
||||
*/
|
||||
bool invalidObjectiveVector() const
|
||||
{
|
||||
{
|
||||
return invalidObjectiveVectorValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the fitness value of the current solution
|
||||
*/
|
||||
Fitness fitness() const
|
||||
{
|
||||
{
|
||||
if ( invalidFitness() )
|
||||
{
|
||||
{
|
||||
throw std::runtime_error("invalid fitness in MOEO");
|
||||
}
|
||||
}
|
||||
return fitnessValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -151,8 +152,8 @@ public:
|
|||
*/
|
||||
void fitness(const Fitness & _fitnessValue)
|
||||
{
|
||||
fitnessValue = _fitnessValue;
|
||||
invalidFitnessValue = false;
|
||||
fitnessValue = _fitnessValue;
|
||||
invalidFitnessValue = false;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -161,7 +162,7 @@ public:
|
|||
*/
|
||||
void invalidateFitness()
|
||||
{
|
||||
invalidFitnessValue = true;
|
||||
invalidFitnessValue = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -169,22 +170,22 @@ public:
|
|||
* Returns true if the fitness value is invalid, false otherwise
|
||||
*/
|
||||
bool invalidFitness() const
|
||||
{
|
||||
{
|
||||
return invalidFitnessValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the diversity value of the current solution
|
||||
*/
|
||||
Diversity diversity() const
|
||||
{
|
||||
{
|
||||
if ( invalidDiversity() )
|
||||
{
|
||||
{
|
||||
throw std::runtime_error("invalid diversity in MOEO");
|
||||
}
|
||||
}
|
||||
return diversityValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -193,8 +194,8 @@ public:
|
|||
*/
|
||||
void diversity(const Diversity & _diversityValue)
|
||||
{
|
||||
diversityValue = _diversityValue;
|
||||
invalidDiversityValue = false;
|
||||
diversityValue = _diversityValue;
|
||||
invalidDiversityValue = false;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -203,7 +204,7 @@ public:
|
|||
*/
|
||||
void invalidateDiversity()
|
||||
{
|
||||
invalidDiversityValue = true;
|
||||
invalidDiversityValue = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -211,9 +212,9 @@ public:
|
|||
* Returns true if the diversity value is invalid, false otherwise
|
||||
*/
|
||||
bool invalidDiversity() const
|
||||
{
|
||||
{
|
||||
return invalidDiversityValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -221,9 +222,9 @@ public:
|
|||
*/
|
||||
void invalidate()
|
||||
{
|
||||
invalidateObjectiveVector();
|
||||
invalidateFitness();
|
||||
invalidateDiversity();
|
||||
invalidateObjectiveVector();
|
||||
invalidateFitness();
|
||||
invalidateDiversity();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -231,9 +232,9 @@ public:
|
|||
* Returns true if the fitness value is invalid, false otherwise
|
||||
*/
|
||||
bool invalid() const
|
||||
{
|
||||
{
|
||||
return invalidObjectiveVector();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -243,18 +244,18 @@ public:
|
|||
* @param _other the other MOEO object to compare with
|
||||
*/
|
||||
bool operator<(const MOEO & _other) const
|
||||
{
|
||||
{
|
||||
return objectiveVector() < _other.objectiveVector();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the class id (the class name as a std::string)
|
||||
*/
|
||||
virtual std::string className() const
|
||||
{
|
||||
{
|
||||
return "MOEO";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -262,16 +263,16 @@ public:
|
|||
* @param _os output stream
|
||||
*/
|
||||
virtual void printOn(std::ostream & _os) const
|
||||
{
|
||||
{
|
||||
if ( invalidObjectiveVector() )
|
||||
{
|
||||
{
|
||||
_os << "INVALID\t";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
_os << objectiveVectorValue << '\t';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -280,23 +281,23 @@ public:
|
|||
*/
|
||||
virtual void readFrom(std::istream & _is)
|
||||
{
|
||||
std::string objectiveVector_str;
|
||||
int pos = _is.tellg();
|
||||
_is >> objectiveVector_str;
|
||||
if (objectiveVector_str == "INVALID")
|
||||
std::string objectiveVector_str;
|
||||
int pos = _is.tellg();
|
||||
_is >> objectiveVector_str;
|
||||
if (objectiveVector_str == "INVALID")
|
||||
{
|
||||
invalidateObjectiveVector();
|
||||
invalidateObjectiveVector();
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
invalidObjectiveVectorValue = false;
|
||||
_is.seekg(pos); // rewind
|
||||
_is >> objectiveVectorValue;
|
||||
invalidObjectiveVectorValue = false;
|
||||
_is.seekg(pos); // rewind
|
||||
_is >> objectiveVectorValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the objective vector of this solution */
|
||||
ObjectiveVector objectiveVectorValue;
|
||||
|
|
@ -311,6 +312,6 @@ private:
|
|||
/** true if the diversity value is invalid */
|
||||
bool invalidDiversityValue;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEO_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoBitVector.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
|
||||
class moeoBitVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: begin;
|
||||
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: end;
|
||||
|
|
@ -67,22 +67,22 @@ public:
|
|||
* Returns the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const
|
||||
{
|
||||
return "moeoBitVector";
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
return "moeoBitVector";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writing object
|
||||
* @param _os output stream
|
||||
*/
|
||||
virtual void printOn(std::ostream & _os) const
|
||||
{
|
||||
{
|
||||
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os);
|
||||
_os << ' ';
|
||||
_os << size() << ' ';
|
||||
std::copy(begin(), end(), std::ostream_iterator<bool>(_os));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -91,18 +91,18 @@ public:
|
|||
*/
|
||||
virtual void readFrom(std::istream & _is)
|
||||
{
|
||||
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is);
|
||||
unsigned int s;
|
||||
_is >> s;
|
||||
std::string bits;
|
||||
_is >> bits;
|
||||
if (_is)
|
||||
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is);
|
||||
unsigned int s;
|
||||
_is >> s;
|
||||
std::string bits;
|
||||
_is >> bits;
|
||||
if (_is)
|
||||
{
|
||||
resize(bits.size());
|
||||
std::transform(bits.begin(), bits.end(), begin(), std::bind2nd(std::equal_to<char>(), '1'));
|
||||
resize(bits.size());
|
||||
std::transform(bits.begin(), bits.end(), begin(), std::bind2nd(std::equal_to<char>(), '1'));
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOBITVECTOR_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoEvalFunc.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
* Functor that evaluates one MOEO by setting all its objective values.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoEvalFunc : public eoEvalFunc< MOEOT > {};
|
||||
class moeoEvalFunc : public eoEvalFunc< MOEOT >
|
||||
{};
|
||||
|
||||
#endif /*MOEOEVALFUNC_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoObjectiveVector.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -48,8 +48,8 @@
|
|||
*/
|
||||
template < class ObjectiveVectorTraits, class ObjectiveVectorType >
|
||||
class moeoObjectiveVector : public std::vector < ObjectiveVectorType >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The traits of objective vectors */
|
||||
typedef ObjectiveVectorTraits Traits;
|
||||
|
|
@ -79,7 +79,7 @@ public:
|
|||
*/
|
||||
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()
|
||||
{
|
||||
return ObjectiveVectorTraits::nObjectives();
|
||||
return ObjectiveVectorTraits::nObjectives();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ public:
|
|||
*/
|
||||
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)
|
||||
{
|
||||
return ObjectiveVectorTraits::maximizing(_i);
|
||||
return ObjectiveVectorTraits::maximizing(_i);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOOBJECTIVEVECTOR_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoObjectiveVectorTraits.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoObjectiveVectorTraits.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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.
|
||||
*/
|
||||
class moeoObjectiveVectorTraits
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Parameters setting
|
||||
|
|
@ -56,20 +56,21 @@ public:
|
|||
*/
|
||||
static void setup(unsigned int _nObjectives, std::vector < bool > & _bObjectives)
|
||||
{
|
||||
// in case the number of objectives was already set to a different value
|
||||
if ( nObj && (nObj != _nObjectives) ) {
|
||||
std::cout << "WARNING\n";
|
||||
std::cout << "WARNING : the number of objectives are changing\n";
|
||||
std::cout << "WARNING : Make sure all existing objects are destroyed\n";
|
||||
std::cout << "WARNING\n";
|
||||
// in case the number of objectives was already set to a different value
|
||||
if ( nObj && (nObj != _nObjectives) )
|
||||
{
|
||||
std::cout << "WARNING\n";
|
||||
std::cout << "WARNING : the number of objectives are changing\n";
|
||||
std::cout << "WARNING : Make sure all existing objects are destroyed\n";
|
||||
std::cout << "WARNING\n";
|
||||
}
|
||||
// number of objectives
|
||||
nObj = _nObjectives;
|
||||
// min/max vector
|
||||
bObj = _bObjectives;
|
||||
// in case the number of objectives and the min/max vector size don't match
|
||||
if (nObj != bObj.size())
|
||||
throw std::runtime_error("Number of objectives and min/max size don't match in moeoObjectiveVectorTraits::setup");
|
||||
// number of objectives
|
||||
nObj = _nObjectives;
|
||||
// min/max vector
|
||||
bObj = _bObjectives;
|
||||
// in case the number of objectives and the min/max vector size don't match
|
||||
if (nObj != bObj.size())
|
||||
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()
|
||||
{
|
||||
// in case the number of objectives would not be assigned yet
|
||||
if (! nObj)
|
||||
throw std::runtime_error("Number of objectives not assigned in moeoObjectiveVectorTraits");
|
||||
return nObj;
|
||||
// in case the number of objectives would not be assigned yet
|
||||
if (! nObj)
|
||||
throw std::runtime_error("Number of objectives not assigned in moeoObjectiveVectorTraits");
|
||||
return nObj;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -91,10 +92,10 @@ public:
|
|||
*/
|
||||
static bool minimizing(unsigned int _i)
|
||||
{
|
||||
// in case there would be a wrong index
|
||||
if (_i >= bObj.size())
|
||||
throw std::runtime_error("Wrong index in moeoObjectiveVectorTraits");
|
||||
return bObj[_i];
|
||||
// in case there would be a wrong index
|
||||
if (_i >= bObj.size())
|
||||
throw std::runtime_error("Wrong index in moeoObjectiveVectorTraits");
|
||||
return bObj[_i];
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -102,8 +103,9 @@ public:
|
|||
* Returns true if the _ith objective have to be maximized
|
||||
* @param _i the index
|
||||
*/
|
||||
static bool maximizing(unsigned int _i) {
|
||||
return (! minimizing(_i));
|
||||
static bool maximizing(unsigned int _i)
|
||||
{
|
||||
return (! minimizing(_i));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -112,17 +114,17 @@ public:
|
|||
*/
|
||||
static double tolerance()
|
||||
{
|
||||
return 1e-6;
|
||||
return 1e-6;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** The number of objectives */
|
||||
static unsigned int nObj;
|
||||
/** The min/max vector */
|
||||
static std::vector < bool > bObj;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOOBJECTIVEVECTORTRAITS_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoRealObjectiveVector.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -50,8 +50,8 @@
|
|||
*/
|
||||
template < class ObjectiveVectorTraits >
|
||||
class moeoRealObjectiveVector : public moeoObjectiveVector < ObjectiveVectorTraits, double >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
using moeoObjectiveVector < ObjectiveVectorTraits, double >::size;
|
||||
using moeoObjectiveVector < ObjectiveVectorTraits, double >::operator[];
|
||||
|
|
@ -77,10 +77,10 @@ public:
|
|||
* @param _other the other moeoRealObjectiveVector object to compare with
|
||||
*/
|
||||
bool dominates(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
|
||||
{
|
||||
{
|
||||
moeoParetoObjectiveVectorComparator < moeoRealObjectiveVector<ObjectiveVectorTraits> > comparator;
|
||||
return comparator(_other, *this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -88,16 +88,16 @@ public:
|
|||
* @param _other the other moeoRealObjectiveVector object to compare with
|
||||
*/
|
||||
bool operator==(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
|
||||
{
|
||||
{
|
||||
for (unsigned int i=0; i < size(); i++)
|
||||
{
|
||||
{
|
||||
if ( fabs(operator[](i) - _other[i]) > ObjectiveVectorTraits::tolerance() )
|
||||
{
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -105,9 +105,9 @@ public:
|
|||
* @param _other the other moeoRealObjectiveVector object to compare with
|
||||
*/
|
||||
bool operator!=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
|
||||
{
|
||||
{
|
||||
return ! operator==(_other);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -116,10 +116,10 @@ public:
|
|||
* @param _other the other moeoRealObjectiveVector object to compare with
|
||||
*/
|
||||
bool operator<(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
|
||||
{
|
||||
{
|
||||
moeoObjectiveObjectiveVectorComparator < moeoRealObjectiveVector < ObjectiveVectorTraits > > cmp;
|
||||
return cmp(*this, _other);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -128,9 +128,9 @@ public:
|
|||
* @param _other the other moeoRealObjectiveVector object to compare with
|
||||
*/
|
||||
bool operator>(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
|
||||
{
|
||||
{
|
||||
return _other < *this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -139,9 +139,9 @@ public:
|
|||
* @param _other the other moeoRealObjectiveVector object to compare with
|
||||
*/
|
||||
bool operator<=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
|
||||
{
|
||||
{
|
||||
return operator==(_other) || operator<(_other);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -150,11 +150,11 @@ public:
|
|||
* @param _other the other moeoRealObjectiveVector object to compare with
|
||||
*/
|
||||
bool operator>=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
|
||||
{
|
||||
{
|
||||
return operator==(_other) || operator>(_other);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -165,11 +165,11 @@ public:
|
|||
template < class ObjectiveVectorTraits >
|
||||
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 >
|
||||
std::istream & operator>>(std::istream & _is, moeoRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector)
|
||||
{
|
||||
_objectiveVector = moeoRealObjectiveVector < ObjectiveVectorTraits > ();
|
||||
for (unsigned int i=0; i<_objectiveVector.size(); i++)
|
||||
_objectiveVector = moeoRealObjectiveVector < ObjectiveVectorTraits > ();
|
||||
for (unsigned int i=0; i<_objectiveVector.size(); i++)
|
||||
{
|
||||
_is >> _objectiveVector[i];
|
||||
_is >> _objectiveVector[i];
|
||||
}
|
||||
return _is;
|
||||
return _is;
|
||||
}
|
||||
|
||||
#endif /*MOEOREALOBJECTIVEVECTOR_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoRealVector.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
|
||||
class moeoRealVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, double >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
|
|
@ -55,16 +55,16 @@ public:
|
|||
*/
|
||||
moeoRealVector(unsigned int _size = 0, double _value = 0.0) : moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, double >(_size, _value)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const
|
||||
{
|
||||
return "moeoRealVector";
|
||||
}
|
||||
|
||||
};
|
||||
{
|
||||
return "moeoRealVector";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOREALVECTOR_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoVector.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -48,8 +48,8 @@
|
|||
*/
|
||||
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType >
|
||||
class moeoVector : public MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >, public std::vector < GeneType >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
using MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity > :: invalidate;
|
||||
using std::vector < GeneType > :: operator[];
|
||||
|
|
@ -70,30 +70,30 @@ public:
|
|||
* @param _value Initial value of all elements (default is default value of type 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.
|
||||
* @param _v a vector of GeneType
|
||||
*/
|
||||
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;
|
||||
resize(_v.size());
|
||||
std::cout << "Warning: Changing size in moeoVector assignation"<<std::endl;
|
||||
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());
|
||||
invalidate();
|
||||
std::copy(_v.begin(), _v.end(), begin());
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -102,9 +102,9 @@ public:
|
|||
* @param _moeo the object to compare with
|
||||
*/
|
||||
bool operator<(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo) const
|
||||
{
|
||||
{
|
||||
return MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::operator<(_moeo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -112,12 +112,12 @@ public:
|
|||
* @param _os output stream
|
||||
*/
|
||||
virtual void printOn(std::ostream & _os) const
|
||||
{
|
||||
{
|
||||
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os);
|
||||
_os << ' ';
|
||||
_os << size() << ' ';
|
||||
std::copy(begin(), end(), std::ostream_iterator<AtomType>(_os, " "));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -126,20 +126,20 @@ public:
|
|||
*/
|
||||
virtual void readFrom(std::istream & _is)
|
||||
{
|
||||
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is);
|
||||
unsigned int sz;
|
||||
_is >> sz;
|
||||
resize(sz);
|
||||
unsigned int i;
|
||||
for (i = 0; i < sz; ++i)
|
||||
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is);
|
||||
unsigned int sz;
|
||||
_is >> sz;
|
||||
resize(sz);
|
||||
unsigned int i;
|
||||
for (i = 0; i < sz; ++i)
|
||||
{
|
||||
AtomType atom;
|
||||
_is >> atom;
|
||||
operator[](i) = atom;
|
||||
AtomType atom;
|
||||
_is >> atom;
|
||||
operator[](i) = atom;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -150,7 +150,7 @@ public:
|
|||
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)
|
||||
{
|
||||
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 >
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoDistance.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class MOEOT , class Type >
|
||||
class moeoDistance : public eoBF < const MOEOT &, const MOEOT &, const Type >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Nothing to do
|
||||
|
|
@ -74,6 +74,6 @@ public:
|
|||
virtual void setup(eoRealInterval _realInterval, unsigned int _obj)
|
||||
{}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEODISTANCE_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoDistanceMatrix.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
*/
|
||||
template < class MOEOT , class 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 > > :: operator[];
|
||||
|
|
@ -61,10 +61,10 @@ public:
|
|||
*/
|
||||
moeoDistanceMatrix (unsigned int _size, moeoDistance < MOEOT , Type > & _distance) : distance(_distance)
|
||||
{
|
||||
this->resize(_size);
|
||||
for (unsigned int i=0; i<_size; i++)
|
||||
this->resize(_size);
|
||||
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)
|
||||
{
|
||||
// 1 - setup the bounds (if necessary)
|
||||
distance.setup(_pop);
|
||||
// 2 - compute distances
|
||||
this->operator[](0).operator[](0) = Type();
|
||||
for (unsigned int i=0; i<size(); i++)
|
||||
// 1 - setup the bounds (if necessary)
|
||||
distance.setup(_pop);
|
||||
// 2 - compute distances
|
||||
this->operator[](0).operator[](0) = Type();
|
||||
for (unsigned int i=0; i<size(); i++)
|
||||
{
|
||||
this->operator[](i).operator[](i) = Type();
|
||||
for (unsigned int j=0; j<i; j++)
|
||||
this->operator[](i).operator[](i) = Type();
|
||||
for (unsigned int j=0; j<i; j++)
|
||||
{
|
||||
this->operator[](i).operator[](j) = distance(_pop[i], _pop[j]);
|
||||
this->operator[](j).operator[](i) = this->operator[](i).operator[](j);
|
||||
this->operator[](i).operator[](j) = distance(_pop[i], _pop[j]);
|
||||
this->operator[](j).operator[](i) = this->operator[](i).operator[](j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the distance to use */
|
||||
moeoDistance < MOEOT , Type > & distance;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEODISTANCEMATRIX_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoEuclideanDistance.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoEuclideanDistance : public moeoNormalizedDistance < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** the objective vector type of the solutions */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -61,23 +61,23 @@ public:
|
|||
*/
|
||||
const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
||||
{
|
||||
double result = 0.0;
|
||||
double tmp1, tmp2;
|
||||
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
|
||||
double result = 0.0;
|
||||
double tmp1, tmp2;
|
||||
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
|
||||
{
|
||||
tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
result += (tmp1-tmp2) * (tmp1-tmp2);
|
||||
tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
result += (tmp1-tmp2) * (tmp1-tmp2);
|
||||
}
|
||||
return sqrt(result);
|
||||
return sqrt(result);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the bounds for every objective */
|
||||
using moeoNormalizedDistance < MOEOT > :: bounds;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOEUCLIDEANDISTANCE_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoManhattanDistance.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoManhattanDistance : public moeoNormalizedDistance < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** the objective vector type of the solutions */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -61,23 +61,23 @@ public:
|
|||
*/
|
||||
const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
||||
{
|
||||
double result = 0.0;
|
||||
double tmp1, tmp2;
|
||||
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
|
||||
double result = 0.0;
|
||||
double tmp1, tmp2;
|
||||
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
|
||||
{
|
||||
tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
result += fabs(tmp1-tmp2);
|
||||
tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
result += fabs(tmp1-tmp2);
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the bounds for every objective */
|
||||
using moeoNormalizedDistance < MOEOT > :: bounds;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOMANHATTANDISTANCE_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoNormalizedDistance.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
*/
|
||||
template < class MOEOT , class Type = double >
|
||||
class moeoNormalizedDistance : public moeoDistance < MOEOT , Type >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** the objective vector type of the solutions */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -59,11 +59,11 @@ public:
|
|||
*/
|
||||
moeoNormalizedDistance()
|
||||
{
|
||||
bounds.resize(ObjectiveVector::Traits::nObjectives());
|
||||
// initialize bounds in case someone does not want to use them
|
||||
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
bounds.resize(ObjectiveVector::Traits::nObjectives());
|
||||
// initialize bounds in case someone does not want to use them
|
||||
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()
|
||||
{
|
||||
return 1e-6;
|
||||
return 1e-6;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -83,18 +83,18 @@ public:
|
|||
*/
|
||||
virtual void setup(const eoPop < MOEOT > & _pop)
|
||||
{
|
||||
double min, max;
|
||||
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
double min, max;
|
||||
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
{
|
||||
min = _pop[0].objectiveVector()[i];
|
||||
max = _pop[0].objectiveVector()[i];
|
||||
for (unsigned int j=1; j<_pop.size(); j++)
|
||||
min = _pop[0].objectiveVector()[i];
|
||||
max = _pop[0].objectiveVector()[i];
|
||||
for (unsigned int j=1; j<_pop.size(); j++)
|
||||
{
|
||||
min = std::min(min, _pop[j].objectiveVector()[i]);
|
||||
max = std::max(max, _pop[j].objectiveVector()[i]);
|
||||
min = std::min(min, _pop[j].objectiveVector()[i]);
|
||||
max = std::max(max, _pop[j].objectiveVector()[i]);
|
||||
}
|
||||
// setting of the bounds for the objective i
|
||||
setup(min, max, i);
|
||||
// setting of the bounds for the objective i
|
||||
setup(min, max, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,12 +107,12 @@ public:
|
|||
*/
|
||||
virtual void setup(double _min, double _max, unsigned int _obj)
|
||||
{
|
||||
if (_min == _max)
|
||||
if (_min == _max)
|
||||
{
|
||||
_min -= tiny();
|
||||
_max += tiny();
|
||||
_min -= 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)
|
||||
{
|
||||
bounds[_obj] = _realInterval;
|
||||
bounds[_obj] = _realInterval;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** the bounds for every objective (bounds[i] = bounds for the objective i) */
|
||||
std::vector < eoRealInterval > bounds;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEONORMALIZEDDISTANCE_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoCrowdingDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -48,8 +48,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoCrowdingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** the objective vector type of the solutions */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -59,18 +59,18 @@ public:
|
|||
* Returns a big value (regarded as infinite)
|
||||
*/
|
||||
double inf() const
|
||||
{
|
||||
{
|
||||
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)
|
||||
*/
|
||||
double tiny() const
|
||||
{
|
||||
{
|
||||
return 1e-6;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -79,16 +79,16 @@ public:
|
|||
*/
|
||||
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)
|
||||
{
|
||||
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
|
||||
|
|
@ -114,34 +114,34 @@ protected:
|
|||
*/
|
||||
virtual void setDistances (eoPop < MOEOT > & _pop)
|
||||
{
|
||||
double min, max, distance;
|
||||
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
|
||||
// set diversity to 0
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
double min, max, distance;
|
||||
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
|
||||
// set diversity to 0
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
{
|
||||
_pop[i].diversity(0);
|
||||
_pop[i].diversity(0);
|
||||
}
|
||||
// for each objective
|
||||
for (unsigned int obj=0; obj<nObjectives; obj++)
|
||||
// for each objective
|
||||
for (unsigned int obj=0; obj<nObjectives; obj++)
|
||||
{
|
||||
// comparator
|
||||
moeoOneObjectiveComparator < MOEOT > objComp(obj);
|
||||
// sort
|
||||
std::sort(_pop.begin(), _pop.end(), objComp);
|
||||
// min & max
|
||||
min = _pop[0].objectiveVector()[obj];
|
||||
max = _pop[_pop.size()-1].objectiveVector()[obj];
|
||||
// set the diversity value to infiny for min and max
|
||||
_pop[0].diversity(inf());
|
||||
_pop[_pop.size()-1].diversity(inf());
|
||||
for (unsigned int i=1; i<_pop.size()-1; i++)
|
||||
// comparator
|
||||
moeoOneObjectiveComparator < MOEOT > objComp(obj);
|
||||
// sort
|
||||
std::sort(_pop.begin(), _pop.end(), objComp);
|
||||
// min & max
|
||||
min = _pop[0].objectiveVector()[obj];
|
||||
max = _pop[_pop.size()-1].objectiveVector()[obj];
|
||||
// set the diversity value to infiny for min and max
|
||||
_pop[0].diversity(inf());
|
||||
_pop[_pop.size()-1].diversity(inf());
|
||||
for (unsigned int i=1; i<_pop.size()-1; i++)
|
||||
{
|
||||
distance = (_pop[i+1].objectiveVector()[obj] - _pop[i-1].objectiveVector()[obj]) / (max-min);
|
||||
_pop[i].diversity(_pop[i].diversity() + distance);
|
||||
distance = (_pop[i+1].objectiveVector()[obj] - _pop[i-1].objectiveVector()[obj]) / (max-min);
|
||||
_pop[i].diversity(_pop[i].diversity() + distance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOCROWDINGDIVERSITYASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -46,8 +46,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoDiversityAssignment : public eoUF < eoPop < MOEOT > &, void >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type for objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -68,9 +68,9 @@ public:
|
|||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo)
|
||||
{
|
||||
updateByDeleting(_pop, _moeo.objectiveVector());
|
||||
updateByDeleting(_pop, _moeo.objectiveVector());
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEODIVERSITYASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoDummyDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoDummyDiversityAssignment : public moeoDiversityAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type for objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -58,12 +58,12 @@ public:
|
|||
*/
|
||||
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
|
||||
_pop[idx].diversity(0.0);
|
||||
// set the diversity to 0
|
||||
_pop[idx].diversity(0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -76,9 +76,9 @@ public:
|
|||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
// nothing to do... ;-)
|
||||
// nothing to do... ;-)
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEODUMMYDIVERSITYASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoFrontByFrontCrowdingDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -48,8 +48,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoFrontByFrontCrowdingDiversityAssignment : public moeoCrowdingDiversityAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** the objective vector type of the solutions */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -64,11 +64,11 @@ public:
|
|||
*/
|
||||
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 >::tiny;
|
||||
|
|
@ -79,61 +79,61 @@ private:
|
|||
*/
|
||||
void setDistances (eoPop < MOEOT > & _pop)
|
||||
{
|
||||
unsigned int a,b;
|
||||
double min, max, distance;
|
||||
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
|
||||
// set diversity to 0 for every individual
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
unsigned int a,b;
|
||||
double min, max, distance;
|
||||
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
|
||||
// set diversity to 0 for every individual
|
||||
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
|
||||
moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator;
|
||||
std::sort(_pop.begin(), _pop.end(), fitnessComparator);
|
||||
// compute the crowding distance values for every individual "front" by "front" (front : from a to b)
|
||||
a = 0; // the front starts at a
|
||||
while (a < _pop.size())
|
||||
// sort the whole pop according to fitness values
|
||||
moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator;
|
||||
std::sort(_pop.begin(), _pop.end(), fitnessComparator);
|
||||
// compute the crowding distance values for every individual "front" by "front" (front : from a to b)
|
||||
a = 0; // the front starts at a
|
||||
while (a < _pop.size())
|
||||
{
|
||||
b = lastIndex(_pop,a); // the front ends at b
|
||||
// if there is less than 2 individuals in the front...
|
||||
if ((b-a) < 2)
|
||||
b = lastIndex(_pop,a); // the front ends at b
|
||||
// if there is less than 2 individuals in the front...
|
||||
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 (unsigned int obj=0; obj<nObjectives; obj++)
|
||||
// for each objective
|
||||
for (unsigned int obj=0; obj<nObjectives; obj++)
|
||||
{
|
||||
// sort in the descending order using the values of the objective 'obj'
|
||||
moeoOneObjectiveComparator < MOEOT > objComp(obj);
|
||||
std::sort(_pop.begin()+a, _pop.begin()+b+1, objComp);
|
||||
// min & max
|
||||
min = _pop[b].objectiveVector()[obj];
|
||||
max = _pop[a].objectiveVector()[obj];
|
||||
// avoid extreme case
|
||||
if (min == max)
|
||||
// sort in the descending order using the values of the objective 'obj'
|
||||
moeoOneObjectiveComparator < MOEOT > objComp(obj);
|
||||
std::sort(_pop.begin()+a, _pop.begin()+b+1, objComp);
|
||||
// min & max
|
||||
min = _pop[b].objectiveVector()[obj];
|
||||
max = _pop[a].objectiveVector()[obj];
|
||||
// avoid extreme case
|
||||
if (min == max)
|
||||
{
|
||||
min -= tiny();
|
||||
max += tiny();
|
||||
min -= tiny();
|
||||
max += tiny();
|
||||
}
|
||||
// set the diversity value to infiny for min and max
|
||||
_pop[a].diversity(inf());
|
||||
_pop[b].diversity(inf());
|
||||
// set the diversity values for the other individuals
|
||||
for (unsigned int i=a+1; i<b; i++)
|
||||
// set the diversity value to infiny for min and max
|
||||
_pop[a].diversity(inf());
|
||||
_pop[b].diversity(inf());
|
||||
// set the diversity values for the other individuals
|
||||
for (unsigned int i=a+1; i<b; i++)
|
||||
{
|
||||
distance = (_pop[i-1].objectiveVector()[obj] - _pop[i+1].objectiveVector()[obj]) / (max-min);
|
||||
_pop[i].diversity(_pop[i].diversity() + distance);
|
||||
distance = (_pop[i-1].objectiveVector()[obj] - _pop[i+1].objectiveVector()[obj]) / (max-min);
|
||||
_pop[i].diversity(_pop[i].diversity() + distance);
|
||||
}
|
||||
}
|
||||
}
|
||||
// go to the next front
|
||||
a = b+1;
|
||||
// go to the next front
|
||||
a = b+1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,14 +145,14 @@ private:
|
|||
*/
|
||||
unsigned int lastIndex (eoPop < MOEOT > & _pop, unsigned int _start)
|
||||
{
|
||||
unsigned int i=_start;
|
||||
while ( (i<_pop.size()-1) && (_pop[i].fitness()==_pop[i+1].fitness()) )
|
||||
unsigned int i=_start;
|
||||
while ( (i<_pop.size()-1) && (_pop[i].fitness()==_pop[i+1].fitness()) )
|
||||
{
|
||||
i++;
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
return i;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOFRONTBYFRONTCROWDINGDIVERSITYASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoFrontByFrontSharingDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoFrontByFrontSharingDiversityAssignment : public moeoSharingDiversityAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** the objective vector type of the solutions */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -80,11 +80,11 @@ public:
|
|||
*/
|
||||
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 >::nicheSize;
|
||||
|
|
@ -98,34 +98,34 @@ private:
|
|||
*/
|
||||
void setSimilarities(eoPop < MOEOT > & _pop)
|
||||
{
|
||||
// compute distances between every individuals
|
||||
moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
|
||||
dMatrix(_pop);
|
||||
// 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++)
|
||||
// compute distances between every individuals
|
||||
moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
|
||||
dMatrix(_pop);
|
||||
// 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 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[j][i] = nicheSize;
|
||||
dMatrix[i][j] = nicheSize;
|
||||
dMatrix[j][i] = nicheSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
// compute similarities
|
||||
double sum;
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
// compute similarities
|
||||
double sum;
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
{
|
||||
sum = 0.0;
|
||||
for (unsigned int j=0; j<_pop.size(); j++)
|
||||
sum = 0.0;
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoSharingDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -51,8 +51,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoSharingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** the objective vector type of the solutions */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -83,14 +83,14 @@ public:
|
|||
*/
|
||||
void operator()(eoPop < MOEOT > & _pop)
|
||||
{
|
||||
// 1 - set simuilarities
|
||||
setSimilarities(_pop);
|
||||
// 2 - a higher diversity is better, so the values need to be inverted
|
||||
moeoDiversityThenFitnessComparator < MOEOT > divComparator;
|
||||
double max = std::max_element(_pop.begin(), _pop.end(), divComparator)->diversity();
|
||||
for (unsigned int i=0 ; i<_pop.size() ; i++)
|
||||
// 1 - set simuilarities
|
||||
setSimilarities(_pop);
|
||||
// 2 - a higher diversity is better, so the values need to be inverted
|
||||
moeoDiversityThenFitnessComparator < MOEOT > divComparator;
|
||||
double max = std::max_element(_pop.begin(), _pop.end(), divComparator)->diversity();
|
||||
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)
|
||||
{
|
||||
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 */
|
||||
moeoDistance < MOEOT , double > & distance;
|
||||
|
|
@ -126,19 +126,19 @@ protected:
|
|||
*/
|
||||
virtual void setSimilarities(eoPop < MOEOT > & _pop)
|
||||
{
|
||||
// compute distances between every individuals
|
||||
moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
|
||||
dMatrix(_pop);
|
||||
// compute similarities
|
||||
double sum;
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
// compute distances between every individuals
|
||||
moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
|
||||
dMatrix(_pop);
|
||||
// compute similarities
|
||||
double sum;
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
{
|
||||
sum = 0.0;
|
||||
for (unsigned int j=0; j<_pop.size(); j++)
|
||||
sum = 0.0;
|
||||
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 result;
|
||||
if (_dist < nicheSize)
|
||||
double result;
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <make_checkpoint_moeo.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -66,136 +66,136 @@ bool testDirRes(std::string _dirName, bool _erase);
|
|||
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 > & checkpoint = _state.storeFunctor(new eoCheckPoint < MOEOT > (_continue));
|
||||
/* the objective vector type */
|
||||
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
|
||||
eoCheckPoint < MOEOT > & checkpoint = _state.storeFunctor(new eoCheckPoint < MOEOT > (_continue));
|
||||
/* the objective vector type */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
||||
// 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
|
||||
///////////////////
|
||||
// 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
|
||||
//-----------------------------
|
||||
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>);
|
||||
checkpoint.add(*popStat);
|
||||
popStat = & _state.storeFunctor(new eoSortedPopStat<MOEOT>);
|
||||
checkpoint.add(*popStat);
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
// State savers
|
||||
//////////////////////////////
|
||||
// feed the state to state savers
|
||||
// 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" );
|
||||
if (_parser.isItThere(saveFrequencyParam))
|
||||
//////////////////////////////////
|
||||
// State savers
|
||||
//////////////////////////////
|
||||
// feed the state to state savers
|
||||
// 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" );
|
||||
if (_parser.isItThere(saveFrequencyParam))
|
||||
{
|
||||
// first make sure dirName is OK
|
||||
if (! dirOK )
|
||||
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
|
||||
unsigned int freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX );
|
||||
// first make sure dirName is OK
|
||||
if (! dirOK )
|
||||
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
|
||||
unsigned int freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX );
|
||||
#ifdef _MSVC
|
||||
std::string stmp = dirName + "\generations";
|
||||
std::string stmp = dirName + "\generations";
|
||||
#else
|
||||
std::string stmp = dirName + "/generations";
|
||||
std::string stmp = dirName + "/generations";
|
||||
#endif
|
||||
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
|
||||
_state.storeFunctor(stateSaver1);
|
||||
checkpoint.add(*stateSaver1);
|
||||
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
|
||||
_state.storeFunctor(stateSaver1);
|
||||
checkpoint.add(*stateSaver1);
|
||||
}
|
||||
// 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" );
|
||||
if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0)
|
||||
// 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" );
|
||||
if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0)
|
||||
{
|
||||
// first make sure dirName is OK
|
||||
if (! dirOK )
|
||||
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
|
||||
// first make sure dirName is OK
|
||||
if (! dirOK )
|
||||
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
|
||||
#ifdef _MSVC
|
||||
std::string stmp = dirName + "\time";
|
||||
std::string stmp = dirName + "\time";
|
||||
#else
|
||||
std::string stmp = dirName + "/time";
|
||||
std::string stmp = dirName + "/time";
|
||||
#endif
|
||||
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
|
||||
_state.storeFunctor(stateSaver2);
|
||||
checkpoint.add(*stateSaver2);
|
||||
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
|
||||
_state.storeFunctor(stateSaver2);
|
||||
checkpoint.add(*stateSaver2);
|
||||
}
|
||||
|
||||
///////////////////
|
||||
// Archive
|
||||
//////////////////
|
||||
// update the archive every generation
|
||||
bool updateArch = _parser.getORcreateParam(true, "updateArch", "Update the archive at each gen.", '\0', "Evolution Engine").value();
|
||||
if (updateArch)
|
||||
///////////////////
|
||||
// Archive
|
||||
//////////////////
|
||||
// update the archive every generation
|
||||
bool updateArch = _parser.getORcreateParam(true, "updateArch", "Update the archive at each gen.", '\0', "Evolution Engine").value();
|
||||
if (updateArch)
|
||||
{
|
||||
moeoArchiveUpdater < MOEOT > * updater = new moeoArchiveUpdater < MOEOT > (_archive, _pop);
|
||||
_state.storeFunctor(updater);
|
||||
checkpoint.add(*updater);
|
||||
moeoArchiveUpdater < MOEOT > * updater = new moeoArchiveUpdater < MOEOT > (_archive, _pop);
|
||||
_state.storeFunctor(updater);
|
||||
checkpoint.add(*updater);
|
||||
}
|
||||
// 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();
|
||||
if (storeArch)
|
||||
// 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();
|
||||
if (storeArch)
|
||||
{
|
||||
if (! dirOK )
|
||||
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
|
||||
if (! dirOK )
|
||||
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
|
||||
#ifdef _MSVC
|
||||
std::string stmp = dirName + "\arch";
|
||||
std::string stmp = dirName + "\arch";
|
||||
#else
|
||||
std::string stmp = dirName + "/arch";
|
||||
std::string stmp = dirName + "/arch";
|
||||
#endif
|
||||
moeoArchiveObjectiveVectorSavingUpdater < MOEOT > * save_updater = new moeoArchiveObjectiveVectorSavingUpdater < MOEOT > (_archive, stmp);
|
||||
_state.storeFunctor(save_updater);
|
||||
checkpoint.add(*save_updater);
|
||||
moeoArchiveObjectiveVectorSavingUpdater < MOEOT > * save_updater = new moeoArchiveObjectiveVectorSavingUpdater < MOEOT > (_archive, stmp);
|
||||
_state.storeFunctor(save_updater);
|
||||
checkpoint.add(*save_updater);
|
||||
}
|
||||
// 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();
|
||||
if (cont)
|
||||
// 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();
|
||||
if (cont)
|
||||
{
|
||||
if (! dirOK )
|
||||
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
|
||||
if (! dirOK )
|
||||
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
|
||||
#ifdef _MSVC
|
||||
std::string stmp = dirName + "\contribution";
|
||||
std::string stmp = dirName + "\contribution";
|
||||
#else
|
||||
std::string stmp = dirName + "/contribution";
|
||||
std::string stmp = dirName + "/contribution";
|
||||
#endif
|
||||
moeoContributionMetric < ObjectiveVector > * contribution = new moeoContributionMetric < ObjectiveVector >;
|
||||
moeoBinaryMetricSavingUpdater < MOEOT > * contribution_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*contribution, _archive, stmp);
|
||||
_state.storeFunctor(contribution_updater);
|
||||
checkpoint.add(*contribution_updater);
|
||||
moeoContributionMetric < ObjectiveVector > * contribution = new moeoContributionMetric < ObjectiveVector >;
|
||||
moeoBinaryMetricSavingUpdater < MOEOT > * contribution_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*contribution, _archive, stmp);
|
||||
_state.storeFunctor(contribution_updater);
|
||||
checkpoint.add(*contribution_updater);
|
||||
}
|
||||
// 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();
|
||||
if (ent)
|
||||
// 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();
|
||||
if (ent)
|
||||
{
|
||||
if (! dirOK )
|
||||
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
|
||||
if (! dirOK )
|
||||
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
|
||||
#ifdef _MSVC
|
||||
std::string stmp = dirName + "\entropy";
|
||||
std::string stmp = dirName + "\entropy";
|
||||
#else
|
||||
std::string stmp = dirName + "/entropy";
|
||||
std::string stmp = dirName + "/entropy";
|
||||
#endif
|
||||
moeoEntropyMetric < ObjectiveVector > * entropy = new moeoEntropyMetric < ObjectiveVector >;
|
||||
moeoBinaryMetricSavingUpdater < MOEOT > * entropy_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*entropy, _archive, stmp);
|
||||
_state.storeFunctor(entropy_updater);
|
||||
checkpoint.add(*entropy_updater);
|
||||
moeoEntropyMetric < ObjectiveVector > * entropy = new moeoEntropyMetric < ObjectiveVector >;
|
||||
moeoBinaryMetricSavingUpdater < MOEOT > * entropy_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*entropy, _archive, stmp);
|
||||
_state.storeFunctor(entropy_updater);
|
||||
checkpoint.add(*entropy_updater);
|
||||
}
|
||||
|
||||
// and that's it for the (control and) output
|
||||
return checkpoint;
|
||||
// and that's it for the (control and) output
|
||||
return checkpoint;
|
||||
}
|
||||
|
||||
#endif /*MAKE_CHECKPOINT_MOEO_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <make_continue_moeo.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -58,11 +58,11 @@
|
|||
template <class MOEOT>
|
||||
eoCombinedContinue<MOEOT> * make_combinedContinue(eoCombinedContinue<MOEOT> *_combined, eoContinue<MOEOT> *_cont)
|
||||
{
|
||||
if (_combined) // already exists
|
||||
_combined->add(*_cont);
|
||||
else
|
||||
_combined = new eoCombinedContinue<MOEOT>(*_cont);
|
||||
return _combined;
|
||||
if (_combined) // already exists
|
||||
_combined->add(*_cont);
|
||||
else
|
||||
_combined = new eoCombinedContinue<MOEOT>(*_cont);
|
||||
return _combined;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -75,57 +75,57 @@ eoCombinedContinue<MOEOT> * make_combinedContinue(eoCombinedContinue<MOEOT> *_co
|
|||
template <class MOEOT>
|
||||
eoContinue<MOEOT> & do_make_continue_moeo(eoParser& _parser, eoState& _state, eoEvalFuncCounter<MOEOT> & _eval)
|
||||
{
|
||||
// the combined continue - to be filled
|
||||
eoCombinedContinue<MOEOT> *continuator = NULL;
|
||||
// First the eoGenContinue - need a default value so you can run blind
|
||||
// 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");
|
||||
if (maxGenParam.value()) // positive: -> define and store
|
||||
// the combined continue - to be filled
|
||||
eoCombinedContinue<MOEOT> *continuator = NULL;
|
||||
// First the eoGenContinue - need a default value so you can run blind
|
||||
// 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");
|
||||
if (maxGenParam.value()) // positive: -> define and store
|
||||
{
|
||||
eoGenContinue<MOEOT> *genCont = new eoGenContinue<MOEOT>(maxGenParam.value());
|
||||
_state.storeFunctor(genCont);
|
||||
// and "add" to combined
|
||||
continuator = make_combinedContinue<MOEOT>(continuator, genCont);
|
||||
eoGenContinue<MOEOT> *genCont = new eoGenContinue<MOEOT>(maxGenParam.value());
|
||||
_state.storeFunctor(genCont);
|
||||
// and "add" to combined
|
||||
continuator = make_combinedContinue<MOEOT>(continuator, genCont);
|
||||
}
|
||||
// maxEval
|
||||
eoValueParam<unsigned long>& maxEvalParam = _parser.getORcreateParam((unsigned long)(0), "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion");
|
||||
if (maxEvalParam.value())
|
||||
// maxEval
|
||||
eoValueParam<unsigned long>& maxEvalParam = _parser.getORcreateParam((unsigned long)(0), "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion");
|
||||
if (maxEvalParam.value())
|
||||
{
|
||||
eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value());
|
||||
_state.storeFunctor(evalCont);
|
||||
// and "add" to combined
|
||||
continuator = make_combinedContinue<MOEOT>(continuator, evalCont);
|
||||
eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value());
|
||||
_state.storeFunctor(evalCont);
|
||||
// and "add" to combined
|
||||
continuator = make_combinedContinue<MOEOT>(continuator, evalCont);
|
||||
}
|
||||
// maxTime
|
||||
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
|
||||
// maxTime
|
||||
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
|
||||
{
|
||||
eoTimeContinue<MOEOT> *timeCont = new eoTimeContinue<MOEOT>(maxTimeParam.value());
|
||||
_state.storeFunctor(timeCont);
|
||||
// and "add" to combined
|
||||
continuator = make_combinedContinue<MOEOT>(continuator, timeCont);
|
||||
eoTimeContinue<MOEOT> *timeCont = new eoTimeContinue<MOEOT>(maxTimeParam.value());
|
||||
_state.storeFunctor(timeCont);
|
||||
// and "add" to combined
|
||||
continuator = make_combinedContinue<MOEOT>(continuator, timeCont);
|
||||
}
|
||||
// CtrlC
|
||||
// CtrlC
|
||||
#ifndef _MSC_VER
|
||||
// the CtrlC interception (Linux only I'm afraid)
|
||||
eoCtrlCContinue<MOEOT> *ctrlCCont;
|
||||
eoValueParam<bool>& ctrlCParam = _parser.createParam(true, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion");
|
||||
if (_parser.isItThere(ctrlCParam))
|
||||
// the CtrlC interception (Linux only I'm afraid)
|
||||
eoCtrlCContinue<MOEOT> *ctrlCCont;
|
||||
eoValueParam<bool>& ctrlCParam = _parser.createParam(true, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion");
|
||||
if (_parser.isItThere(ctrlCParam))
|
||||
{
|
||||
ctrlCCont = new eoCtrlCContinue<MOEOT>;
|
||||
// store
|
||||
_state.storeFunctor(ctrlCCont);
|
||||
// add to combinedContinue
|
||||
continuator = make_combinedContinue<MOEOT>(continuator, ctrlCCont);
|
||||
ctrlCCont = new eoCtrlCContinue<MOEOT>;
|
||||
// store
|
||||
_state.storeFunctor(ctrlCCont);
|
||||
// add to combinedContinue
|
||||
continuator = make_combinedContinue<MOEOT>(continuator, ctrlCCont);
|
||||
}
|
||||
#endif
|
||||
// now check that there is at least one!
|
||||
if (!continuator)
|
||||
throw std::runtime_error("You MUST provide a stopping criterion");
|
||||
// OK, it's there: store in the eoState
|
||||
_state.storeFunctor(continuator);
|
||||
// and return
|
||||
return *continuator;
|
||||
// now check that there is at least one!
|
||||
if (!continuator)
|
||||
throw std::runtime_error("You MUST provide a stopping criterion");
|
||||
// OK, it's there: store in the eoState
|
||||
_state.storeFunctor(continuator);
|
||||
// and return
|
||||
return *continuator;
|
||||
}
|
||||
|
||||
#endif /*MAKE_CONTINUE_MOEO_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <make_ea_moeo.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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)
|
||||
{
|
||||
|
||||
/* the objective vector type */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
/* the objective vector type */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
||||
|
||||
/* the fitness assignment strategy */
|
||||
std::string & fitnessParam = _parser.createParam(std::string("FastNonDominatedSorting"), "fitness",
|
||||
"Fitness assignment scheme: Dummy, FastNonDominatedSorting or IndicatorBased", 'F',
|
||||
"Evolution Engine").value();
|
||||
std::string & indicatorParam = _parser.createParam(std::string("Epsilon"), "indicator",
|
||||
"Binary indicator for IndicatorBased: Epsilon, Hypervolume", 'i',
|
||||
"Evolution Engine").value();
|
||||
double rho = _parser.createParam(1.1, "rho", "reference point for the hypervolume indicator", 'r',
|
||||
/* the fitness assignment strategy */
|
||||
std::string & fitnessParam = _parser.createParam(std::string("FastNonDominatedSorting"), "fitness",
|
||||
"Fitness assignment scheme: Dummy, FastNonDominatedSorting or IndicatorBased", 'F',
|
||||
"Evolution Engine").value();
|
||||
std::string & indicatorParam = _parser.createParam(std::string("Epsilon"), "indicator",
|
||||
"Binary indicator for IndicatorBased: Epsilon, Hypervolume", 'i',
|
||||
"Evolution Engine").value();
|
||||
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();
|
||||
double kappa = _parser.createParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", 'k',
|
||||
"Evolution Engine").value();
|
||||
moeoFitnessAssignment < MOEOT > * fitnessAssignment;
|
||||
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
|
||||
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric;
|
||||
if (indicatorParam == std::string("Epsilon"))
|
||||
// metric
|
||||
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric;
|
||||
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;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam;
|
||||
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;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
}
|
||||
_state.storeFunctor(fitnessAssignment);
|
||||
_state.storeFunctor(fitnessAssignment);
|
||||
|
||||
|
||||
/* the diversity assignment strategy */
|
||||
eoValueParam<eoParamParamType> & diversityParam = _parser.createParam(eoParamParamType("Dummy"), "diversity",
|
||||
"Diversity assignment scheme: Dummy, Sharing(nicheSize) or Crowding", 'D', "Evolution Engine");
|
||||
eoParamParamType & diversityParamValue = diversityParam.value();
|
||||
moeoDiversityAssignment < MOEOT > * diversityAssignment;
|
||||
if (diversityParamValue.first == std::string("Dummy"))
|
||||
/* the diversity assignment strategy */
|
||||
eoValueParam<eoParamParamType> & diversityParam = _parser.createParam(eoParamParamType("Dummy"), "diversity",
|
||||
"Diversity assignment scheme: Dummy, Sharing(nicheSize) or Crowding", 'D', "Evolution Engine");
|
||||
eoParamParamType & diversityParamValue = diversityParam.value();
|
||||
moeoDiversityAssignment < MOEOT > * diversityAssignment;
|
||||
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;
|
||||
if (!diversityParamValue.second.size()) // no parameter added
|
||||
double nicheSize;
|
||||
if (!diversityParamValue.second.size()) // no parameter added
|
||||
{
|
||||
std::cerr << "WARNING, no niche size given for Sharing, using 0.5" << std::endl;
|
||||
nicheSize = 0.5;
|
||||
diversityParamValue.second.push_back(std::string("0.5"));
|
||||
std::cerr << "WARNING, no niche size given for Sharing, using 0.5" << std::endl;
|
||||
nicheSize = 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;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
std::string stmp = std::string("Invalid diversity assignment strategy: ") + diversityParamValue.first;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
}
|
||||
_state.storeFunctor(diversityAssignment);
|
||||
_state.storeFunctor(diversityAssignment);
|
||||
|
||||
|
||||
/* the comparator strategy */
|
||||
std::string & comparatorParam = _parser.createParam(std::string("FitnessThenDiversity"), "comparator",
|
||||
"Comparator scheme: FitnessThenDiversity, DiversityThenFitness or Aggregative", 'C', "Evolution Engine").value();
|
||||
moeoComparator < MOEOT > * comparator;
|
||||
if (comparatorParam == std::string("FitnessThenDiversity"))
|
||||
/* the comparator strategy */
|
||||
std::string & comparatorParam = _parser.createParam(std::string("FitnessThenDiversity"), "comparator",
|
||||
"Comparator scheme: FitnessThenDiversity, DiversityThenFitness or Aggregative", 'C', "Evolution Engine").value();
|
||||
moeoComparator < MOEOT > * comparator;
|
||||
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;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
std::string stmp = std::string("Invalid comparator strategy: ") + comparatorParam;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
}
|
||||
_state.storeFunctor(comparator);
|
||||
_state.storeFunctor(comparator);
|
||||
|
||||
|
||||
/* the selection strategy */
|
||||
eoValueParam < eoParamParamType > & selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection",
|
||||
"Selection scheme: DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine");
|
||||
eoParamParamType & ppSelect = selectionParam.value();
|
||||
moeoSelectOne < MOEOT > * select;
|
||||
if (ppSelect.first == std::string("DetTour"))
|
||||
/* the selection strategy */
|
||||
eoValueParam < eoParamParamType > & selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection",
|
||||
"Selection scheme: DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine");
|
||||
eoParamParamType & ppSelect = selectionParam.value();
|
||||
moeoSelectOne < MOEOT > * select;
|
||||
if (ppSelect.first == std::string("DetTour"))
|
||||
{
|
||||
unsigned int tSize;
|
||||
if (!ppSelect.second.size()) // no parameter added
|
||||
unsigned int tSize;
|
||||
if (!ppSelect.second.size()) // no parameter added
|
||||
{
|
||||
std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl;
|
||||
tSize = 2;
|
||||
// put back 2 in parameter for consistency (and status file)
|
||||
ppSelect.second.push_back(std::string("2"));
|
||||
std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl;
|
||||
tSize = 2;
|
||||
// put back 2 in parameter for consistency (and status file)
|
||||
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;
|
||||
if (!ppSelect.second.size()) // no parameter added
|
||||
double tRate;
|
||||
if (!ppSelect.second.size()) // no parameter added
|
||||
{
|
||||
std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl;
|
||||
tRate = 1;
|
||||
// put back 1 in parameter for consistency (and status file)
|
||||
ppSelect.second.push_back(std::string("1"));
|
||||
std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl;
|
||||
tRate = 1;
|
||||
// put back 1 in parameter for consistency (and status file)
|
||||
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 if (ppSelect.first == std::string("Random"))
|
||||
else
|
||||
{
|
||||
select = new moeoRandomSelect <MOEOT > ();
|
||||
std::string stmp = std::string("Invalid selection strategy: ") + ppSelect.first;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string stmp = std::string("Invalid selection strategy: ") + ppSelect.first;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
}
|
||||
_state.storeFunctor(select);
|
||||
_state.storeFunctor(select);
|
||||
|
||||
|
||||
/* the replacement strategy */
|
||||
std::string & replacementParam = _parser.createParam(std::string("Elitist"), "replacement",
|
||||
"Replacement scheme: Elitist, Environmental or Generational", 'R', "Evolution Engine").value();
|
||||
moeoReplacement < MOEOT > * replace;
|
||||
if (replacementParam == std::string("Elitist"))
|
||||
/* the replacement strategy */
|
||||
std::string & replacementParam = _parser.createParam(std::string("Elitist"), "replacement",
|
||||
"Replacement scheme: Elitist, Environmental or Generational", 'R', "Evolution Engine").value();
|
||||
moeoReplacement < MOEOT > * replace;
|
||||
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;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
std::string stmp = std::string("Invalid replacement strategy: ") + replacementParam;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
}
|
||||
_state.storeFunctor(replace);
|
||||
_state.storeFunctor(replace);
|
||||
|
||||
|
||||
/* the number of offspring */
|
||||
eoValueParam < eoHowMany > & offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring",
|
||||
"Number of offspring (percentage or absolute)", 'O', "Evolution Engine");
|
||||
/* the number of offspring */
|
||||
eoValueParam < eoHowMany > & offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring",
|
||||
"Number of offspring (percentage or absolute)", 'O', "Evolution Engine");
|
||||
|
||||
|
||||
// the general breeder
|
||||
eoGeneralBreeder < MOEOT > * breed = new eoGeneralBreeder < MOEOT > (*select, _op, offspringRateParam.value());
|
||||
_state.storeFunctor(breed);
|
||||
// the eoEasyEA
|
||||
moeoEA < MOEOT > * algo = new moeoEasyEA < MOEOT > (_continue, _eval, *breed, *replace, *fitnessAssignment, *diversityAssignment);
|
||||
_state.storeFunctor(algo);
|
||||
return *algo;
|
||||
// the general breeder
|
||||
eoGeneralBreeder < MOEOT > * breed = new eoGeneralBreeder < MOEOT > (*select, _op, offspringRateParam.value());
|
||||
_state.storeFunctor(breed);
|
||||
// the eoEasyEA
|
||||
moeoEA < MOEOT > * algo = new moeoEasyEA < MOEOT > (_continue, _eval, *breed, *replace, *fitnessAssignment, *diversityAssignment);
|
||||
_state.storeFunctor(algo);
|
||||
return *algo;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <make_ls_moeo.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -67,80 +67,81 @@
|
|||
*/
|
||||
template < class MOEOT, class Move >
|
||||
moeoLS < MOEOT, eoPop<MOEOT> & > & do_make_ls_moeo (
|
||||
eoParser & _parser,
|
||||
eoState & _state,
|
||||
eoEvalFunc < MOEOT > & _eval,
|
||||
moeoMoveIncrEval < Move > & _moveIncrEval,
|
||||
eoContinue < MOEOT > & _continue,
|
||||
eoMonOp < MOEOT > & _op,
|
||||
eoMonOp < MOEOT > & _opInit,
|
||||
moMoveInit < Move > & _moveInit,
|
||||
moNextMove < Move > & _nextMove,
|
||||
moeoArchive < MOEOT > & _archive
|
||||
eoParser & _parser,
|
||||
eoState & _state,
|
||||
eoEvalFunc < MOEOT > & _eval,
|
||||
moeoMoveIncrEval < Move > & _moveIncrEval,
|
||||
eoContinue < MOEOT > & _continue,
|
||||
eoMonOp < MOEOT > & _op,
|
||||
eoMonOp < MOEOT > & _opInit,
|
||||
moMoveInit < Move > & _moveInit,
|
||||
moNextMove < Move > & _nextMove,
|
||||
moeoArchive < MOEOT > & _archive
|
||||
)
|
||||
{
|
||||
/* the objective vector type */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
/* the fitness assignment strategy */
|
||||
std::string & fitnessParam = _parser.getORcreateParam(std::string("IndicatorBased"), "fitness",
|
||||
"Fitness assignment strategy parameter: IndicatorBased...", 'F',
|
||||
"Evolution Engine").value();
|
||||
std::string & indicatorParam = _parser.getORcreateParam(std::string("Epsilon"), "indicator",
|
||||
"Binary indicator to use with the IndicatorBased assignment: Epsilon, Hypervolume", 'i',
|
||||
"Evolution Engine").value();
|
||||
double rho = _parser.getORcreateParam(1.1, "rho", "reference point for the hypervolume indicator",
|
||||
'r', "Evolution Engine").value();
|
||||
double kappa = _parser.getORcreateParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased",
|
||||
'k', "Evolution Engine").value();
|
||||
moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > * fitnessAssignment;
|
||||
if (fitnessParam == std::string("IndicatorBased"))
|
||||
/* the objective vector type */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
/* the fitness assignment strategy */
|
||||
std::string & fitnessParam = _parser.getORcreateParam(std::string("IndicatorBased"), "fitness",
|
||||
"Fitness assignment strategy parameter: IndicatorBased...", 'F',
|
||||
"Evolution Engine").value();
|
||||
std::string & indicatorParam = _parser.getORcreateParam(std::string("Epsilon"), "indicator",
|
||||
"Binary indicator to use with the IndicatorBased assignment: Epsilon, Hypervolume", 'i',
|
||||
"Evolution Engine").value();
|
||||
double rho = _parser.getORcreateParam(1.1, "rho", "reference point for the hypervolume indicator",
|
||||
'r', "Evolution Engine").value();
|
||||
double kappa = _parser.getORcreateParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased",
|
||||
'k', "Evolution Engine").value();
|
||||
moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > * fitnessAssignment;
|
||||
if (fitnessParam == std::string("IndicatorBased"))
|
||||
{
|
||||
// metric
|
||||
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric;
|
||||
if (indicatorParam == std::string("Epsilon"))
|
||||
// metric
|
||||
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric;
|
||||
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;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam;
|
||||
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;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
}
|
||||
_state.storeFunctor(fitnessAssignment);
|
||||
// number of iterations
|
||||
unsigned int n = _parser.getORcreateParam(1, "n", "Number of iterations for population Initialization", 'n', "Evolution Engine").value();
|
||||
// LS
|
||||
std::string & lsParam = _parser.getORcreateParam(std::string("I-IBMOLS"), "ls",
|
||||
"Local Search: IBMOLS, I-IBMOLS (Iterated-IBMOLS)...", 'L',
|
||||
"Evolution Engine").value();
|
||||
moeoLS < MOEOT, eoPop<MOEOT> & > * ls;
|
||||
if (lsParam == std::string("IBMOLS"))
|
||||
_state.storeFunctor(fitnessAssignment);
|
||||
// number of iterations
|
||||
unsigned int n = _parser.getORcreateParam(1, "n", "Number of iterations for population Initialization", 'n', "Evolution Engine").value();
|
||||
// LS
|
||||
std::string & lsParam = _parser.getORcreateParam(std::string("I-IBMOLS"), "ls",
|
||||
"Local Search: IBMOLS, I-IBMOLS (Iterated-IBMOLS)...", 'L',
|
||||
"Evolution Engine").value();
|
||||
moeoLS < MOEOT, eoPop<MOEOT> & > * ls;
|
||||
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;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam;
|
||||
throw std::runtime_error(stmp.c_str());
|
||||
}
|
||||
_state.storeFunctor(ls);
|
||||
// that's it !
|
||||
return *ls;
|
||||
_state.storeFunctor(ls);
|
||||
// that's it !
|
||||
return *ls;
|
||||
}
|
||||
|
||||
#endif /*MAKE_LS_MOEO_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoAchievementFitnessAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoAchievementFitnessAssignment : public moeoScalarFitnessAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** the objective vector type of the solutions */
|
||||
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)
|
||||
{
|
||||
// consistency check
|
||||
if ((spn < 0.0) || (spn > 1.0))
|
||||
// consistency check
|
||||
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";
|
||||
spn = 0.0001;
|
||||
std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n";
|
||||
spn = 0.0001;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -78,17 +78,17 @@ public:
|
|||
*/
|
||||
moeoAchievementFitnessAssignment(ObjectiveVector & _reference, double _spn=0.0001) : reference(_reference), spn(_spn)
|
||||
{
|
||||
// compute the default values for lambdas
|
||||
lambdas = std::vector < double > (ObjectiveVector::nObjectives());
|
||||
for (unsigned int i=0 ; i<lambdas.size(); i++)
|
||||
// compute the default values for lambdas
|
||||
lambdas = std::vector < double > (ObjectiveVector::nObjectives());
|
||||
for (unsigned int i=0 ; i<lambdas.size(); i++)
|
||||
{
|
||||
lambdas[i] = 1.0 / ObjectiveVector::nObjectives();
|
||||
lambdas[i] = 1.0 / ObjectiveVector::nObjectives();
|
||||
}
|
||||
// consistency check
|
||||
if ((spn < 0.0) || (spn > 1.0))
|
||||
// consistency check
|
||||
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";
|
||||
spn = 0.0001;
|
||||
std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n";
|
||||
spn = 0.0001;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,9 +99,9 @@ public:
|
|||
*/
|
||||
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)
|
||||
{
|
||||
// nothing to do ;-)
|
||||
// nothing to do ;-)
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -123,11 +123,11 @@ public:
|
|||
*/
|
||||
void setReference(const ObjectiveVector & _reference)
|
||||
{
|
||||
reference = _reference;
|
||||
reference = _reference;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the reference point */
|
||||
ObjectiveVector reference;
|
||||
|
|
@ -141,9 +141,9 @@ private:
|
|||
* Returns a big value (regarded as infinite)
|
||||
*/
|
||||
double inf() const
|
||||
{
|
||||
{
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -152,19 +152,19 @@ private:
|
|||
*/
|
||||
void compute(MOEOT & _moeo)
|
||||
{
|
||||
unsigned int nobj = MOEOT::ObjectiveVector::nObjectives();
|
||||
double temp;
|
||||
double min = inf();
|
||||
double sum = 0;
|
||||
for (unsigned int obj=0; obj<nobj; obj++)
|
||||
unsigned int nobj = MOEOT::ObjectiveVector::nObjectives();
|
||||
double temp;
|
||||
double min = inf();
|
||||
double sum = 0;
|
||||
for (unsigned int obj=0; obj<nobj; obj++)
|
||||
{
|
||||
temp = lambdas[obj] * (reference[obj] - _moeo.objectiveVector()[obj]);
|
||||
min = std::min(min, temp);
|
||||
sum += temp;
|
||||
temp = lambdas[obj] * (reference[obj] - _moeo.objectiveVector()[obj]);
|
||||
min = std::min(min, temp);
|
||||
sum += temp;
|
||||
}
|
||||
_moeo.fitness(min + spn*sum);
|
||||
_moeo.fitness(min + spn*sum);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOACHIEVEMENTFITNESSASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoBinaryIndicatorBasedFitnessAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoBinaryIndicatorBasedFitnessAssignment : public moeoIndicatorBasedFitnessAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type for objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -60,6 +60,6 @@ public:
|
|||
*/
|
||||
virtual double updateByAdding(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) = 0;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoCriterionBasedFitnessAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
* moeoCriterionBasedFitnessAssignment is a moeoFitnessAssignment for criterion-based strategies.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoCriterionBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > {};
|
||||
class moeoCriterionBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
|
||||
{};
|
||||
|
||||
#endif /*MOEOCRITERIONBASEDFITNESSASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoDummyFitnessAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoDummyFitnessAssignment : public moeoFitnessAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type for objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -58,12 +58,12 @@ public:
|
|||
*/
|
||||
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
|
||||
_pop[idx].fitness(0.0);
|
||||
// set the diversity to 0
|
||||
_pop[idx].fitness(0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -76,9 +76,9 @@ public:
|
|||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
// nothing to do... ;-)
|
||||
// nothing to do... ;-)
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEODUMMYFITNESSASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoExpBinaryIndicatorBasedFitnessAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -52,8 +52,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorBasedFitnessAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type of objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -74,12 +74,12 @@ public:
|
|||
*/
|
||||
void operator()(eoPop < MOEOT > & _pop)
|
||||
{
|
||||
// 1 - setting of the bounds
|
||||
setup(_pop);
|
||||
// 2 - computing every indicator values
|
||||
computeValues(_pop);
|
||||
// 3 - setting fitnesses
|
||||
setFitnesses(_pop);
|
||||
// 1 - setting of the bounds
|
||||
setup(_pop);
|
||||
// 2 - computing every indicator values
|
||||
computeValues(_pop);
|
||||
// 3 - setting fitnesses
|
||||
setFitnesses(_pop);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -90,15 +90,15 @@ public:
|
|||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
std::vector < double > v;
|
||||
v.resize(_pop.size());
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
std::vector < double > v;
|
||||
v.resize(_pop.size());
|
||||
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)
|
||||
{
|
||||
std::vector < double > v;
|
||||
// update every fitness values to take the new individual into account
|
||||
v.resize(_pop.size());
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
std::vector < double > v;
|
||||
// update every fitness values to take the new individual into account
|
||||
v.resize(_pop.size());
|
||||
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
|
||||
v.clear();
|
||||
v.resize(_pop.size());
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
// compute the fitness of the new individual
|
||||
v.clear();
|
||||
v.resize(_pop.size());
|
||||
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;
|
||||
for (unsigned int i=0; i<v.size(); i++)
|
||||
double result = 0;
|
||||
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 */
|
||||
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & metric;
|
||||
|
|
@ -154,18 +154,18 @@ protected:
|
|||
*/
|
||||
void setup(const eoPop < MOEOT > & _pop)
|
||||
{
|
||||
double min, max;
|
||||
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
double min, max;
|
||||
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
{
|
||||
min = _pop[0].objectiveVector()[i];
|
||||
max = _pop[0].objectiveVector()[i];
|
||||
for (unsigned int j=1; j<_pop.size(); j++)
|
||||
min = _pop[0].objectiveVector()[i];
|
||||
max = _pop[0].objectiveVector()[i];
|
||||
for (unsigned int j=1; j<_pop.size(); j++)
|
||||
{
|
||||
min = std::min(min, _pop[j].objectiveVector()[i]);
|
||||
max = std::max(max, _pop[j].objectiveVector()[i]);
|
||||
min = std::min(min, _pop[j].objectiveVector()[i]);
|
||||
max = std::max(max, _pop[j].objectiveVector()[i]);
|
||||
}
|
||||
// setting of the bounds for the objective i
|
||||
metric.setup(min, max, i);
|
||||
// setting of the bounds for the objective i
|
||||
metric.setup(min, max, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -176,16 +176,16 @@ protected:
|
|||
*/
|
||||
void computeValues(const eoPop < MOEOT > & _pop)
|
||||
{
|
||||
values.clear();
|
||||
values.resize(_pop.size());
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
values.clear();
|
||||
values.resize(_pop.size());
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
{
|
||||
values[i].resize(_pop.size());
|
||||
for (unsigned int j=0; j<_pop.size(); j++)
|
||||
values[i].resize(_pop.size());
|
||||
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)
|
||||
{
|
||||
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 result = 0;
|
||||
for (unsigned int i=0; i<values.size(); i++)
|
||||
double result = 0;
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoFastNonDominatedSortingFitnessAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -55,8 +55,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoFastNonDominatedSortingFitnessAssignment : public moeoParetoBasedFitnessAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** the objective vector type of the solutions */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -83,37 +83,37 @@ public:
|
|||
*/
|
||||
void operator()(eoPop < MOEOT > & _pop)
|
||||
{
|
||||
// number of objectives for the problem under consideration
|
||||
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
|
||||
if (nObjectives == 1)
|
||||
// number of objectives for the problem under consideration
|
||||
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
|
||||
if (nObjectives == 1)
|
||||
{
|
||||
// one objective
|
||||
oneObjective(_pop);
|
||||
// one objective
|
||||
oneObjective(_pop);
|
||||
}
|
||||
else if (nObjectives == 2)
|
||||
else if (nObjectives == 2)
|
||||
{
|
||||
// two objectives (the two objectives function is still to implement)
|
||||
mObjectives(_pop);
|
||||
// two objectives (the two objectives function is still to implement)
|
||||
mObjectives(_pop);
|
||||
}
|
||||
else if (nObjectives > 2)
|
||||
else if (nObjectives > 2)
|
||||
{
|
||||
// more than two objectives
|
||||
mObjectives(_pop);
|
||||
// more than two objectives
|
||||
mObjectives(_pop);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
// problem with the number of objectives
|
||||
throw std::runtime_error("Problem with the number of objectives in moeoNonDominatedSortingFitnessAssignment");
|
||||
// problem with the number of objectives
|
||||
throw std::runtime_error("Problem with the number of objectives in moeoNonDominatedSortingFitnessAssignment");
|
||||
}
|
||||
// a higher fitness is better, so the values need to be inverted
|
||||
double max = _pop[0].fitness();
|
||||
for (unsigned int i=1 ; i<_pop.size() ; i++)
|
||||
// a higher fitness is better, so the values need to be inverted
|
||||
double max = _pop[0].fitness();
|
||||
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)
|
||||
{
|
||||
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 ( comparator(_pop[i].objectiveVector(), _objVec) )
|
||||
// if _pop[i] is dominated by _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 */
|
||||
moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
|
||||
/** Functor to compare two objective vectors according to Pareto dominance relation */
|
||||
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
|
||||
/** Functor allowing to compare two solutions according to their first objective value, then their second, and so on. */
|
||||
class ObjectiveComparator : public moeoComparator < MOEOT >
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Returns true if _moeo1 < _moeo2 on the first objective, then on the second, and so on
|
||||
* @param _moeo1 the first solution
|
||||
* @param _moeo2 the second solution
|
||||
*/
|
||||
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
||||
{
|
||||
return cmp(_moeo1.objectiveVector(), _moeo2.objectiveVector());
|
||||
}
|
||||
private:
|
||||
/** the corresponding comparator for objective vectors */
|
||||
moeoObjectiveObjectiveVectorComparator < ObjectiveVector > cmp;
|
||||
} objComparator;
|
||||
class ObjectiveComparator : public moeoComparator < MOEOT >
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Returns true if _moeo1 < _moeo2 on the first objective, then on the second, and so on
|
||||
* @param _moeo1 the first solution
|
||||
* @param _moeo2 the second solution
|
||||
*/
|
||||
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
||||
{
|
||||
return cmp(_moeo1.objectiveVector(), _moeo2.objectiveVector());
|
||||
}
|
||||
private:
|
||||
/** the corresponding comparator for objective vectors */
|
||||
moeoObjectiveObjectiveVectorComparator < ObjectiveVector > cmp;
|
||||
}
|
||||
objComparator;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -167,18 +168,18 @@ private:
|
|||
*/
|
||||
void oneObjective (eoPop < MOEOT > & _pop)
|
||||
{
|
||||
// sorts the population in the ascending order
|
||||
std::sort(_pop.begin(), _pop.end(), objComparator);
|
||||
// assign fitness values
|
||||
unsigned int rank = 1;
|
||||
_pop[_pop.size()-1].fitness(rank);
|
||||
for (unsigned int i=_pop.size()-2; i>=0; i--)
|
||||
// sorts the population in the ascending order
|
||||
std::sort(_pop.begin(), _pop.end(), objComparator);
|
||||
// assign fitness values
|
||||
unsigned int rank = 1;
|
||||
_pop[_pop.size()-1].fitness(rank);
|
||||
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)
|
||||
{
|
||||
//... TO DO !
|
||||
//... TO DO !
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -199,66 +200,66 @@ private:
|
|||
*/
|
||||
void mObjectives (eoPop < MOEOT > & _pop)
|
||||
{
|
||||
// S[i] = indexes of the individuals dominated by _pop[i]
|
||||
std::vector < std::vector<unsigned int> > S(_pop.size());
|
||||
// n[i] = number of individuals that dominate the individual _pop[i]
|
||||
std::vector < unsigned int > n(_pop.size(), 0);
|
||||
// fronts: F[i] = indexes of the individuals contained in the ith front
|
||||
std::vector < std::vector<unsigned int> > F(_pop.size()+2);
|
||||
// used to store the number of the first front
|
||||
F[1].reserve(_pop.size());
|
||||
for (unsigned int p=0; p<_pop.size(); p++)
|
||||
// S[i] = indexes of the individuals dominated by _pop[i]
|
||||
std::vector < std::vector<unsigned int> > S(_pop.size());
|
||||
// n[i] = number of individuals that dominate the individual _pop[i]
|
||||
std::vector < unsigned int > n(_pop.size(), 0);
|
||||
// fronts: F[i] = indexes of the individuals contained in the ith front
|
||||
std::vector < std::vector<unsigned int> > F(_pop.size()+2);
|
||||
// used to store the number of the first front
|
||||
F[1].reserve(_pop.size());
|
||||
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 ( comparator(_pop[q].objectiveVector(), _pop[p].objectiveVector()) )
|
||||
// if q is dominated by p
|
||||
if ( comparator(_pop[q].objectiveVector(), _pop[p].objectiveVector()) )
|
||||
{
|
||||
// add q to the set of solutions dominated by p
|
||||
S[p].push_back(q);
|
||||
// add q to the set of solutions dominated by p
|
||||
S[p].push_back(q);
|
||||
}
|
||||
// if p is dominated by q
|
||||
else if ( comparator(_pop[p].objectiveVector(), _pop[q].objectiveVector()) )
|
||||
// if p is dominated by q
|
||||
else if ( comparator(_pop[p].objectiveVector(), _pop[q].objectiveVector()) )
|
||||
{
|
||||
// increment the domination counter of p
|
||||
n[p]++;
|
||||
// increment the domination counter of p
|
||||
n[p]++;
|
||||
}
|
||||
}
|
||||
// if no individual dominates p
|
||||
if (n[p] == 0)
|
||||
// if no individual dominates p
|
||||
if (n[p] == 0)
|
||||
{
|
||||
// p belongs to the first front
|
||||
_pop[p].fitness(1);
|
||||
F[1].push_back(p);
|
||||
// p belongs to the first front
|
||||
_pop[p].fitness(1);
|
||||
F[1].push_back(p);
|
||||
}
|
||||
}
|
||||
// front counter
|
||||
unsigned int counter=1;
|
||||
unsigned int p,q;
|
||||
while (! F[counter].empty())
|
||||
// front counter
|
||||
unsigned int counter=1;
|
||||
unsigned int p,q;
|
||||
while (! F[counter].empty())
|
||||
{
|
||||
// used to store the number of the next front
|
||||
F[counter+1].reserve(_pop.size());
|
||||
for (unsigned int i=0; i<F[counter].size(); i++)
|
||||
// used to store the number of the next front
|
||||
F[counter+1].reserve(_pop.size());
|
||||
for (unsigned int i=0; i<F[counter].size(); i++)
|
||||
{
|
||||
p = F[counter][i];
|
||||
for (unsigned int j=0; j<S[p].size(); j++)
|
||||
p = F[counter][i];
|
||||
for (unsigned int j=0; j<S[p].size(); j++)
|
||||
{
|
||||
q = S[p][j];
|
||||
n[q]--;
|
||||
// if no individual dominates q anymore
|
||||
if (n[q] == 0)
|
||||
q = S[p][j];
|
||||
n[q]--;
|
||||
// if no individual dominates q anymore
|
||||
if (n[q] == 0)
|
||||
{
|
||||
// q belongs to the next front
|
||||
_pop[q].fitness(counter+1);
|
||||
F[counter+1].push_back(q);
|
||||
// q belongs to the next front
|
||||
_pop[q].fitness(counter+1);
|
||||
F[counter+1].push_back(q);
|
||||
}
|
||||
}
|
||||
}
|
||||
counter++;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOFASTNONDOMINATEDSORTINGFITNESSASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoFitnessAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -46,8 +46,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoFitnessAssignment : public eoUF < eoPop < MOEOT > &, void >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type for objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -68,9 +68,9 @@ public:
|
|||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo)
|
||||
{
|
||||
updateByDeleting(_pop, _moeo.objectiveVector());
|
||||
updateByDeleting(_pop, _moeo.objectiveVector());
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOFITNESSASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoIndicatorBasedFitnessAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
* moeoIndicatorBasedFitnessAssignment is a moeoFitnessAssignment for Indicator-based strategies.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > {};
|
||||
class moeoIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
|
||||
{};
|
||||
|
||||
#endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoParetoBasedFitnessAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
* moeoParetoBasedFitnessAssignment is a moeoFitnessAssignment for Pareto-based strategies.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoParetoBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > {};
|
||||
|
||||
class moeoParetoBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
|
||||
{};
|
||||
|
||||
#endif /*MOEOPARETOBASEDFITNESSASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoReferencePointIndicatorBasedFitnessAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -48,8 +48,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoReferencePointIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type of objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -60,7 +60,7 @@ public:
|
|||
* @param _metric the quality indicator
|
||||
*/
|
||||
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)
|
||||
{
|
||||
// 1 - setting of the bounds
|
||||
setup(_pop);
|
||||
// 2 - setting fitnesses
|
||||
setFitnesses(_pop);
|
||||
// 1 - setting of the bounds
|
||||
setup(_pop);
|
||||
// 2 - setting fitnesses
|
||||
setFitnesses(_pop);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -84,11 +84,11 @@ public:
|
|||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
// nothing to do ;-)
|
||||
// nothing to do ;-)
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** the reference point */
|
||||
ObjectiveVector & refPoint;
|
||||
|
|
@ -102,18 +102,18 @@ protected:
|
|||
*/
|
||||
void setup(const eoPop < MOEOT > & _pop)
|
||||
{
|
||||
double min, max;
|
||||
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
double min, max;
|
||||
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
{
|
||||
min = refPoint[i];
|
||||
max = refPoint[i];
|
||||
for (unsigned int j=0; j<_pop.size(); j++)
|
||||
min = refPoint[i];
|
||||
max = refPoint[i];
|
||||
for (unsigned int j=0; j<_pop.size(); j++)
|
||||
{
|
||||
min = std::min(min, _pop[j].objectiveVector()[i]);
|
||||
max = std::max(max, _pop[j].objectiveVector()[i]);
|
||||
min = std::min(min, _pop[j].objectiveVector()[i]);
|
||||
max = std::max(max, _pop[j].objectiveVector()[i]);
|
||||
}
|
||||
// setting of the bounds for the objective i
|
||||
metric.setup(min, max, i);
|
||||
// setting of the bounds for the objective i
|
||||
metric.setup(min, max, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,12 +123,12 @@ protected:
|
|||
*/
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoScalarFitnessAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
* moeoScalarFitnessAssignment is a moeoFitnessAssignment for scalar strategies.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoScalarFitnessAssignment : public moeoFitnessAssignment < MOEOT > {};
|
||||
|
||||
class moeoScalarFitnessAssignment : public moeoFitnessAssignment < MOEOT >
|
||||
{};
|
||||
|
||||
#endif /*MOEOSCALARFITNESSASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoUnaryIndicatorBasedFitnessAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
* moeoIndicatorBasedFitnessAssignment for unary indicators.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoUnaryIndicatorBasedFitnessAssignment : public moeoIndicatorBasedFitnessAssignment < MOEOT > {};
|
||||
class moeoUnaryIndicatorBasedFitnessAssignment : public moeoIndicatorBasedFitnessAssignment < MOEOT >
|
||||
{};
|
||||
|
||||
#endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoAdditiveEpsilonBinaryMetric.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
*/
|
||||
template < class ObjectiveVector >
|
||||
class moeoAdditiveEpsilonBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
// computation of the epsilon value for the first objective
|
||||
double result = epsilon(_o1, _o2, 0);
|
||||
// computation of the epsilon value for the other objectives
|
||||
double tmp;
|
||||
for (unsigned int i=1; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
// computation of the epsilon value for the first objective
|
||||
double result = epsilon(_o1, _o2, 0);
|
||||
// computation of the epsilon value for the other objectives
|
||||
double tmp;
|
||||
for (unsigned int i=1; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
{
|
||||
tmp = epsilon(_o1, _o2, i);
|
||||
result = std::max(result, tmp);
|
||||
tmp = epsilon(_o1, _o2, i);
|
||||
result = std::max(result, tmp);
|
||||
}
|
||||
// returns the maximum epsilon value
|
||||
return result;
|
||||
// returns the maximum epsilon value
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the bounds for every objective */
|
||||
using moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > :: bounds;
|
||||
|
|
@ -88,22 +88,22 @@ private:
|
|||
*/
|
||||
double epsilon(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj)
|
||||
{
|
||||
double result;
|
||||
// if the objective _obj have to be minimized
|
||||
if (ObjectiveVector::Traits::minimizing(_obj))
|
||||
double result;
|
||||
// if the objective _obj have to be minimized
|
||||
if (ObjectiveVector::Traits::minimizing(_obj))
|
||||
{
|
||||
// _o1[_obj] - _o2[_obj]
|
||||
result = ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() );
|
||||
// _o1[_obj] - _o2[_obj]
|
||||
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
|
||||
else
|
||||
// if the objective _obj have to be maximized
|
||||
else
|
||||
{
|
||||
// _o2[_obj] - _o1[_obj]
|
||||
result = ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() );
|
||||
// _o2[_obj] - _o1[_obj]
|
||||
result = ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() );
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOADDITIVEEPSILONBINARYMETRIC_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoContributionMetric.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,44 +47,47 @@
|
|||
*/
|
||||
template < class ObjectiveVector >
|
||||
class moeoContributionMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Returns the contribution of the Pareto set '_set1' relatively to the Pareto set '_set2'
|
||||
* @param _set1 the first Pareto set
|
||||
* @param _set2 the second Pareto set
|
||||
*/
|
||||
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 n1 = card_N(_set1, _set2);
|
||||
unsigned int w2 = card_W(_set2, _set1);
|
||||
unsigned int n2 = card_N(_set2, _set1);
|
||||
return (double) (c / 2.0 + w1 + n1) / (c + w1 + n1 + w2 + n2);
|
||||
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 n1 = card_N(_set1, _set2);
|
||||
unsigned int w2 = card_W(_set2, _set1);
|
||||
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 */
|
||||
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of solutions both in '_set1' and '_set2'
|
||||
* @param _set1 the first Pareto set
|
||||
* @param _set2 the second Pareto set
|
||||
*/
|
||||
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++)
|
||||
for (unsigned int j=0; j<_set2.size(); j++)
|
||||
if (_set1[i] == _set2[j]) {
|
||||
c++;
|
||||
break;
|
||||
}
|
||||
return c;
|
||||
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++)
|
||||
for (unsigned int j=0; j<_set2.size(); j++)
|
||||
if (_set1[i] == _set2[j])
|
||||
{
|
||||
c++;
|
||||
break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -93,16 +96,17 @@ private:
|
|||
* @param _set1 the first Pareto set
|
||||
* @param _set2 the second Pareto set
|
||||
*/
|
||||
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++)
|
||||
for (unsigned int j=0; j<_set2.size(); j++)
|
||||
if (paretoComparator(_set2[j], _set1[i]))
|
||||
{
|
||||
w++;
|
||||
break;
|
||||
}
|
||||
return w;
|
||||
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++)
|
||||
for (unsigned int j=0; j<_set2.size(); j++)
|
||||
if (paretoComparator(_set2[j], _set1[i]))
|
||||
{
|
||||
w++;
|
||||
break;
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -111,22 +115,24 @@ private:
|
|||
* @param _set1 the first Pareto set
|
||||
* @param _set2 the second Pareto set
|
||||
*/
|
||||
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++) {
|
||||
bool domin_rel = false;
|
||||
for (unsigned int j=0; j<_set2.size(); j++)
|
||||
if ( (paretoComparator(_set2[j], _set1[i])) || (paretoComparator(_set1[i], _set2[j])) )
|
||||
{
|
||||
domin_rel = true;
|
||||
break;
|
||||
}
|
||||
if (! domin_rel)
|
||||
n++;
|
||||
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++)
|
||||
{
|
||||
bool domin_rel = false;
|
||||
for (unsigned int j=0; j<_set2.size(); j++)
|
||||
if ( (paretoComparator(_set2[j], _set1[i])) || (paretoComparator(_set1[i], _set2[j])) )
|
||||
{
|
||||
domin_rel = true;
|
||||
break;
|
||||
}
|
||||
if (! domin_rel)
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOCONTRIBUTIONMETRIC_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoEntropyMetric.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -48,52 +48,55 @@
|
|||
*/
|
||||
template < class ObjectiveVector >
|
||||
class moeoEntropyMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Returns the entropy of the Pareto set '_set1' relatively to the Pareto set '_set2'
|
||||
* @param _set1 the first Pareto set
|
||||
* @param _set2 the second Pareto set
|
||||
*/
|
||||
double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
|
||||
// normalization
|
||||
std::vector< ObjectiveVector > set1 = _set1;
|
||||
std::vector< ObjectiveVector > set2= _set2;
|
||||
removeDominated (set1);
|
||||
removeDominated (set2);
|
||||
prenormalize (set1);
|
||||
normalize (set1);
|
||||
normalize (set2);
|
||||
double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2)
|
||||
{
|
||||
// normalization
|
||||
std::vector< ObjectiveVector > set1 = _set1;
|
||||
std::vector< ObjectiveVector > set2= _set2;
|
||||
removeDominated (set1);
|
||||
removeDominated (set2);
|
||||
prenormalize (set1);
|
||||
normalize (set1);
|
||||
normalize (set2);
|
||||
|
||||
// making of PO*
|
||||
std::vector< ObjectiveVector > star; // rotf :-)
|
||||
computeUnion (set1, set2, star);
|
||||
removeDominated (star);
|
||||
// making of PO*
|
||||
std::vector< ObjectiveVector > star; // rotf :-)
|
||||
computeUnion (set1, set2, star);
|
||||
removeDominated (star);
|
||||
|
||||
// making of PO1 U PO*
|
||||
std::vector< ObjectiveVector > union_set1_star; // rotf again ...
|
||||
computeUnion (set1, star, union_set1_star);
|
||||
// making of PO1 U PO*
|
||||
std::vector< ObjectiveVector > union_set1_star; // rotf again ...
|
||||
computeUnion (set1, star, union_set1_star);
|
||||
|
||||
unsigned int C = union_set1_star.size();
|
||||
float omega=0;
|
||||
float entropy=0;
|
||||
unsigned int C = union_set1_star.size();
|
||||
float omega=0;
|
||||
float entropy=0;
|
||||
|
||||
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());
|
||||
if (n_i > 0) {
|
||||
omega += 1.0 / N_i;
|
||||
entropy += (float) n_i / (N_i * C) * log (((float) n_i / C) / log (2.0));
|
||||
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());
|
||||
if (n_i > 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 (2.0);
|
||||
return entropy;
|
||||
entropy /= - log (omega);
|
||||
entropy *= log (2.0);
|
||||
return entropy;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** vector of min values */
|
||||
std::vector<double> vect_min_val;
|
||||
|
|
@ -107,19 +110,22 @@ private:
|
|||
* Removes the dominated individuals contained in _f
|
||||
* @param _f a Pareto set
|
||||
*/
|
||||
void removeDominated(std::vector < ObjectiveVector > & _f) {
|
||||
for (unsigned int i=0 ; i<_f.size(); i++) {
|
||||
bool dom = false;
|
||||
for (unsigned int j=0; j<_f.size(); j++)
|
||||
if (i != j && paretoComparator(_f[i],_f[j]))
|
||||
{
|
||||
dom = true;
|
||||
break;
|
||||
}
|
||||
if (dom) {
|
||||
_f[i] = _f.back();
|
||||
_f.pop_back();
|
||||
i--;
|
||||
void removeDominated(std::vector < ObjectiveVector > & _f)
|
||||
{
|
||||
for (unsigned int i=0 ; i<_f.size(); i++)
|
||||
{
|
||||
bool dom = false;
|
||||
for (unsigned int j=0; j<_f.size(); j++)
|
||||
if (i != j && paretoComparator(_f[i],_f[j]))
|
||||
{
|
||||
dom = true;
|
||||
break;
|
||||
}
|
||||
if (dom)
|
||||
{
|
||||
_f[i] = _f.back();
|
||||
_f.pop_back();
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -129,20 +135,23 @@ private:
|
|||
* Prenormalization
|
||||
* @param _f a Pareto set
|
||||
*/
|
||||
void prenormalize (const std::vector< ObjectiveVector > & _f) {
|
||||
vect_min_val.clear();
|
||||
vect_max_val.clear();
|
||||
void prenormalize (const std::vector< ObjectiveVector > & _f)
|
||||
{
|
||||
vect_min_val.clear();
|
||||
vect_max_val.clear();
|
||||
|
||||
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++) {
|
||||
if (_f[j][i] < min_val)
|
||||
min_val = _f[j][i];
|
||||
if (_f[j][i]>max_val)
|
||||
max_val = _f[j][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++)
|
||||
{
|
||||
if (_f[j][i] < min_val)
|
||||
min_val = _f[j][i];
|
||||
if (_f[j][i]>max_val)
|
||||
max_val = _f[j][i];
|
||||
}
|
||||
vect_min_val.push_back(min_val);
|
||||
vect_max_val.push_back (max_val);
|
||||
vect_min_val.push_back(min_val);
|
||||
vect_max_val.push_back (max_val);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -151,10 +160,11 @@ private:
|
|||
* Normalization
|
||||
* @param _f a Pareto set
|
||||
*/
|
||||
void normalize (std::vector< ObjectiveVector > & _f) {
|
||||
for (unsigned int i=0 ; i<ObjectiveVector::nObjectives(); 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]);
|
||||
void normalize (std::vector< ObjectiveVector > & _f)
|
||||
{
|
||||
for (unsigned int i=0 ; i<ObjectiveVector::nObjectives(); 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 _f the final Pareto set
|
||||
*/
|
||||
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++) {
|
||||
bool b = false;
|
||||
for (unsigned int j=0; j<_f1.size(); j ++)
|
||||
if (_f1[j] == _f2[i]) {
|
||||
b = true;
|
||||
break;
|
||||
}
|
||||
if (! b)
|
||||
_f.push_back(_f2[i]);
|
||||
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++)
|
||||
{
|
||||
bool b = false;
|
||||
for (unsigned int j=0; j<_f1.size(); j ++)
|
||||
if (_f1[j] == _f2[i])
|
||||
{
|
||||
b = true;
|
||||
break;
|
||||
}
|
||||
if (! b)
|
||||
_f.push_back(_f2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -182,26 +195,29 @@ private:
|
|||
/**
|
||||
* How many in niche
|
||||
*/
|
||||
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++) {
|
||||
if (euclidianDistance(_f[i], _s) < (_s.size() / (double) _size))
|
||||
n++;
|
||||
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++)
|
||||
{
|
||||
if (euclidianDistance(_f[i], _s) < (_s.size() / (double) _size))
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Euclidian distance
|
||||
*/
|
||||
double euclidianDistance (const ObjectiveVector & _set1, const ObjectiveVector & _to, unsigned int _deg = 2) {
|
||||
double dist=0;
|
||||
for (unsigned int i=0; i<_set1.size(); i++)
|
||||
dist += pow(fabs(_set1[i] - _to[i]), (int)_deg);
|
||||
return pow(dist, 1.0 / _deg);
|
||||
double euclidianDistance (const ObjectiveVector & _set1, const ObjectiveVector & _to, unsigned int _deg = 2)
|
||||
{
|
||||
double dist=0;
|
||||
for (unsigned int i=0; i<_set1.size(); i++)
|
||||
dist += pow(fabs(_set1[i] - _to[i]), (int)_deg);
|
||||
return pow(dist, 1.0 / _deg);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOENTROPYMETRIC_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoHypervolumeBinaryMetric.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -52,8 +52,8 @@
|
|||
*/
|
||||
template < class ObjectiveVector >
|
||||
class moeoHypervolumeBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
|
|
@ -61,20 +61,20 @@ public:
|
|||
*/
|
||||
moeoHypervolumeBinaryMetric(double _rho = 1.1) : rho(_rho)
|
||||
{
|
||||
// not-a-maximization problem check
|
||||
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
// not-a-maximization problem check
|
||||
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
|
||||
if (rho < 1)
|
||||
// consistency check
|
||||
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 << "Adjusted to 1" << std::endl;
|
||||
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 << "Adjusted to 1" << std::endl;
|
||||
rho = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -87,21 +87,21 @@ public:
|
|||
*/
|
||||
double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2)
|
||||
{
|
||||
double result;
|
||||
// if _o2 is dominated by _o1
|
||||
if ( paretoComparator(_o2,_o1) )
|
||||
double result;
|
||||
// if _o2 is dominated by _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 */
|
||||
double rho;
|
||||
|
|
@ -120,47 +120,47 @@ private:
|
|||
*/
|
||||
double hypervolume(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj, const bool _flag = false)
|
||||
{
|
||||
double result;
|
||||
double range = rho * bounds[_obj].range();
|
||||
double max = bounds[_obj].minimum() + range;
|
||||
// value of _1 for the objective _obj
|
||||
double v1 = _o1[_obj];
|
||||
// value of _2 for the objective _obj (if _flag=true, v2=max)
|
||||
double v2;
|
||||
if (_flag)
|
||||
double result;
|
||||
double range = rho * bounds[_obj].range();
|
||||
double max = bounds[_obj].minimum() + range;
|
||||
// value of _1 for the objective _obj
|
||||
double v1 = _o1[_obj];
|
||||
// value of _2 for the objective _obj (if _flag=true, v2=max)
|
||||
double v2;
|
||||
if (_flag)
|
||||
{
|
||||
v2 = max;
|
||||
v2 = max;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
v2 = _o2[_obj];
|
||||
v2 = _o2[_obj];
|
||||
}
|
||||
// computation of the volume
|
||||
if (_obj == 0)
|
||||
// computation of the volume
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoMetric.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,49 +44,56 @@
|
|||
/**
|
||||
* Base class for performance metrics (also known as quality indicators).
|
||||
*/
|
||||
class moeoMetric : public eoFunctorBase {};
|
||||
class moeoMetric : public eoFunctorBase
|
||||
{};
|
||||
|
||||
|
||||
/**
|
||||
* Base class for unary metrics.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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)
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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)
|
||||
*/
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoNormalizedSolutionVsSolutionBinaryMetric.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -49,19 +49,19 @@
|
|||
*/
|
||||
template < class ObjectiveVector, class R >
|
||||
class moeoNormalizedSolutionVsSolutionBinaryMetric : public moeoSolutionVsSolutionBinaryMetric < ObjectiveVector, R >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default ctr for any moeoNormalizedSolutionVsSolutionBinaryMetric object
|
||||
*/
|
||||
moeoNormalizedSolutionVsSolutionBinaryMetric()
|
||||
{
|
||||
bounds.resize(ObjectiveVector::Traits::nObjectives());
|
||||
// initialize bounds in case someone does not want to use them
|
||||
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||
bounds.resize(ObjectiveVector::Traits::nObjectives());
|
||||
// initialize bounds in case someone does not want to use them
|
||||
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)
|
||||
{
|
||||
if (_min == _max)
|
||||
if (_min == _max)
|
||||
{
|
||||
_min -= tiny();
|
||||
_max += tiny();
|
||||
_min -= 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)
|
||||
{
|
||||
bounds[_obj] = _realInterval;
|
||||
bounds[_obj] = _realInterval;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -99,15 +99,15 @@ public:
|
|||
*/
|
||||
static double tiny()
|
||||
{
|
||||
return 1e-6;
|
||||
return 1e-6;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** the bounds for every objective (bounds[i] = bounds for the objective i) */
|
||||
std::vector < eoRealInterval > bounds;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEONORMALIZEDSOLUTIONVSSOLUTIONBINARYMETRIC_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoMoveIncrEval.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,6 +41,7 @@
|
|||
#include <eoFunctor.h>
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoElitistReplacement.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -49,8 +49,8 @@
|
|||
* Elitist replacement strategy that consists in keeping the N best individuals.
|
||||
*/
|
||||
template < class MOEOT > class moeoElitistReplacement:public moeoReplacement < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Full constructor.
|
||||
|
|
@ -59,7 +59,7 @@ public:
|
|||
* @param _comparator the comparator (used to compare 2 individuals)
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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)
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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)
|
||||
{
|
||||
unsigned int sz = _parents.size ();
|
||||
// merges offspring and parents into a global population
|
||||
_parents.reserve (_parents.size () + _offspring.size ());
|
||||
std::copy (_offspring.begin (), _offspring.end (), back_inserter (_parents));
|
||||
// evaluates the fitness and the diversity of this global population
|
||||
fitnessAssignment (_parents);
|
||||
diversityAssignment (_parents);
|
||||
// sorts the whole population according to the comparator
|
||||
std::sort(_parents.begin(), _parents.end(), comparator);
|
||||
// finally, resize this global population
|
||||
_parents.resize (sz);
|
||||
// and clear the offspring population
|
||||
_offspring.clear ();
|
||||
unsigned int sz = _parents.size ();
|
||||
// merges offspring and parents into a global population
|
||||
_parents.reserve (_parents.size () + _offspring.size ());
|
||||
std::copy (_offspring.begin (), _offspring.end (), back_inserter (_parents));
|
||||
// evaluates the fitness and the diversity of this global population
|
||||
fitnessAssignment (_parents);
|
||||
diversityAssignment (_parents);
|
||||
// sorts the whole population according to the comparator
|
||||
std::sort(_parents.begin(), _parents.end(), comparator);
|
||||
// finally, resize this global population
|
||||
_parents.resize (sz);
|
||||
// and clear the offspring population
|
||||
_offspring.clear ();
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** the fitness assignment strategy */
|
||||
moeoFitnessAssignment < MOEOT > & fitnessAssignment;
|
||||
|
|
@ -128,8 +128,8 @@ protected:
|
|||
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
|
||||
/** this object is used to compare solutions in order to sort the population */
|
||||
class Cmp
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Ctor.
|
||||
* @param _comp the comparator
|
||||
|
|
@ -143,13 +143,14 @@ protected:
|
|||
*/
|
||||
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
||||
{
|
||||
return comp(_moeo2,_moeo1);
|
||||
return comp(_moeo2,_moeo1);
|
||||
}
|
||||
private:
|
||||
private:
|
||||
/** the comparator */
|
||||
moeoComparator < MOEOT > & comp;
|
||||
} comparator;
|
||||
}
|
||||
comparator;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOELITISTREPLACEMENT_H_ */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoEnvironmentalReplacement.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -49,8 +49,8 @@
|
|||
* and by updating the fitness and diversity values after each deletion.
|
||||
*/
|
||||
template < class MOEOT > class moeoEnvironmentalReplacement:public moeoReplacement < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type for objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -63,7 +63,7 @@ public:
|
|||
* @param _comparator the comparator (used to compare 2 individuals)
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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)
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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)
|
||||
{
|
||||
unsigned int sz = _parents.size();
|
||||
// merges offspring and parents into a global population
|
||||
_parents.reserve (_parents.size() + _offspring.size());
|
||||
std::copy (_offspring.begin(), _offspring.end(), back_inserter(_parents));
|
||||
// evaluates the fitness and the diversity of this global population
|
||||
fitnessAssignment (_parents);
|
||||
diversityAssignment (_parents);
|
||||
// remove individuals 1 by 1 and update the fitness values
|
||||
unsigned int worstIdx;
|
||||
ObjectiveVector worstObjVec;
|
||||
while (_parents.size() > sz)
|
||||
unsigned int sz = _parents.size();
|
||||
// merges offspring and parents into a global population
|
||||
_parents.reserve (_parents.size() + _offspring.size());
|
||||
std::copy (_offspring.begin(), _offspring.end(), back_inserter(_parents));
|
||||
// evaluates the fitness and the diversity of this global population
|
||||
fitnessAssignment (_parents);
|
||||
diversityAssignment (_parents);
|
||||
// remove individuals 1 by 1 and update the fitness values
|
||||
unsigned int worstIdx;
|
||||
ObjectiveVector worstObjVec;
|
||||
while (_parents.size() > sz)
|
||||
{
|
||||
// the individual to delete
|
||||
worstIdx = std::min_element(_parents.begin(), _parents.end(), comparator) - _parents.begin();
|
||||
worstObjVec = _parents[worstIdx].objectiveVector();
|
||||
// remove the woorst individual
|
||||
_parents[worstIdx] = _parents.back();
|
||||
_parents.pop_back();
|
||||
// update of the fitness and diversity values
|
||||
fitnessAssignment.updateByDeleting(_parents, worstObjVec);
|
||||
diversityAssignment.updateByDeleting(_parents, worstObjVec);
|
||||
// the individual to delete
|
||||
worstIdx = std::min_element(_parents.begin(), _parents.end(), comparator) - _parents.begin();
|
||||
worstObjVec = _parents[worstIdx].objectiveVector();
|
||||
// remove the woorst individual
|
||||
_parents[worstIdx] = _parents.back();
|
||||
_parents.pop_back();
|
||||
// update of the fitness and diversity values
|
||||
fitnessAssignment.updateByDeleting(_parents, worstObjVec);
|
||||
diversityAssignment.updateByDeleting(_parents, worstObjVec);
|
||||
|
||||
}
|
||||
// clear the offspring population
|
||||
_offspring.clear ();
|
||||
// clear the offspring population
|
||||
_offspring.clear ();
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** the fitness assignment strategy */
|
||||
moeoFitnessAssignment < MOEOT > & fitnessAssignment;
|
||||
|
|
@ -144,8 +144,8 @@ protected:
|
|||
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
|
||||
/** this object is used to compare solutions in order to sort the population */
|
||||
class Cmp
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Ctor.
|
||||
* @param _comp the comparator
|
||||
|
|
@ -159,13 +159,14 @@ protected:
|
|||
*/
|
||||
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
||||
{
|
||||
return comp(_moeo1,_moeo2);
|
||||
return comp(_moeo1,_moeo2);
|
||||
}
|
||||
private:
|
||||
private:
|
||||
/** the comparator */
|
||||
moeoComparator < MOEOT > & comp;
|
||||
} comparator;
|
||||
}
|
||||
comparator;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOENVIRONMENTALREPLACEMENT_H_ */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoGenerationalReplacement.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -46,8 +46,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoGenerationalReplacement : public moeoReplacement < MOEOT >, public eoGenerationalReplacement < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Swaps _parents and _offspring
|
||||
|
|
@ -56,9 +56,9 @@ public:
|
|||
*/
|
||||
void operator()(eoPop < MOEOT > & _parents, eoPop < MOEOT > & _offspring)
|
||||
{
|
||||
eoGenerationalReplacement < MOEOT >::operator ()(_parents, _offspring);
|
||||
eoGenerationalReplacement < MOEOT >::operator ()(_parents, _offspring);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOGENERATIONALREPLACEMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoReplacement.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
* Replacement strategy for multi-objective optimization.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoReplacement : public eoReplacement < MOEOT > {};
|
||||
class moeoReplacement : public eoReplacement < MOEOT >
|
||||
{};
|
||||
|
||||
#endif /*MOEOREPLACEMENT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoDetTournamentSelect.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
* Selection strategy that selects ONE individual by deterministic tournament.
|
||||
*/
|
||||
template < class MOEOT > class moeoDetTournamentSelect:public moeoSelectOne < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Full Ctor.
|
||||
|
|
@ -57,12 +57,12 @@ public:
|
|||
*/
|
||||
moeoDetTournamentSelect (moeoComparator < MOEOT > & _comparator, unsigned int _tSize = 2) : comparator (_comparator), tSize (_tSize)
|
||||
{
|
||||
// consistency check
|
||||
if (tSize < 2)
|
||||
// consistency check
|
||||
if (tSize < 2)
|
||||
{
|
||||
std::
|
||||
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
|
||||
tSize = 2;
|
||||
std::
|
||||
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
|
||||
tSize = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,12 +73,12 @@ public:
|
|||
*/
|
||||
moeoDetTournamentSelect (unsigned int _tSize = 2) : comparator (defaultComparator), tSize (_tSize)
|
||||
{
|
||||
// consistency check
|
||||
if (tSize < 2)
|
||||
// consistency check
|
||||
if (tSize < 2)
|
||||
{
|
||||
std::
|
||||
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
|
||||
tSize = 2;
|
||||
std::
|
||||
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
|
||||
tSize = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,12 +89,12 @@ public:
|
|||
*/
|
||||
const MOEOT & operator() (const eoPop < MOEOT > &_pop)
|
||||
{
|
||||
// use the selector
|
||||
return mo_deterministic_tournament (_pop, tSize, comparator);
|
||||
// use the selector
|
||||
return mo_deterministic_tournament (_pop, tSize, comparator);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** the comparator (used to compare 2 individuals) */
|
||||
moeoComparator < MOEOT > & comparator;
|
||||
|
|
@ -103,6 +103,6 @@ protected:
|
|||
/** the number of individuals in the tournament */
|
||||
unsigned int tSize;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEODETTOURNAMENTSELECT_H_ */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoRandomSelect.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -46,13 +46,14 @@
|
|||
* Selection strategy that selects only one element randomly from a whole population.
|
||||
*/
|
||||
template < class MOEOT > class moeoRandomSelect:public moeoSelectOne < MOEOT >, public eoRandomSelect <MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor.
|
||||
*/
|
||||
moeoRandomSelect(){}
|
||||
moeoRandomSelect()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -60,9 +61,9 @@ public:
|
|||
*/
|
||||
const MOEOT & operator () (const eoPop < MOEOT > &_pop)
|
||||
{
|
||||
return eoRandomSelect < MOEOT >::operator ()(_pop);
|
||||
return eoRandomSelect < MOEOT >::operator ()(_pop);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEORANDOMSELECT_H_ */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoRouletteSelect.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoRouletteSelect:public moeoSelectOne < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor.
|
||||
|
|
@ -56,12 +56,12 @@ public:
|
|||
*/
|
||||
moeoRouletteSelect (unsigned int _tSize = 2) : tSize (_tSize)
|
||||
{
|
||||
// consistency check
|
||||
if (tSize < 2)
|
||||
// consistency check
|
||||
if (tSize < 2)
|
||||
{
|
||||
std::
|
||||
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
|
||||
tSize = 2;
|
||||
std::
|
||||
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
|
||||
tSize = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,16 +72,16 @@ public:
|
|||
*/
|
||||
const MOEOT & operator () (const eoPop < MOEOT > & _pop)
|
||||
{
|
||||
// use the selector
|
||||
return mo_roulette_wheel(_pop,tSize);
|
||||
// use the selector
|
||||
return mo_roulette_wheel(_pop,tSize);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** size */
|
||||
double & tSize;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOROULETTESELECT_H_ */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoSelectFromPopAndArch.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -49,8 +49,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoSelectFromPopAndArch : public moeoSelectOne < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
|
|
@ -60,7 +60,7 @@ public:
|
|||
* @param _ratioFromPop the ratio of selected individuals from the population
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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)
|
||||
{
|
||||
if (arch.size() > 0)
|
||||
if (rng.flip(ratioFromPop))
|
||||
return popSelectOne(pop);
|
||||
else
|
||||
return archSelectOne(arch);
|
||||
if (arch.size() > 0)
|
||||
if (rng.flip(ratioFromPop))
|
||||
return popSelectOne(pop);
|
||||
else
|
||||
return popSelectOne(pop);
|
||||
return archSelectOne(arch);
|
||||
else
|
||||
return popSelectOne(pop);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -95,11 +95,11 @@ public:
|
|||
*/
|
||||
virtual void setup (const eoPop < MOEOT > & _pop)
|
||||
{
|
||||
popSelectOne.setup(_pop);
|
||||
popSelectOne.setup(_pop);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** The population's selection operator */
|
||||
moeoSelectOne < MOEOT > & popSelectOne;
|
||||
|
|
@ -112,6 +112,6 @@ private:
|
|||
/** A random selection operator (used as default for archSelectOne) */
|
||||
moeoRandomSelect < MOEOT > randomSelectOne;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOSELECTONEFROMPOPANDARCH_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoSelectOne.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoSelectOne : public eoSelectOne < MOEOT > {};
|
||||
class moeoSelectOne : public eoSelectOne < MOEOT >
|
||||
{};
|
||||
|
||||
#endif /*MOEOSELECTONE_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoSelectors.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,71 +44,71 @@
|
|||
template <class It,class MOEOT>
|
||||
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);
|
||||
// compare the two individuals by using the comparator
|
||||
if (_comparator(*best, *competitor))
|
||||
// best "better" than competitor
|
||||
best=competitor;
|
||||
It competitor = _begin + _gen.random(_end - _begin);
|
||||
// compare the two individuals by using the comparator
|
||||
if (_comparator(*best, *competitor))
|
||||
// best "better" than competitor
|
||||
best=competitor;
|
||||
}
|
||||
return best;
|
||||
return best;
|
||||
}
|
||||
|
||||
|
||||
template <class MOEOT>
|
||||
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>
|
||||
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>
|
||||
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 i2 = _begin + _gen.random(_end - _begin);
|
||||
It i1 = _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;
|
||||
// else
|
||||
if (return_better) return i2;
|
||||
// else
|
||||
|
||||
return i1;
|
||||
return i1;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if (return_better) return i1;
|
||||
// else
|
||||
if (return_better) return i1;
|
||||
// else
|
||||
}
|
||||
// else
|
||||
// else
|
||||
|
||||
return i2;
|
||||
return i2;
|
||||
}
|
||||
|
||||
|
||||
template <class MOEOT>
|
||||
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>
|
||||
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)
|
||||
{
|
||||
|
||||
float roulette = _gen.uniform(total);
|
||||
float roulette = _gen.uniform(total);
|
||||
|
||||
if (roulette == 0.0) // covers the case where total==0.0
|
||||
return _begin + _gen.random(_end - _begin); // uniform choice
|
||||
if (roulette == 0.0) // covers the case where total==0.0
|
||||
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>
|
||||
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
|
||||
return _pop[_gen.random(_pop.size())]; // uniform choice
|
||||
if (roulette == 0.0) // covers the case where total==0.0
|
||||
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>
|
||||
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
|
||||
return _pop[_gen.random(_pop.size())]; // uniform choice
|
||||
if (roulette == 0.0) // covers the case where total==0.0
|
||||
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
|
||||
roulette -= static_cast<double>((i++)->fitness());
|
||||
// fitness only
|
||||
roulette -= static_cast<double>((i++)->fitness());
|
||||
}
|
||||
|
||||
return *--i;
|
||||
return *--i;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoStochTournamentSelect.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
* Selection strategy that selects ONE individual by stochastic tournament.
|
||||
*/
|
||||
template < class MOEOT > class moeoStochTournamentSelect:public moeoSelectOne <MOEOT>
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Full Ctor
|
||||
|
|
@ -57,19 +57,19 @@ public:
|
|||
*/
|
||||
moeoStochTournamentSelect (moeoComparator < MOEOT > & _comparator, double _tRate = 1.0) : comparator (_comparator), tRate (_tRate)
|
||||
{
|
||||
// consistency checks
|
||||
if (tRate < 0.5)
|
||||
// consistency checks
|
||||
if (tRate < 0.5)
|
||||
{
|
||||
std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
|
||||
tRate = 0.55;
|
||||
std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
|
||||
tRate = 0.55;
|
||||
}
|
||||
if (tRate > 1)
|
||||
if (tRate > 1)
|
||||
{
|
||||
std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
|
||||
tRate = 1;
|
||||
std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
|
||||
tRate = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default.
|
||||
|
|
@ -77,16 +77,16 @@ public:
|
|||
*/
|
||||
moeoStochTournamentSelect (double _tRate = 1.0) : comparator (defaultComparator), tRate (_tRate)
|
||||
{
|
||||
// consistency checks
|
||||
if (tRate < 0.5)
|
||||
// consistency checks
|
||||
if (tRate < 0.5)
|
||||
{
|
||||
std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
|
||||
tRate = 0.55;
|
||||
std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
|
||||
tRate = 0.55;
|
||||
}
|
||||
if (tRate > 1)
|
||||
if (tRate > 1)
|
||||
{
|
||||
std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
|
||||
tRate = 1;
|
||||
std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
|
||||
tRate = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,12 +97,12 @@ public:
|
|||
*/
|
||||
const MOEOT & operator() (const eoPop < MOEOT > &_pop)
|
||||
{
|
||||
// use the selector
|
||||
return mo_stochastic_tournament(_pop,tRate,comparator);
|
||||
// use the selector
|
||||
return mo_stochastic_tournament(_pop,tRate,comparator);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** the comparator (used to compare 2 individuals) */
|
||||
moeoComparator < MOEOT > & comparator;
|
||||
|
|
@ -111,6 +111,6 @@ protected:
|
|||
/** the tournament rate */
|
||||
double tRate;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOSTOCHTOURNAMENTSELECT_H_ */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoArchiveObjectiveVectorSavingUpdater.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -51,8 +51,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoArchiveObjectiveVectorSavingUpdater : public eoUpdater
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
|
|
@ -62,46 +62,47 @@ public:
|
|||
* @param _id own ID
|
||||
*/
|
||||
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
|
||||
*/
|
||||
void operator()() {
|
||||
char buff[MAX_BUFFER_SIZE];
|
||||
if (count)
|
||||
void operator()()
|
||||
{
|
||||
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);
|
||||
for (unsigned int i = 0; i < arch.size (); i++)
|
||||
f << arch[i].objectiveVector() << std::endl;
|
||||
f.close ();
|
||||
std::ofstream f(buff);
|
||||
for (unsigned int i = 0; i < arch.size (); i++)
|
||||
f << arch[i].objectiveVector() << std::endl;
|
||||
f.close ();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** local archive */
|
||||
moeoArchive<MOEOT> & arch;
|
||||
|
|
@ -114,6 +115,6 @@ private:
|
|||
/** own ID */
|
||||
int id;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoArchiveUpdater.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoArchiveUpdater : public eoUpdater
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
|
|
@ -62,18 +62,19 @@ public:
|
|||
/**
|
||||
* Updates the archive with newly found non-dominated solutions contained in the main population
|
||||
*/
|
||||
void operator()() {
|
||||
arch.update(pop);
|
||||
void operator()()
|
||||
{
|
||||
arch.update(pop);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the archive of non-dominated solutions */
|
||||
moeoArchive < MOEOT > & arch;
|
||||
/** the main population */
|
||||
const eoPop < MOEOT > & pop;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOARCHIVEUPDATER_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoBinaryMetricSavingUpdater.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -51,8 +51,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoBinaryMetricSavingUpdater : public eoUpdater
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The objective vector type of a solution */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -65,37 +65,41 @@ public:
|
|||
* @param _filename the target 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
|
||||
*/
|
||||
void operator()() {
|
||||
if (pop.size()) {
|
||||
if (firstGen) {
|
||||
firstGen = false;
|
||||
void operator()()
|
||||
{
|
||||
if (pop.size())
|
||||
{
|
||||
if (firstGen)
|
||||
{
|
||||
firstGen = false;
|
||||
}
|
||||
else {
|
||||
// creation of the two Pareto sets
|
||||
std::vector < ObjectiveVector > from;
|
||||
std::vector < ObjectiveVector > to;
|
||||
for (unsigned int i=0; i<pop.size(); i++)
|
||||
from.push_back(pop[i].objectiveVector());
|
||||
for (unsigned int i=0 ; i<oldPop.size(); i++)
|
||||
to.push_back(oldPop[i].objectiveVector());
|
||||
// writing the result into the file
|
||||
std::ofstream f (filename.c_str(), std::ios::app);
|
||||
f << counter++ << ' ' << metric(from,to) << std::endl;
|
||||
f.close();
|
||||
else
|
||||
{
|
||||
// creation of the two Pareto sets
|
||||
std::vector < ObjectiveVector > from;
|
||||
std::vector < ObjectiveVector > to;
|
||||
for (unsigned int i=0; i<pop.size(); i++)
|
||||
from.push_back(pop[i].objectiveVector());
|
||||
for (unsigned int i=0 ; i<oldPop.size(); i++)
|
||||
to.push_back(oldPop[i].objectiveVector());
|
||||
// writing the result into the file
|
||||
std::ofstream f (filename.c_str(), std::ios::app);
|
||||
f << counter++ << ' ' << metric(from,to) << std::endl;
|
||||
f.close();
|
||||
}
|
||||
oldPop = pop;
|
||||
oldPop = pop;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** binary metric comparing two Pareto sets */
|
||||
moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & metric;
|
||||
|
|
@ -110,6 +114,6 @@ private:
|
|||
/** counter */
|
||||
unsigned int counter;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOBINARYMETRICSAVINGUPDATER_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoConvertPopToObjectiveVectors.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -46,8 +46,8 @@
|
|||
*/
|
||||
template < class MOEOT, class ObjectiveVector = typename MOEOT::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
|
||||
|
|
@ -55,15 +55,15 @@ public:
|
|||
*/
|
||||
const std::vector < ObjectiveVector > operator()(const eoPop < MOEOT > _pop)
|
||||
{
|
||||
std::vector < ObjectiveVector > result;
|
||||
result.resize(_pop.size());
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
std::vector < ObjectiveVector > result;
|
||||
result.resize(_pop.size());
|
||||
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_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <t-moeo.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopEA.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -65,68 +65,68 @@ using namespace std;
|
|||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
eoState state; // to keep all things allocated
|
||||
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
eoState state; // to keep all things allocated
|
||||
|
||||
|
||||
/*** the representation-dependent things ***/
|
||||
/*** the representation-dependent things ***/
|
||||
|
||||
// The fitness evaluation
|
||||
eoEvalFuncCounter<FlowShop>& eval = do_make_eval(parser, state);
|
||||
// the genotype (through a genotype initializer)
|
||||
eoInit<FlowShop>& init = do_make_genotype(parser, state);
|
||||
// the variation operators
|
||||
eoGenOp<FlowShop>& op = do_make_op(parser, state);
|
||||
// The fitness evaluation
|
||||
eoEvalFuncCounter<FlowShop>& eval = do_make_eval(parser, state);
|
||||
// the genotype (through a genotype initializer)
|
||||
eoInit<FlowShop>& init = do_make_genotype(parser, state);
|
||||
// the variation operators
|
||||
eoGenOp<FlowShop>& op = do_make_op(parser, state);
|
||||
|
||||
|
||||
/*** the representation-independent things ***/
|
||||
/*** the representation-independent things ***/
|
||||
|
||||
// initialization of the population
|
||||
eoPop<FlowShop>& pop = do_make_pop(parser, state, init);
|
||||
// definition of the archive
|
||||
moeoArchive<FlowShop> arch;
|
||||
// stopping criteria
|
||||
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
|
||||
// output
|
||||
eoCheckPoint<FlowShop>& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch);
|
||||
// algorithm
|
||||
eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch);
|
||||
// initialization of the population
|
||||
eoPop<FlowShop>& pop = do_make_pop(parser, state, init);
|
||||
// definition of the archive
|
||||
moeoArchive<FlowShop> arch;
|
||||
// stopping criteria
|
||||
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
|
||||
// output
|
||||
eoCheckPoint<FlowShop>& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch);
|
||||
// algorithm
|
||||
eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch);
|
||||
|
||||
|
||||
/*** Go ! ***/
|
||||
/*** Go ! ***/
|
||||
|
||||
// help ?
|
||||
make_help(parser);
|
||||
// help ?
|
||||
make_help(parser);
|
||||
|
||||
// first evalution
|
||||
apply<FlowShop>(eval, pop);
|
||||
// first evalution
|
||||
apply<FlowShop>(eval, pop);
|
||||
|
||||
// printing of the initial population
|
||||
cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
// printing of the initial population
|
||||
cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
// run the algo
|
||||
do_run(algo, pop);
|
||||
// run the algo
|
||||
do_run(algo, pop);
|
||||
|
||||
// printing of the final population
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
// printing of the final population
|
||||
cout << "Final Population\n";
|
||||
pop.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
// printing of the final archive
|
||||
cout << "Final Archive\n";
|
||||
arch.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
// printing of the final archive
|
||||
cout << "Final Archive\n";
|
||||
arch.sortedPrintOn(cout);
|
||||
cout << endl;
|
||||
|
||||
|
||||
}
|
||||
catch (exception& e)
|
||||
catch (exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <Sch1.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,21 +44,21 @@ using namespace std;
|
|||
|
||||
// the moeoObjectiveVectorTraits : minimizing 2 objectives
|
||||
class Sch1ObjectiveVectorTraits : public moeoObjectiveVectorTraits
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
static bool minimizing (int i)
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
static bool maximizing (int i)
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
static unsigned int nObjectives ()
|
||||
{
|
||||
return 2;
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// objective vector of real values
|
||||
|
|
@ -67,66 +67,67 @@ typedef moeoRealObjectiveVector < Sch1ObjectiveVectorTraits > Sch1ObjectiveVecto
|
|||
|
||||
// multi-objective evolving object for the Sch1 problem
|
||||
class Sch1 : public moeoRealVector < Sch1ObjectiveVector, double, double >
|
||||
{
|
||||
public:
|
||||
Sch1() : moeoRealVector < Sch1ObjectiveVector, double, double > (1) {}
|
||||
};
|
||||
{
|
||||
public:
|
||||
Sch1() : moeoRealVector < Sch1ObjectiveVector, double, double > (1)
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
// evaluation of objective functions
|
||||
class Sch1Eval : public moeoEvalFunc < Sch1 >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
void operator () (Sch1 & _sch1)
|
||||
{
|
||||
if (_sch1.invalidObjectiveVector())
|
||||
if (_sch1.invalidObjectiveVector())
|
||||
{
|
||||
Sch1ObjectiveVector objVec;
|
||||
double x = _sch1[0];
|
||||
objVec[0] = x * x;
|
||||
objVec[1] = (x - 2.0) * (x - 2.0);
|
||||
_sch1.objectiveVector(objVec);
|
||||
Sch1ObjectiveVector objVec;
|
||||
double x = _sch1[0];
|
||||
objVec[0] = x * x;
|
||||
objVec[1] = (x - 2.0) * (x - 2.0);
|
||||
_sch1.objectiveVector(objVec);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// main
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
// parameters
|
||||
unsigned int POP_SIZE = 20;
|
||||
unsigned int MAX_GEN = 100;
|
||||
double M_EPSILON = 0.01;
|
||||
double P_CROSS = 0.25;
|
||||
double P_MUT = 0.35;
|
||||
// parameters
|
||||
unsigned int POP_SIZE = 20;
|
||||
unsigned int MAX_GEN = 100;
|
||||
double M_EPSILON = 0.01;
|
||||
double P_CROSS = 0.25;
|
||||
double P_MUT = 0.35;
|
||||
|
||||
// objective functions evaluation
|
||||
Sch1Eval eval;
|
||||
// objective functions evaluation
|
||||
Sch1Eval eval;
|
||||
|
||||
// crossover and mutation
|
||||
eoQuadCloneOp < Sch1 > xover;
|
||||
eoUniformMutation < Sch1 > mutation (M_EPSILON);
|
||||
// crossover and mutation
|
||||
eoQuadCloneOp < Sch1 > xover;
|
||||
eoUniformMutation < Sch1 > mutation (M_EPSILON);
|
||||
|
||||
// generate initial population
|
||||
eoRealVectorBounds bounds (1, 0.0, 2.0); // [0, 2]
|
||||
eoRealInitBounded < Sch1 > init (bounds);
|
||||
eoPop < Sch1 > pop (POP_SIZE, init);
|
||||
// generate initial population
|
||||
eoRealVectorBounds bounds (1, 0.0, 2.0); // [0, 2]
|
||||
eoRealInitBounded < Sch1 > init (bounds);
|
||||
eoPop < Sch1 > pop (POP_SIZE, init);
|
||||
|
||||
// build NSGA-II
|
||||
moeoNSGAII < Sch1 > nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT);
|
||||
// build NSGA-II
|
||||
moeoNSGAII < Sch1 > nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT);
|
||||
|
||||
// run the algo
|
||||
nsgaII (pop);
|
||||
// run the algo
|
||||
nsgaII (pop);
|
||||
|
||||
// extract first front of the final population using an moeoArchive (this is the output of nsgaII)
|
||||
moeoArchive < Sch1 > arch;
|
||||
arch.update (pop);
|
||||
// extract first front of the final population using an moeoArchive (this is the output of nsgaII)
|
||||
moeoArchive < Sch1 > arch;
|
||||
arch.update (pop);
|
||||
|
||||
// printing of the final archive
|
||||
cout << "Final Archive" << endl;
|
||||
arch.sortedPrintOn (cout);
|
||||
cout << endl;
|
||||
// printing of the final archive
|
||||
cout << "Final Archive" << endl;
|
||||
arch.sortedPrintOn (cout);
|
||||
cout << endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShop.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -38,6 +38,6 @@
|
|||
#include <FlowShop.h>
|
||||
|
||||
std::string FlowShop::className() const
|
||||
{
|
||||
{
|
||||
return "FlowShop";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShop.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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.
|
||||
*/
|
||||
class FlowShop: public moeoVector < FlowShopObjectiveVector , double , double , unsigned int >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* class name
|
||||
*/
|
||||
std::string className() const;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*FLOWSHOP_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopBenchmarkParser.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -40,87 +40,92 @@
|
|||
|
||||
FlowShopBenchmarkParser::FlowShopBenchmarkParser(const std::string _benchmarkFileName)
|
||||
{
|
||||
init(_benchmarkFileName);
|
||||
init(_benchmarkFileName);
|
||||
}
|
||||
|
||||
|
||||
const unsigned int FlowShopBenchmarkParser::getM()
|
||||
{
|
||||
return M;
|
||||
return M;
|
||||
}
|
||||
|
||||
|
||||
const unsigned int FlowShopBenchmarkParser::getN()
|
||||
{
|
||||
return N;
|
||||
return N;
|
||||
}
|
||||
|
||||
|
||||
const std::vector< std::vector<unsigned int> > FlowShopBenchmarkParser::getP()
|
||||
{
|
||||
return p;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<unsigned int> FlowShopBenchmarkParser::getD()
|
||||
{
|
||||
return d;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
void FlowShopBenchmarkParser::printOn(std::ostream & _os) const
|
||||
{
|
||||
{
|
||||
_os << "M=" << M << " N=" << N << std::endl;
|
||||
_os << "*** processing times" << std::endl;
|
||||
for (unsigned int i=0; i<M; i++) {
|
||||
for (unsigned int j=0; j<N; j++) {
|
||||
for (unsigned int i=0; i<M; i++)
|
||||
{
|
||||
for (unsigned int j=0; j<N; j++)
|
||||
{
|
||||
_os << p[i][j] << " ";
|
||||
}
|
||||
}
|
||||
_os << 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 << std::endl << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FlowShopBenchmarkParser::init(const std::string _benchmarkFileName)
|
||||
{
|
||||
std::string buffer;
|
||||
std::string::size_type start, end;
|
||||
std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in);
|
||||
// opening of the benchmark file
|
||||
if (! inputFile)
|
||||
throw std::runtime_error("*** ERROR : Unable to open the benchmark file");
|
||||
// number of jobs (N)
|
||||
getline(inputFile, buffer, '\n');
|
||||
N = atoi(buffer.data());
|
||||
// number of machines M
|
||||
getline(inputFile, buffer, '\n');
|
||||
M = atoi(buffer.data());
|
||||
// initial and current seeds (not used)
|
||||
getline(inputFile, buffer, '\n');
|
||||
// processing times and due-dates
|
||||
p = std::vector< std::vector<unsigned int> > (M,N);
|
||||
d = std::vector<unsigned int> (N);
|
||||
// for each job...
|
||||
for (unsigned int j=0 ; j<N ; j++) {
|
||||
// index of the job (<=> j)
|
||||
getline(inputFile, buffer, '\n');
|
||||
// due-date of the job j
|
||||
getline(inputFile, buffer, '\n');
|
||||
d[j] = atoi(buffer.data());
|
||||
// processing times of the job j on each machine
|
||||
getline(inputFile, buffer, '\n');
|
||||
start = buffer.find_first_not_of(" ");
|
||||
for (unsigned int i=0 ; i<M ; i++) {
|
||||
end = buffer.find_first_of(" ", start);
|
||||
p[i][j] = atoi(buffer.substr(start, end-start).data());
|
||||
start = buffer.find_first_not_of(" ", end);
|
||||
std::string buffer;
|
||||
std::string::size_type start, end;
|
||||
std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in);
|
||||
// opening of the benchmark file
|
||||
if (! inputFile)
|
||||
throw std::runtime_error("*** ERROR : Unable to open the benchmark file");
|
||||
// number of jobs (N)
|
||||
getline(inputFile, buffer, '\n');
|
||||
N = atoi(buffer.data());
|
||||
// number of machines M
|
||||
getline(inputFile, buffer, '\n');
|
||||
M = atoi(buffer.data());
|
||||
// initial and current seeds (not used)
|
||||
getline(inputFile, buffer, '\n');
|
||||
// processing times and due-dates
|
||||
p = std::vector< std::vector<unsigned int> > (M,N);
|
||||
d = std::vector<unsigned int> (N);
|
||||
// for each job...
|
||||
for (unsigned int j=0 ; j<N ; j++)
|
||||
{
|
||||
// index of the job (<=> j)
|
||||
getline(inputFile, buffer, '\n');
|
||||
// due-date of the job j
|
||||
getline(inputFile, buffer, '\n');
|
||||
d[j] = atoi(buffer.data());
|
||||
// processing times of the job j on each machine
|
||||
getline(inputFile, buffer, '\n');
|
||||
start = buffer.find_first_not_of(" ");
|
||||
for (unsigned int i=0 ; i<M ; i++)
|
||||
{
|
||||
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
|
||||
inputFile.close();
|
||||
// closing of the input file
|
||||
inputFile.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopBenchmarkParser.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 FlowShopBenchmarkParser
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
|
|
@ -86,7 +86,7 @@ public:
|
|||
void printOn(std::ostream & _os) const;
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** number of machines */
|
||||
unsigned int M;
|
||||
|
|
@ -104,6 +104,6 @@ private:
|
|||
*/
|
||||
void init(const std::string _benchmarkFileName);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*FLOWSHOPBENCHMARKPARSER_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopEval.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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) :
|
||||
M(_M), N (_N), p(_p), d(_d)
|
||||
M(_M), N (_N), p(_p), d(_d)
|
||||
{}
|
||||
|
||||
|
||||
void FlowShopEval::operator()(FlowShop & _flowshop)
|
||||
{
|
||||
FlowShopObjectiveVector objVector;
|
||||
objVector[0] = makespan(_flowshop);
|
||||
objVector[1] = tardiness(_flowshop);
|
||||
_flowshop.objectiveVector(objVector);
|
||||
FlowShopObjectiveVector objVector;
|
||||
objVector[0] = makespan(_flowshop);
|
||||
objVector[1] = tardiness(_flowshop);
|
||||
_flowshop.objectiveVector(objVector);
|
||||
}
|
||||
|
||||
|
||||
|
||||
double FlowShopEval::makespan(const FlowShop & _flowshop)
|
||||
{
|
||||
// completion times computation for each job on each 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);
|
||||
return C[M-1][_flowshop[N-1]];
|
||||
// completion times computation for each job on each 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);
|
||||
return C[M-1][_flowshop[N-1]];
|
||||
}
|
||||
|
||||
|
||||
double FlowShopEval::tardiness(const FlowShop & _flowshop)
|
||||
{
|
||||
// completion times computation for each job on each 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);
|
||||
// tardiness computation
|
||||
unsigned int long sum = 0;
|
||||
for (unsigned int j=0 ; j<N ; j++)
|
||||
sum += (unsigned int) std::max (0, (int) (C[M-1][_flowshop[j]] - d[_flowshop[j]]));
|
||||
return sum;
|
||||
// completion times computation for each job on each 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);
|
||||
// tardiness computation
|
||||
unsigned int long sum = 0;
|
||||
for (unsigned int j=0 ; j<N ; j++)
|
||||
sum += (unsigned int) std::max (0, (int) (C[M-1][_flowshop[j]] - d[_flowshop[j]]));
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
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> > FlowShopEval::completionTime(const FlowShop & _flowshop)
|
||||
{
|
||||
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++)
|
||||
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++)
|
||||
C[i][_flowshop[j]] = std::max(C[i][_flowshop[j-1]], C[i-1][_flowshop[j]]) + p[i][_flowshop[j]];
|
||||
return C;
|
||||
C[i][_flowshop[j]] = std::max(C[i][_flowshop[j-1]], C[i-1][_flowshop[j]]) + p[i][_flowshop[j]];
|
||||
return C;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopEval.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -46,8 +46,8 @@
|
|||
* Evaluation of the objective vector a (multi-objective) FlowShop object
|
||||
*/
|
||||
class FlowShopEval : public moeoEvalFunc<FlowShop>
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
|
|
@ -66,7 +66,7 @@ public:
|
|||
void operator()(FlowShop & _flowshop);
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** number of machines */
|
||||
unsigned int M;
|
||||
|
|
@ -99,6 +99,6 @@ private:
|
|||
*/
|
||||
std::vector< std::vector<unsigned int> > completionTime (const FlowShop & _flowshop);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*FLOWSHOPEVAL_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopInit.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,21 +44,21 @@ FlowShopInit::FlowShopInit(unsigned int _N) : N(_N)
|
|||
|
||||
void FlowShopInit::operator()(FlowShop & _flowshop)
|
||||
{
|
||||
// scheduling vector
|
||||
std::vector<unsigned int> scheduling(N);
|
||||
// initialisation of possible values
|
||||
std::vector<unsigned int> possibles(N);
|
||||
for (unsigned int i=0 ; i<N ; i++)
|
||||
possibles[i] = i;
|
||||
// random initialization
|
||||
unsigned int rInd; // random index
|
||||
for (unsigned int i=0; i<N; i++)
|
||||
// scheduling vector
|
||||
std::vector<unsigned int> scheduling(N);
|
||||
// initialisation of possible values
|
||||
std::vector<unsigned int> possibles(N);
|
||||
for (unsigned int i=0 ; i<N ; i++)
|
||||
possibles[i] = i;
|
||||
// random initialization
|
||||
unsigned int rInd; // random index
|
||||
for (unsigned int i=0; i<N; i++)
|
||||
{
|
||||
rInd = (unsigned int) rng.uniform(N-i);
|
||||
scheduling[i] = possibles[rInd];
|
||||
possibles[rInd] = possibles[N-i-1];
|
||||
rInd = (unsigned int) rng.uniform(N-i);
|
||||
scheduling[i] = possibles[rInd];
|
||||
possibles[rInd] = possibles[N-i-1];
|
||||
}
|
||||
_flowshop.resize(N);
|
||||
_flowshop.value(scheduling);
|
||||
_flowshop.invalidate(); // IMPORTANT in case the _genotype is old
|
||||
_flowshop.resize(N);
|
||||
_flowshop.value(scheduling);
|
||||
_flowshop.invalidate(); // IMPORTANT in case the _genotype is old
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopInit.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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
|
||||
*/
|
||||
class FlowShopInit : public eoInit<FlowShop>
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
|
|
@ -62,11 +62,11 @@ public:
|
|||
void operator()(FlowShop & _flowshop);
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the number of jobs (size of a scheduling vector) */
|
||||
unsigned int N;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*FLOWSHOPINIT_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopObjectiveVector.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopObjectiveVectorTraits.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -40,18 +40,18 @@
|
|||
|
||||
bool FlowShopObjectiveVectorTraits::minimizing (int _i)
|
||||
{
|
||||
// minimizing both
|
||||
return true;
|
||||
// minimizing both
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FlowShopObjectiveVectorTraits::maximizing (int _i)
|
||||
{
|
||||
// minimizing both
|
||||
return false;
|
||||
// minimizing both
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int FlowShopObjectiveVectorTraits::nObjectives ()
|
||||
{
|
||||
// 2 objectives
|
||||
return 2;
|
||||
// 2 objectives
|
||||
return 2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopObjectiveVectorTraits.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,8 +44,8 @@
|
|||
* Definition of the objective vector traits for multi-objective flow-shop problems
|
||||
*/
|
||||
class FlowShopObjectiveVectorTraits : public moeoObjectiveVectorTraits
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Returns true if the _ith objective have to be minimzed
|
||||
|
|
@ -66,6 +66,6 @@ public:
|
|||
*/
|
||||
static unsigned int nObjectives ();
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*FLOWSHOPOBJECTIVEVECTORTRAITS_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopOpCrossoverQuad.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,71 +39,72 @@
|
|||
|
||||
|
||||
std::string FlowShopOpCrossoverQuad::className() const
|
||||
{
|
||||
{
|
||||
return "FlowShopOpCrossoverQuad";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FlowShopOpCrossoverQuad::operator()(FlowShop & _flowshop1, FlowShop & _flowshop2)
|
||||
{
|
||||
bool oneAtLeastIsModified;
|
||||
// computation of the 2 random points
|
||||
unsigned int point1, point2;
|
||||
do
|
||||
bool oneAtLeastIsModified;
|
||||
// computation of the 2 random points
|
||||
unsigned int point1, point2;
|
||||
do
|
||||
{
|
||||
point1 = 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;
|
||||
point1 = rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
|
||||
point2 = rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
|
||||
}
|
||||
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
|
||||
oneAtLeastIsModified = false;
|
||||
// update
|
||||
_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
|
||||
return oneAtLeastIsModified;
|
||||
else
|
||||
{
|
||||
// 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 result = _parent1;
|
||||
std::vector<bool> taken_values(result.size(), false);
|
||||
if (_point1 > _point2)
|
||||
std::swap(_point1, _point2);
|
||||
/* first parent */
|
||||
for (unsigned int i=0 ; i<=_point1 ; i++)
|
||||
FlowShop result = _parent1;
|
||||
std::vector<bool> taken_values(result.size(), false);
|
||||
if (_point1 > _point2)
|
||||
std::swap(_point1, _point2);
|
||||
/* first parent */
|
||||
for (unsigned int i=0 ; i<=_point1 ; i++)
|
||||
{
|
||||
// result[i] == _parent1[i]
|
||||
taken_values[_parent1[i]] = true;
|
||||
// result[i] == _parent1[i]
|
||||
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]
|
||||
taken_values[_parent1[i]] = true;
|
||||
// result[i] == _parent1[i]
|
||||
taken_values[_parent1[i]] = true;
|
||||
}
|
||||
/* second parent */
|
||||
unsigned int i = _point1+1;
|
||||
unsigned int j = 0;
|
||||
while (i<_point2 && j<_parent2.size())
|
||||
/* second parent */
|
||||
unsigned int i = _point1+1;
|
||||
unsigned int j = 0;
|
||||
while (i<_point2 && j<_parent2.size())
|
||||
{
|
||||
if (! taken_values[_parent2[j]])
|
||||
if (! taken_values[_parent2[j]])
|
||||
{
|
||||
result[i] = _parent2[j];
|
||||
i++;
|
||||
result[i] = _parent2[j];
|
||||
i++;
|
||||
}
|
||||
j++;
|
||||
j++;
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopOpCrossoverQuad.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
* Quadratic crossover operator for flow-shop (modify the both genotypes)
|
||||
*/
|
||||
class FlowShopOpCrossoverQuad : public eoQuadOp < FlowShop >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* the class name (used to display statistics)
|
||||
|
|
@ -62,7 +62,7 @@ public:
|
|||
bool operator()(FlowShop & _flowshop1, FlowShop & _flowshop2);
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*FLOWSHOPOPCROSSOVERQUAD_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopOpMutationExchange.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,37 +39,38 @@
|
|||
|
||||
|
||||
std::string FlowShopOpMutationExchange::className() const
|
||||
{
|
||||
{
|
||||
return "FlowShopOpMutationExchange";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FlowShopOpMutationExchange::operator()(FlowShop & _flowshop)
|
||||
{
|
||||
bool isModified;
|
||||
FlowShop result = _flowshop;
|
||||
// computation of the 2 random points
|
||||
unsigned int point1, point2;
|
||||
do
|
||||
bool isModified;
|
||||
FlowShop result = _flowshop;
|
||||
// computation of the 2 random points
|
||||
unsigned int point1, point2;
|
||||
do
|
||||
{
|
||||
point1 = 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;
|
||||
point1 = rng.random(result.size());
|
||||
point2 = rng.random(result.size());
|
||||
}
|
||||
else
|
||||
while (point1 == point2);
|
||||
// swap
|
||||
std::swap (result[point1], result[point2]);
|
||||
// update (if necessary)
|
||||
if (result != _flowshop)
|
||||
{
|
||||
// the genotype has not been modified
|
||||
isModified = false;
|
||||
// update
|
||||
_flowshop.value(result);
|
||||
// the genotype has been modified
|
||||
isModified = true;
|
||||
}
|
||||
// return 'true' if the genotype has been modified
|
||||
return isModified;
|
||||
else
|
||||
{
|
||||
// the genotype has not been modified
|
||||
isModified = false;
|
||||
}
|
||||
// return 'true' if the genotype has been modified
|
||||
return isModified;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopOpMutationExchange.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
* Exchange mutation operator for the flow-shop
|
||||
*/
|
||||
class FlowShopOpMutationExchange : public eoMonOp<FlowShop>
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* the class name (used to display statistics)
|
||||
|
|
@ -60,6 +60,6 @@ public:
|
|||
*/
|
||||
bool operator()(FlowShop & _flowshop);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*FLOWSHOPOPMUTATIONEXCHANGE_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopOpMutationShift.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,47 +39,48 @@
|
|||
|
||||
|
||||
std::string FlowShopOpMutationShift::className() const
|
||||
{
|
||||
{
|
||||
return "FlowShopOpMutationShift";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FlowShopOpMutationShift::operator()(FlowShop & _flowshop)
|
||||
{
|
||||
bool isModified;
|
||||
int direction;
|
||||
unsigned int tmp;
|
||||
FlowShop result = _flowshop;
|
||||
// computation of the 2 random points
|
||||
unsigned int point1, point2;
|
||||
do
|
||||
bool isModified;
|
||||
int direction;
|
||||
unsigned int tmp;
|
||||
FlowShop result = _flowshop;
|
||||
// computation of the 2 random points
|
||||
unsigned int point1, point2;
|
||||
do
|
||||
{
|
||||
point1 = 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;
|
||||
point1 = rng.random(result.size());
|
||||
point2 = rng.random(result.size());
|
||||
}
|
||||
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
|
||||
isModified = false;
|
||||
// update
|
||||
_flowshop.value(result);
|
||||
// the genotype has been modified
|
||||
isModified = true;
|
||||
}
|
||||
// return 'true' if the genotype has been modified
|
||||
return isModified;
|
||||
else
|
||||
{
|
||||
// the genotype has not been modified
|
||||
isModified = false;
|
||||
}
|
||||
// return 'true' if the genotype has been modified
|
||||
return isModified;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <FlowShopOpMutationShift.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,8 +45,8 @@
|
|||
* Shift mutation operator for flow-shop
|
||||
*/
|
||||
class FlowShopOpMutationShift : public eoMonOp < FlowShop >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* the class name (used to display statistics)
|
||||
|
|
@ -60,6 +60,6 @@ public:
|
|||
*/
|
||||
bool operator()(FlowShop & _flowshop);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*FLOWSHOPOPMUTATIONSHIFT_H_*/
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue