add algo
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@368 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
c20c1918ec
commit
f2d6974e3b
11 changed files with 1408 additions and 0 deletions
21
branches/paradiseo-moeo-1.0/src/algo/moeoAlgo.h
Normal file
21
branches/paradiseo-moeo-1.0/src/algo/moeoAlgo.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoAlgo.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEOALGO_H_
|
||||||
|
#define MOEOALGO_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for multi-objective algorithms.
|
||||||
|
*/
|
||||||
|
class moeoAlgo {};
|
||||||
|
|
||||||
|
#endif /*MOEOALGO_H_*/
|
||||||
67
branches/paradiseo-moeo-1.0/src/algo/moeoCombinedLS.h
Normal file
67
branches/paradiseo-moeo-1.0/src/algo/moeoCombinedLS.h
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoCombinedLS.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEOCOMBINEDLS_H_
|
||||||
|
#define MOEOCOMBINEDLS_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <algo/moeoLS.h>
|
||||||
|
#include <archive/moeoArchive.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class allows to embed a set of local searches that are sequentially applied,
|
||||||
|
* and so working and updating the same archive of non-dominated solutions.
|
||||||
|
*/
|
||||||
|
template < class MOEOT, class Type >
|
||||||
|
class moeoCombinedLS : public moeoLS < MOEOT, Type >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor
|
||||||
|
* @param _first_mols the first multi-objective local search to add
|
||||||
|
*/
|
||||||
|
moeoCombinedLS(moeoLS < MOEOT, Type > & _first_mols)
|
||||||
|
{
|
||||||
|
combinedLS.push_back (& _first_mols);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new local search to combine
|
||||||
|
* @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.
|
||||||
|
* The new non-dominated solutions are added to the archive
|
||||||
|
* @param _type the object to apply the local search to
|
||||||
|
* @param _arch the archive of non-dominated solutions
|
||||||
|
*/
|
||||||
|
void operator () (Type _type, moeoArchive < MOEOT > & _arch)
|
||||||
|
{
|
||||||
|
for (unsigned int i=0; i<combinedLS.size(); i++)
|
||||||
|
combinedLS[i] -> operator()(_type, _arch);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/** the vector that contains the combined LS */
|
||||||
|
std::vector< moeoLS < MOEOT, Type > * > combinedLS;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*MOEOCOMBINEDLS_H_*/
|
||||||
25
branches/paradiseo-moeo-1.0/src/algo/moeoEA.h
Normal file
25
branches/paradiseo-moeo-1.0/src/algo/moeoEA.h
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoEA.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEOEA_H_
|
||||||
|
#define MOEOEA_H_
|
||||||
|
|
||||||
|
#include <eoAlgo.h>
|
||||||
|
#include <algo/moeoAlgo.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for multi-objective evolutionary algorithms.
|
||||||
|
*/
|
||||||
|
template < class MOEOT >
|
||||||
|
class moeoEA : public moeoAlgo, public eoAlgo < MOEOT > {};
|
||||||
|
|
||||||
|
#endif /*MOEOEA_H_*/
|
||||||
218
branches/paradiseo-moeo-1.0/src/algo/moeoEasyEA.h
Executable file
218
branches/paradiseo-moeo-1.0/src/algo/moeoEasyEA.h
Executable file
|
|
@ -0,0 +1,218 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoEasyEA.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef _MOEOEASYEA_H
|
||||||
|
#define _MOEOEASYEA_H
|
||||||
|
|
||||||
|
#include <apply.h>
|
||||||
|
#include <eoBreed.h>
|
||||||
|
#include <eoContinue.h>
|
||||||
|
#include <eoMergeReduce.h>
|
||||||
|
#include <eoPopEvalFunc.h>
|
||||||
|
#include <eoSelect.h>
|
||||||
|
#include <eoTransform.h>
|
||||||
|
#include <algo/moeoEA.h>
|
||||||
|
#include <diversity/moeoDiversityAssignment.h>
|
||||||
|
#include <diversity/moeoDummyDiversityAssignment.h>
|
||||||
|
#include <fitness/moeoFitnessAssignment.h>
|
||||||
|
#include <replacement/moeoReplacement.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An easy class to design multi-objective evolutionary algorithms.
|
||||||
|
*/
|
||||||
|
template < class MOEOT >
|
||||||
|
class moeoEasyEA: public moeoEA < MOEOT >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor taking a breed and merge.
|
||||||
|
* @param _continuator the stopping criteria
|
||||||
|
* @param _eval the evaluation functions
|
||||||
|
* @param _breed the breeder
|
||||||
|
* @param _replace the replacement strategy
|
||||||
|
* @param _fitnessEval the fitness evaluation scheme
|
||||||
|
* @param _diversityEval the diversity evaluation scheme
|
||||||
|
* @param _evalFitAndDivBeforeSelection put this parameter to 'true' if you want to re-evalue the fitness and the diversity of the population before the selection process
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor taking a breed, a merge and a eoPopEval.
|
||||||
|
* @param _continuator the stopping criteria
|
||||||
|
* @param _popEval the evaluation functions for the whole population
|
||||||
|
* @param _breed the breeder
|
||||||
|
* @param _replace the replacement strategy
|
||||||
|
* @param _fitnessEval the fitness evaluation scheme
|
||||||
|
* @param _diversityEval the diversity evaluation scheme
|
||||||
|
* @param _evalFitAndDivBeforeSelection put this parameter to 'true' if you want to re-evalue the fitness and the diversity of the population before the selection process
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor taking a breed, a merge and a reduce.
|
||||||
|
* @param _continuator the stopping criteria
|
||||||
|
* @param _eval the evaluation functions
|
||||||
|
* @param _breed the breeder
|
||||||
|
* @param _merge the merge scheme
|
||||||
|
* @param _reduce the reduce scheme
|
||||||
|
* @param _fitnessEval the fitness evaluation scheme
|
||||||
|
* @param _diversityEval the diversity evaluation scheme
|
||||||
|
* @param _evalFitAndDivBeforeSelection put this parameter to 'true' if you want to re-evalue the fitness and the diversity of the population before the selection process
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor taking a select, a transform and a replacement.
|
||||||
|
* @param _continuator the stopping criteria
|
||||||
|
* @param _eval the evaluation functions
|
||||||
|
* @param _select the selection scheme
|
||||||
|
* @param _transform the tranformation scheme
|
||||||
|
* @param _replace the replacement strategy
|
||||||
|
* @param _fitnessEval the fitness evaluation scheme
|
||||||
|
* @param _diversityEval the diversity evaluation scheme
|
||||||
|
* @param _evalFitAndDivBeforeSelection put this parameter to 'true' if you want to re-evalue the fitness and the diversity of the population before the selection process
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor taking a select, a transform, a merge and a reduce.
|
||||||
|
* @param _continuator the stopping criteria
|
||||||
|
* @param _eval the evaluation functions
|
||||||
|
* @param _select the selection scheme
|
||||||
|
* @param _transform the tranformation scheme
|
||||||
|
* @param _merge the merge scheme
|
||||||
|
* @param _reduce the reduce scheme
|
||||||
|
* @param _fitnessEval the fitness evaluation scheme
|
||||||
|
* @param _diversityEval the diversity evaluation scheme
|
||||||
|
* @param _evalFitAndDivBeforeSelection put this parameter to 'true' if you want to re-evalue the fitness and the diversity of the population before the selection process
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a few generation of evolution to the population _pop.
|
||||||
|
* @param _pop the population
|
||||||
|
*/
|
||||||
|
virtual void operator()(eoPop < MOEOT > & _pop)
|
||||||
|
{
|
||||||
|
eoPop < MOEOT > offspring, empty_pop;
|
||||||
|
popEval(empty_pop, _pop); // A first eval of pop.
|
||||||
|
bool firstTime = true;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Population shrinking!");
|
||||||
|
}
|
||||||
|
else if (pSize < _pop.size())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Population growing!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::string s = e.what();
|
||||||
|
s.append( " in moeoEasyEA");
|
||||||
|
throw std::runtime_error( s );
|
||||||
|
}
|
||||||
|
} while (continuator(_pop));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
/** the stopping criteria */
|
||||||
|
eoContinue < MOEOT > & continuator;
|
||||||
|
/** the evaluation functions */
|
||||||
|
eoEvalFunc < MOEOT > & eval;
|
||||||
|
/** to evaluate the whole population */
|
||||||
|
eoPopLoopEval < MOEOT > loopEval;
|
||||||
|
/** to evaluate the whole population */
|
||||||
|
eoPopEvalFunc < MOEOT > & popEval;
|
||||||
|
/** breed: a select followed by a transform */
|
||||||
|
eoSelectTransform < MOEOT > selectTransform;
|
||||||
|
/** the breeder */
|
||||||
|
eoBreed < MOEOT > & breed;
|
||||||
|
/** replacement: a merge followed by a reduce */
|
||||||
|
eoMergeReduce < MOEOT > mergeReduce;
|
||||||
|
/** the replacment strategy */
|
||||||
|
moeoReplacement < MOEOT > & replace;
|
||||||
|
/** the fitness assignment strategy */
|
||||||
|
moeoFitnessAssignment < MOEOT > & fitnessEval;
|
||||||
|
/** the diversity assignment strategy */
|
||||||
|
moeoDiversityAssignment < MOEOT > & diversityEval;
|
||||||
|
/** 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;
|
||||||
|
/** a dummy select */
|
||||||
|
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;
|
||||||
|
/** a dummy merge */
|
||||||
|
eoNoElitism < MOEOT > dummyMerge;
|
||||||
|
/** a dummy reduce */
|
||||||
|
eoTruncate < MOEOT > dummyReduce;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*MOEOEASYEA_H_*/
|
||||||
76
branches/paradiseo-moeo-1.0/src/algo/moeoHybridLS.h
Normal file
76
branches/paradiseo-moeo-1.0/src/algo/moeoHybridLS.h
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoHybridLS.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEOHYBRIDLS_H_
|
||||||
|
#define MOEOHYBRIDLS_H_
|
||||||
|
|
||||||
|
#include <eoContinue.h>
|
||||||
|
#include <eoPop.h>
|
||||||
|
#include <eoSelect.h>
|
||||||
|
#include <utils/eoUpdater.h>
|
||||||
|
#include <algo/moeoLS.h>
|
||||||
|
#include <archive/moeoArchive.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class allows to apply a multi-objective local search to a number of selected individuals contained in the archive
|
||||||
|
* at every generation until a stopping criteria is verified.
|
||||||
|
*/
|
||||||
|
template < class MOEOT >
|
||||||
|
class moeoHybridLS : public eoUpdater
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor
|
||||||
|
* @param _term stopping criteria
|
||||||
|
* @param _select selector
|
||||||
|
* @param _mols a multi-objective local search
|
||||||
|
* @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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies the multi-objective local search to selected individuals contained in the archive if the stopping criteria is not verified
|
||||||
|
*/
|
||||||
|
void operator () ()
|
||||||
|
{
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
mols(selectedSolutions[i], arch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/** stopping criteria */
|
||||||
|
eoContinue < MOEOT > & term;
|
||||||
|
/** selector */
|
||||||
|
eoSelect < MOEOT > & select;
|
||||||
|
/** multi-objective local search */
|
||||||
|
moeoLS < MOEOT, MOEOT > & mols;
|
||||||
|
/** archive */
|
||||||
|
moeoArchive < MOEOT > & arch;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*MOEOHYBRIDLS_H_*/
|
||||||
168
branches/paradiseo-moeo-1.0/src/algo/moeoIBEA.h
Normal file
168
branches/paradiseo-moeo-1.0/src/algo/moeoIBEA.h
Normal file
|
|
@ -0,0 +1,168 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoIBEA.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEOIBEA_H_
|
||||||
|
#define MOEOIBEA_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <eoBreed.h>
|
||||||
|
#include <eoContinue.h>
|
||||||
|
#include <eoEvalFunc.h>
|
||||||
|
#include <eoGenContinue.h>
|
||||||
|
#include <eoGeneralBreeder.h>
|
||||||
|
#include <eoGenOp.h>
|
||||||
|
#include <eoPopEvalFunc.h>
|
||||||
|
#include <eoSGAGenOp.h>
|
||||||
|
#include <algo/moeoEA.h>
|
||||||
|
#include <diversity/moeoDummyDiversityAssignment.h>
|
||||||
|
#include <fitness/moeoIndicatorBasedFitnessAssignment.h>
|
||||||
|
#include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
|
||||||
|
#include <replacement/moeoEnvironmentalReplacement.h>
|
||||||
|
#include <selection/moeoDetTournamentSelect.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IBEA (Indicator-Based Evolutionary Algorithm) as described in:
|
||||||
|
* E. Zitzler, S. Künzli, "Indicator-Based Selection in Multiobjective Search", Proc. 8th International Conference on Parallel Problem Solving from Nature (PPSN VIII), pp. 832-842, Birmingham, UK (2004).
|
||||||
|
* This class builds the IBEA algorithm only by using the fine-grained components of the ParadisEO-MOEO framework.
|
||||||
|
*/
|
||||||
|
template < class MOEOT >
|
||||||
|
class moeoIBEA : public moeoEA < MOEOT >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** The type of objective vector */
|
||||||
|
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple ctor with a eoGenOp.
|
||||||
|
* @param _maxGen number of generations before stopping
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
* @param _metric metric
|
||||||
|
* @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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple ctor with a eoTransform.
|
||||||
|
* @param _maxGen number of generations before stopping
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
* @param _metric metric
|
||||||
|
* @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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor with a crossover, a mutation and their corresponding rates.
|
||||||
|
* @param _maxGen number of generations before stopping
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _crossover crossover
|
||||||
|
* @param _pCross crossover probability
|
||||||
|
* @param _mutation mutation
|
||||||
|
* @param _pMut mutation probability
|
||||||
|
* @param _metric metric
|
||||||
|
* @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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor with a continuator (instead of _maxGen) and a eoGenOp.
|
||||||
|
* @param _continuator stopping criteria
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
* @param _metric metric
|
||||||
|
* @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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor with a continuator (instead of _maxGen) and a eoTransform.
|
||||||
|
* @param _continuator stopping criteria
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
* @param _metric metric
|
||||||
|
* @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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply a few generation of evolution to the population _pop until the stopping criteria is verified.
|
||||||
|
* @param _pop the population
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
{
|
||||||
|
// 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:
|
||||||
|
|
||||||
|
/** a continuator based on the number of generations (used as default) */
|
||||||
|
eoGenContinue < MOEOT > defaultGenContinuator;
|
||||||
|
/** stopping criteria */
|
||||||
|
eoContinue < MOEOT > & continuator;
|
||||||
|
/** evaluation function used to evaluate the whole population */
|
||||||
|
eoPopLoopEval < MOEOT > popEval;
|
||||||
|
/** binary tournament selection */
|
||||||
|
moeoDetTournamentSelect < MOEOT > select;
|
||||||
|
/** fitness assignment used in IBEA */
|
||||||
|
moeoIndicatorBasedFitnessAssignment < MOEOT > fitnessAssignment;
|
||||||
|
/** dummy diversity assignment */
|
||||||
|
moeoDummyDiversityAssignment < MOEOT > dummyDiversityAssignment;
|
||||||
|
/** elitist replacement */
|
||||||
|
moeoEnvironmentalReplacement < MOEOT > replace;
|
||||||
|
/** an object for genetic operators (used as default) */
|
||||||
|
eoSGAGenOp < MOEOT > defaultSGAGenOp;
|
||||||
|
/** general breeder */
|
||||||
|
eoGeneralBreeder < MOEOT > genBreed;
|
||||||
|
/** breeder */
|
||||||
|
eoBreed < MOEOT > & breed;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*MOEOIBEA_H_*/
|
||||||
280
branches/paradiseo-moeo-1.0/src/algo/moeoIBMOLS.h
Executable file
280
branches/paradiseo-moeo-1.0/src/algo/moeoIBMOLS.h
Executable file
|
|
@ -0,0 +1,280 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoIBMOLS.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEOIBMOLS_H_
|
||||||
|
#define MOEOIBMOLS_H_
|
||||||
|
|
||||||
|
#include <eoContinue.h>
|
||||||
|
#include <eoEvalFunc.h>
|
||||||
|
#include <eoPop.h>
|
||||||
|
#include <moMove.h>
|
||||||
|
#include <moMoveInit.h>
|
||||||
|
#include <moNextMove.h>
|
||||||
|
#include <algo/moeoLS.h>
|
||||||
|
#include <archive/moeoArchive.h>
|
||||||
|
#include <fitness/moeoIndicatorBasedFitnessAssignment.h>
|
||||||
|
#include <move/moeoMoveIncrEval.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicator-Based Multi-Objective Local Search (IBMOLS) as described in
|
||||||
|
* Basseur M., Burke K. : "Indicator-Based Multi-Objective Local Search" (2007).
|
||||||
|
*/
|
||||||
|
template < class MOEOT, class Move >
|
||||||
|
class moeoIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** The type of objective vector */
|
||||||
|
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor.
|
||||||
|
* @param _moveInit the move initializer
|
||||||
|
* @param _nextMove the neighborhood explorer
|
||||||
|
* @param _eval the full evaluation
|
||||||
|
* @param _moveIncrEval the incremental evaluation
|
||||||
|
* @param _fitnessAssignment the fitness assignment strategy
|
||||||
|
* @param _continuator the stopping criteria
|
||||||
|
*/
|
||||||
|
moeoIBMOLS(
|
||||||
|
moMoveInit < Move > & _moveInit,
|
||||||
|
moNextMove < Move > & _nextMove,
|
||||||
|
eoEvalFunc < MOEOT > & _eval,
|
||||||
|
moeoMoveIncrEval < Move > & _moveIncrEval,
|
||||||
|
moeoIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
|
||||||
|
eoContinue < MOEOT > & _continuator
|
||||||
|
) :
|
||||||
|
moveInit(_moveInit),
|
||||||
|
nextMove(_nextMove),
|
||||||
|
eval(_eval),
|
||||||
|
moveIncrEval(_moveIncrEval),
|
||||||
|
fitnessAssignment (_fitnessAssignment),
|
||||||
|
continuator (_continuator)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply the local search until a local archive does not change or
|
||||||
|
* another stopping criteria is met and update the archive _arch with new non-dominated solutions.
|
||||||
|
* @param _pop the initial population
|
||||||
|
* @param _arch the (updated) archive
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
{
|
||||||
|
previousArchive.update(archive);
|
||||||
|
oneStep(_pop);
|
||||||
|
archive.update(_pop);
|
||||||
|
} while ( (! archive.equals(previousArchive)) && (continuator(_arch)) );
|
||||||
|
_arch.update(archive);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/** the move initializer */
|
||||||
|
moMoveInit < Move > & moveInit;
|
||||||
|
/** the neighborhood explorer */
|
||||||
|
moNextMove < Move > & nextMove;
|
||||||
|
/** the full evaluation */
|
||||||
|
eoEvalFunc < MOEOT > & eval;
|
||||||
|
/** the incremental evaluation */
|
||||||
|
moeoMoveIncrEval < Move > & moveIncrEval;
|
||||||
|
/** the fitness assignment strategy */
|
||||||
|
moeoIndicatorBasedFitnessAssignment < MOEOT > & fitnessAssignment;
|
||||||
|
/** the stopping criteria */
|
||||||
|
eoContinue < MOEOT > & continuator;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply one step of the local search to the population _pop
|
||||||
|
* @param _pop the population
|
||||||
|
*/
|
||||||
|
void oneStep (eoPop < MOEOT > & _pop)
|
||||||
|
{
|
||||||
|
////////////////////////////////////////////
|
||||||
|
int ext_0_idx, ext_1_idx;
|
||||||
|
ObjectiveVector ext_0_objVec, ext_1_objVec;
|
||||||
|
///////////////////////////////////////////
|
||||||
|
// 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))
|
||||||
|
{
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// qui sont les extremes ? (=> 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_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]) )
|
||||||
|
{
|
||||||
|
ext_0_idx = k;
|
||||||
|
ext_0_objVec = _pop[k].objectiveVector();
|
||||||
|
}
|
||||||
|
// ext_1
|
||||||
|
else if (_pop[k].objectiveVector()[1] < ext_1_objVec[1])
|
||||||
|
{
|
||||||
|
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]) )
|
||||||
|
{
|
||||||
|
ext_1_idx = k;
|
||||||
|
ext_1_objVec = _pop[k].objectiveVector();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// worst init
|
||||||
|
if (ext_0_idx == -1)
|
||||||
|
{
|
||||||
|
unsigned int ind = 0;
|
||||||
|
while (ind == ext_1_idx)
|
||||||
|
{
|
||||||
|
ind++;
|
||||||
|
}
|
||||||
|
worst_idx = ind;
|
||||||
|
worst_objVec = _pop[ind].objectiveVector();
|
||||||
|
worst_fitness = _pop[ind].fitness();
|
||||||
|
}
|
||||||
|
else if (ext_1_idx == -1)
|
||||||
|
{
|
||||||
|
unsigned int ind = 0;
|
||||||
|
while (ind == ext_0_idx)
|
||||||
|
{
|
||||||
|
ind++;
|
||||||
|
}
|
||||||
|
worst_idx = ind;
|
||||||
|
worst_objVec = _pop[ind].objectiveVector();
|
||||||
|
worst_fitness = _pop[ind].fitness();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
worst_idx = -1;
|
||||||
|
worst_objVec = x_objVec;
|
||||||
|
worst_fitness = x_fitness;
|
||||||
|
}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// who is the worst ?
|
||||||
|
for (unsigned int j=0; j<_pop.size(); j++)
|
||||||
|
{
|
||||||
|
if ( (j!=ext_0_idx) && (j!=ext_1_idx) )
|
||||||
|
{
|
||||||
|
if (_pop[j].fitness() < worst_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 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())
|
||||||
|
{
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
// 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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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())
|
||||||
|
{
|
||||||
|
// initilization of the move for the next individual
|
||||||
|
moveInit(move, _pop[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// update fitness values
|
||||||
|
fitnessAssignment.updateByDeleting(_pop, worst_objVec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*MOEOIBMOLS_H_*/
|
||||||
215
branches/paradiseo-moeo-1.0/src/algo/moeoIteratedIBMOLS.h
Executable file
215
branches/paradiseo-moeo-1.0/src/algo/moeoIteratedIBMOLS.h
Executable file
|
|
@ -0,0 +1,215 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoIteratedIBMOLS.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEOITERATEDIBMOLS_H_
|
||||||
|
#define MOEOITERATEDIBMOLS_H_
|
||||||
|
|
||||||
|
#include <eoContinue.h>
|
||||||
|
#include <eoEvalFunc.h>
|
||||||
|
#include <eoOp.h>
|
||||||
|
#include <eoPop.h>
|
||||||
|
#include <utils/rnd_generators.h>
|
||||||
|
#include <moMove.h>
|
||||||
|
#include <moMoveInit.h>
|
||||||
|
#include <moNextMove.h>
|
||||||
|
#include <algo/moeoIBMOLS.h>
|
||||||
|
#include <algo/moeoLS.h>
|
||||||
|
#include <archive/moeoArchive.h>
|
||||||
|
#include <fitness/moeoIndicatorBasedFitnessAssignment.h>
|
||||||
|
#include <move/moeoMoveIncrEval.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//#include <rsCrossQuad.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterated version of IBMOLS as described in
|
||||||
|
* Basseur M., Burke K. : "Indicator-Based Multi-Objective Local Search" (2007).
|
||||||
|
*/
|
||||||
|
template < class MOEOT, class Move >
|
||||||
|
class moeoIteratedIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** The type of objective vector */
|
||||||
|
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor.
|
||||||
|
* @param _moveInit the move initializer
|
||||||
|
* @param _nextMove the neighborhood explorer
|
||||||
|
* @param _eval the full evaluation
|
||||||
|
* @param _moveIncrEval the incremental evaluation
|
||||||
|
* @param _fitnessAssignment the fitness assignment strategy
|
||||||
|
* @param _continuator the stopping criteria
|
||||||
|
* @param _monOp the monary operator
|
||||||
|
* @param _randomMonOp the random monary operator (or random initializer)
|
||||||
|
* @param _nNoiseIterations the number of iterations to apply the random noise
|
||||||
|
*/
|
||||||
|
moeoIteratedIBMOLS(
|
||||||
|
moMoveInit < Move > & _moveInit,
|
||||||
|
moNextMove < Move > & _nextMove,
|
||||||
|
eoEvalFunc < MOEOT > & _eval,
|
||||||
|
moeoMoveIncrEval < Move > & _moveIncrEval,
|
||||||
|
moeoIndicatorBasedFitnessAssignment < 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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply the local search iteratively until the stopping criteria is met.
|
||||||
|
* @param _pop the initial population
|
||||||
|
* @param _arch the (updated) archive
|
||||||
|
*/
|
||||||
|
void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/** the local search to iterate */
|
||||||
|
moeoIBMOLS < MOEOT, Move > ibmols;
|
||||||
|
/** the full evaluation */
|
||||||
|
eoEvalFunc < MOEOT > & eval;
|
||||||
|
/** the stopping criteria */
|
||||||
|
eoContinue < MOEOT > & continuator;
|
||||||
|
/** the monary operator */
|
||||||
|
eoMonOp < MOEOT > & monOp;
|
||||||
|
/** the random monary operator (or random initializer) */
|
||||||
|
eoMonOp < MOEOT > & randomMonOp;
|
||||||
|
/** the number of iterations to apply the random noise */
|
||||||
|
unsigned int nNoiseIterations;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new population randomly initialized and/or initialized from the archive _arch.
|
||||||
|
* @param _pop the output population
|
||||||
|
* @param _arch the archive
|
||||||
|
*/
|
||||||
|
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[i] = i;
|
||||||
|
}
|
||||||
|
// randomize shuffle
|
||||||
|
UF_random_generator <unsigned int 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
|
||||||
|
{
|
||||||
|
// add it to the resulting pop
|
||||||
|
_pop[i] = _arch[shuffle[i]];
|
||||||
|
// then, apply the operator nIterationsNoise times
|
||||||
|
for (unsigned int j=0; j<nNoiseIterations; j++)
|
||||||
|
{
|
||||||
|
monOp(_pop[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// a randomly generated solution needs to be added
|
||||||
|
{
|
||||||
|
// random initialization
|
||||||
|
randomMonOp(_pop[i]);
|
||||||
|
}
|
||||||
|
// evaluation of the new individual
|
||||||
|
_pop[i].invalidate();
|
||||||
|
eval(_pop[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// A DEVELOPPER RAPIDEMENT POUR TESTER AVEC CROSSOVER //
|
||||||
|
/*
|
||||||
|
void generateNewSolutions2(eoPop < MOEOT > & _pop, const moeoArchive < MOEOT > & _arch)
|
||||||
|
{
|
||||||
|
// here, we must have a QuadOp !
|
||||||
|
//eoQuadOp < MOEOT > quadOp;
|
||||||
|
rsCrossQuad quadOp;
|
||||||
|
// shuffle vector for the random selection of individuals
|
||||||
|
vector<unsigned int> shuffle;
|
||||||
|
shuffle.resize(_arch.size());
|
||||||
|
// init shuffle
|
||||||
|
for (unsigned int i=0; i<shuffle.size(); i++)
|
||||||
|
{
|
||||||
|
shuffle[i] = i;
|
||||||
|
}
|
||||||
|
// randomize shuffle
|
||||||
|
UF_random_generator <unsigned int int> gen;
|
||||||
|
std::random_shuffle(shuffle.begin(), shuffle.end(), gen);
|
||||||
|
// start the creation of new solutions
|
||||||
|
unsigned int i=0;
|
||||||
|
while ((i<_pop.size()-1) && (i<_arch.size()-1))
|
||||||
|
{
|
||||||
|
_pop[i] = _arch[shuffle[i]];
|
||||||
|
_pop[i+1] = _arch[shuffle[i+1]];
|
||||||
|
// then, apply the operator nIterationsNoise times
|
||||||
|
for (unsigned int j=0; j<nNoiseIterations; j++)
|
||||||
|
{
|
||||||
|
quadOp(_pop[i], _pop[i+1]);
|
||||||
|
}
|
||||||
|
eval(_pop[i]);
|
||||||
|
eval(_pop[i+1]);
|
||||||
|
i=i+2;
|
||||||
|
}
|
||||||
|
// do we have to add some random solutions ?
|
||||||
|
while (i<_pop.size())
|
||||||
|
{
|
||||||
|
randomMonOp(_pop[i]);
|
||||||
|
eval(_pop[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*MOEOITERATEDIBMOLS_H_*/
|
||||||
27
branches/paradiseo-moeo-1.0/src/algo/moeoLS.h
Normal file
27
branches/paradiseo-moeo-1.0/src/algo/moeoLS.h
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoLS.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEOLS_H_
|
||||||
|
#define MOEOLS_H_
|
||||||
|
|
||||||
|
#include <eoFunctor.h>
|
||||||
|
#include <algo/moeoAlgo.h>
|
||||||
|
#include <archive/moeoArchive.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for local searches applied to multi-objective optimization.
|
||||||
|
* 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 > {};
|
||||||
|
|
||||||
|
#endif /*MOEOLS_H_*/
|
||||||
158
branches/paradiseo-moeo-1.0/src/algo/moeoNSGA.h
Normal file
158
branches/paradiseo-moeo-1.0/src/algo/moeoNSGA.h
Normal file
|
|
@ -0,0 +1,158 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoNSGA.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEONSGA_H_
|
||||||
|
#define MOEONSGA_H_
|
||||||
|
|
||||||
|
#include <eoBreed.h>
|
||||||
|
#include <eoContinue.h>
|
||||||
|
#include <eoEvalFunc.h>
|
||||||
|
#include <eoGenContinue.h>
|
||||||
|
#include <eoGeneralBreeder.h>
|
||||||
|
#include <eoGenOp.h>
|
||||||
|
#include <eoPopEvalFunc.h>
|
||||||
|
#include <eoSGAGenOp.h>
|
||||||
|
#include <algo/moeoEA.h>
|
||||||
|
#include <diversity/moeoFrontByFrontSharingDiversityAssignment.h>
|
||||||
|
#include <fitness/moeoFastNonDominatedSortingFitnessAssignment.h>
|
||||||
|
#include <replacement/moeoElitistReplacement.h>
|
||||||
|
#include <selection/moeoDetTournamentSelect.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NSGA (Non-dominated Sorting Genetic Algorithm) as described in:
|
||||||
|
* N. Srinivas, K. Deb, "Multiobjective Optimization Using Nondominated Sorting in Genetic Algorithms".
|
||||||
|
* Evolutionary Computation, Vol. 2(3), No 2, pp. 221-248 (1994).
|
||||||
|
* This class builds the NSGA algorithm only by using the fine-grained components of the ParadisEO-MOEO framework.
|
||||||
|
*/
|
||||||
|
template < class MOEOT >
|
||||||
|
class moeoNSGA: public moeoEA < MOEOT >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple ctor with a eoGenOp.
|
||||||
|
* @param _maxGen number of generations before stopping
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
* @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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple ctor with a eoTransform.
|
||||||
|
* @param _maxGen number of generations before stopping
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
* @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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor with a crossover, a mutation and their corresponding rates.
|
||||||
|
* @param _maxGen number of generations before stopping
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _crossover crossover
|
||||||
|
* @param _pCross crossover probability
|
||||||
|
* @param _mutation mutation
|
||||||
|
* @param _pMut mutation probability
|
||||||
|
* @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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor with a continuator (instead of _maxGen) and a eoGenOp.
|
||||||
|
* @param _continuator stopping criteria
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
* @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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor with a continuator (instead of _maxGen) and a eoTransform.
|
||||||
|
* @param _continuator stopping criteria
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
* @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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply a few generation of evolution to the population _pop until the stopping criteria is verified.
|
||||||
|
* @param _pop the population
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
{
|
||||||
|
// 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:
|
||||||
|
|
||||||
|
/** a continuator based on the number of generations (used as default) */
|
||||||
|
eoGenContinue < MOEOT > defaultGenContinuator;
|
||||||
|
/** stopping criteria */
|
||||||
|
eoContinue < MOEOT > & continuator;
|
||||||
|
/** evaluation function used to evaluate the whole population */
|
||||||
|
eoPopLoopEval < MOEOT > popEval;
|
||||||
|
/** binary tournament selection */
|
||||||
|
moeoDetTournamentSelect < MOEOT > select;
|
||||||
|
/** fitness assignment used in NSGA-II */
|
||||||
|
moeoFastNonDominatedSortingFitnessAssignment < MOEOT > fitnessAssignment;
|
||||||
|
/** diversity assignment used in NSGA-II */
|
||||||
|
moeoFrontByFrontSharingDiversityAssignment < MOEOT > diversityAssignment;
|
||||||
|
/** elitist replacement */
|
||||||
|
moeoElitistReplacement < MOEOT > replace;
|
||||||
|
/** an object for genetic operators (used as default) */
|
||||||
|
eoSGAGenOp < MOEOT > defaultSGAGenOp;
|
||||||
|
/** general breeder */
|
||||||
|
eoGeneralBreeder < MOEOT > genBreed;
|
||||||
|
/** breeder */
|
||||||
|
eoBreed < MOEOT > & breed;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*MOEONSGAII_H_*/
|
||||||
153
branches/paradiseo-moeo-1.0/src/algo/moeoNSGAII.h
Normal file
153
branches/paradiseo-moeo-1.0/src/algo/moeoNSGAII.h
Normal file
|
|
@ -0,0 +1,153 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoNSGAII.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEONSGAII_H_
|
||||||
|
#define MOEONSGAII_H_
|
||||||
|
|
||||||
|
#include <eoBreed.h>
|
||||||
|
#include <eoContinue.h>
|
||||||
|
#include <eoEvalFunc.h>
|
||||||
|
#include <eoGenContinue.h>
|
||||||
|
#include <eoGeneralBreeder.h>
|
||||||
|
#include <eoGenOp.h>
|
||||||
|
#include <eoPopEvalFunc.h>
|
||||||
|
#include <eoSGAGenOp.h>
|
||||||
|
#include <algo/moeoEA.h>
|
||||||
|
#include <diversity/moeoFrontByFrontCrowdingDistanceDiversityAssignment.h>
|
||||||
|
#include <fitness/moeoFastNonDominatedSortingFitnessAssignment.h>
|
||||||
|
#include <replacement/moeoElitistReplacement.h>
|
||||||
|
#include <selection/moeoDetTournamentSelect.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NSGA-II (Non-dominated Sorting Genetic Algorithm II) as described in:
|
||||||
|
* Deb, K., S. Agrawal, A. Pratap, and T. Meyarivan : "A fast elitist non-dominated sorting genetic algorithm for multi-objective optimization: NSGA-II".
|
||||||
|
* In IEEE Transactions on Evolutionary Computation, Vol. 6, No 2, pp 182-197 (April 2002).
|
||||||
|
* This class builds the NSGA-II algorithm only by using the fine-grained components of the ParadisEO-MOEO framework.
|
||||||
|
*/
|
||||||
|
template < class MOEOT >
|
||||||
|
class moeoNSGAII: public moeoEA < MOEOT >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple ctor with a eoGenOp.
|
||||||
|
* @param _maxGen number of generations before stopping
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
*/
|
||||||
|
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
|
||||||
|
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
||||||
|
replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple ctor with a eoTransform.
|
||||||
|
* @param _maxGen number of generations before stopping
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
*/
|
||||||
|
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) :
|
||||||
|
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
|
||||||
|
replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor with a crossover, a mutation and their corresponding rates.
|
||||||
|
* @param _maxGen number of generations before stopping
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _crossover crossover
|
||||||
|
* @param _pCross crossover probability
|
||||||
|
* @param _mutation mutation
|
||||||
|
* @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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor with a continuator (instead of _maxGen) and a eoGenOp.
|
||||||
|
* @param _continuator stopping criteria
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
*/
|
||||||
|
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
|
||||||
|
continuator(_continuator), popEval(_eval), select(2),
|
||||||
|
replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor with a continuator (instead of _maxGen) and a eoTransform.
|
||||||
|
* @param _continuator stopping criteria
|
||||||
|
* @param _eval evaluation function
|
||||||
|
* @param _op variation operator
|
||||||
|
*/
|
||||||
|
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) :
|
||||||
|
continuator(_continuator), popEval(_eval), select(2),
|
||||||
|
replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply a few generation of evolution to the population _pop until the stopping criteria is verified.
|
||||||
|
* @param _pop the population
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
{
|
||||||
|
// 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:
|
||||||
|
|
||||||
|
/** a continuator based on the number of generations (used as default) */
|
||||||
|
eoGenContinue < MOEOT > defaultGenContinuator;
|
||||||
|
/** stopping criteria */
|
||||||
|
eoContinue < MOEOT > & continuator;
|
||||||
|
/** evaluation function used to evaluate the whole population */
|
||||||
|
eoPopLoopEval < MOEOT > popEval;
|
||||||
|
/** binary tournament selection */
|
||||||
|
moeoDetTournamentSelect < MOEOT > select;
|
||||||
|
/** fitness assignment used in NSGA-II */
|
||||||
|
moeoFastNonDominatedSortingFitnessAssignment < MOEOT > fitnessAssignment;
|
||||||
|
/** diversity assignment used in NSGA-II */
|
||||||
|
moeoFrontByFrontCrowdingDistanceDiversityAssignment < MOEOT > diversityAssignment;
|
||||||
|
/** elitist replacement */
|
||||||
|
moeoElitistReplacement < MOEOT > replace;
|
||||||
|
/** an object for genetic operators (used as default) */
|
||||||
|
eoSGAGenOp < MOEOT > defaultSGAGenOp;
|
||||||
|
/** general breeder */
|
||||||
|
eoGeneralBreeder < MOEOT > genBreed;
|
||||||
|
/** breeder */
|
||||||
|
eoBreed < MOEOT > & breed;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*MOEONSGAII_H_*/
|
||||||
Loading…
Add table
Add a link
Reference in a new issue