new version

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@267 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
liefooga 2007-04-17 15:53:56 +00:00
commit 5df71ee73a
42 changed files with 3554 additions and 824 deletions

View file

@ -0,0 +1,288 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// MOEO.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEO_H_
#define MOEO_H_
#include <iostream>
#include <stdexcept>
#include <string>
#include <EO.h>
/**
* Base class allowing to represent a solution (an individual) for multi-objective optimization.
* The template argument MOEOObjectiveVector allows to represent the solution in the objective space (it can be a moeoObjectiveVector object).
* The template argument MOEOFitness is an object reflecting the quality of the solution in term of convergence (the fitness of a solution is always to be maximized).
* The template argument MOEODiversity is an object reflecting the quality of the solution in term of diversity (the diversity of a solution is always to be maximized).
* All template arguments must have a void and a copy constructor.
* Besides, note that, contrary to the mono-objective case (and to EO) where the fitness value of a solution is confused with its objective value,
* the fitness value differs of the objectives values in the multi-objective case.
*/
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
class MOEO : public EO < MOEOObjectiveVector >
{
public:
/** the objective vector type of a solution */
typedef MOEOObjectiveVector ObjectiveVector;
/** the fitness type of a solution */
typedef MOEOFitness Fitness;
/** the diversity type of a solution */
typedef MOEODiversity Diversity;
/**
* Ctor
*/
MOEO()
{
// default values for every parameters
objectiveVectorValue = ObjectiveVector();
fitnessValue = Fitness();
diversityValue = Diversity();
// invalidate all
invalidate();
}
/**
* Virtual dtor
*/
virtual ~MOEO() {};
/**
* Returns the objective vector of the current solution
*/
ObjectiveVector objectiveVector() const
{
if ( invalidObjectiveVector() )
{
throw std::runtime_error("invalid objective vector");
}
return objectiveVectorValue;
}
/**
* Sets the objective vector of the current solution
* @param _objectiveVectorValue the new objective vector
*/
void objectiveVector(const ObjectiveVector & _objectiveVectorValue)
{
objectiveVectorValue = _objectiveVectorValue;
invalidObjectiveVectorValue = false;
}
/**
* Sets the objective vector as invalid
*/
void invalidateObjectiveVector()
{
invalidObjectiveVectorValue = true;
}
/**
* 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 (MOEO)");
}
return fitnessValue;
}
/**
* Sets the fitness value of the current solution
* @param _fitnessValue the new fitness value
*/
void fitness(const Fitness & _fitnessValue)
{
fitnessValue = _fitnessValue;
invalidFitnessValue = false;
}
/**
* Sets the fitness value as invalid
*/
void invalidateFitness()
{
invalidFitnessValue = true;
}
/**
* 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");
}
return diversityValue;
}
/**
* Sets the diversity value of the current solution
* @param _diversityValue the new diversity value
*/
void diversity(const Diversity & _diversityValue)
{
diversityValue = _diversityValue;
invalidDiversityValue = false;
}
/**
* Sets the diversity value as invalid
*/
void invalidateDiversity()
{
invalidDiversityValue = true;
}
/**
* Returns true if the diversity value is invalid, false otherwise
*/
bool invalidDiversity() const
{
return invalidDiversityValue;
}
/**
* Sets the objective vector, the fitness value and the diversity value as invalid
*/
void invalidate()
{
invalidateObjectiveVector();
invalidateFitness();
invalidateDiversity();
}
/**
* Returns true if the fitness value is invalid, false otherwise
*/
bool invalid() const
{
return invalidObjectiveVector();
}
/**
* Returns true if the objective vector of the current solution is smaller than the objective vector of _other on the first objective,
* then on the second, and so on (can be usefull for sorting/printing).
* You should implement another function in the sub-class of MOEO to have another sorting mecanism.
* @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";
}
/**
* Writing object
* @param _os output stream
*/
virtual void printOn(std::ostream & _os) const
{
if ( invalidObjectiveVector() )
{
_os << "INVALID\t";
}
else
{
_os << objectiveVectorValue << '\t';
}
}
/**
* Reading object
* @param _is input stream
*/
virtual void readFrom(std::istream & _is)
{
std::string objectiveVector_str;
int pos = _is.tellg();
_is >> objectiveVector_str;
if (objectiveVector_str == "INVALID")
{
invalidateObjectiveVector();
}
else
{
invalidObjectiveVectorValue = false;
_is.seekg(pos); // rewind
_is >> objectiveVectorValue;
}
}
private:
/** the objective vector of this solution */
ObjectiveVector objectiveVectorValue;
/** true if the objective vector is invalid */
bool invalidObjectiveVectorValue;
/** the fitness value of this solution */
Fitness fitnessValue;
/** true if the fitness value is invalid */
bool invalidFitnessValue;
/** the diversity value of this solution */
Diversity diversityValue;
/** true if the diversity value is invalid */
bool invalidDiversityValue;
};
#endif /*MOEO_H_*/

0
trunk/paradiseo-moeo/src/Makefile.am Executable file → Normal file
View file

View file

@ -2,7 +2,7 @@
//-----------------------------------------------------------------------------
// moeo
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
@ -13,6 +13,43 @@
#ifndef MOEO_
#define MOEO_
#include <moeo.h>
#include <eo>
#endif /*MOEO_H_*/
#include <MOEO.h>
#include <moeoArchiveObjectiveVectorSavingUpdater.h>
#include <moeoArchiveUpdater.h>
#include <moeoArchive.h>
#include <moeoCombinedLS.h>
#include <moeoComparator.h>
#include <moeoConvertPopToObjectiveVectors.h>
#include <moeoCrowdingDistanceDiversityAssignment.h>
#include <moeoDetTournamentSelect.h>
#include <moeoDiversityAssignment.h>
#include <moeoEA.h>
#include <moeoEasyEA.h>
#include <moeoElitistReplacement.h>
#include <moeoEnvironmentalReplacement.h>
#include <moeoEvalFunc.h>
#include <moeoFastNonDominatedSortingFitnessAssignment.h>
#include <moeoFitnessAssignment.h>
#include <moeoGenerationalReplacement.h>
#include <moeoHybridLS.h>
#include <moeoIndicatorBasedFitnessAssignment.h>
#include <moeoLS.h>
#include <moeoNSGAII.h>
#include <moeoObjectiveVectorComparator.h>
#include <moeoObjectiveVector.h>
#include <moeoRandomSelect.h>
#include <moeoReplacement.h>
#include <moeoRouletteSelect.h>
#include <moeoSelectFromPopAndArch.h>
#include <moeoSelectOne.h>
#include <moeoStochTournamentSelect.h>
#include <moeoVector.h>
#include <metric/moeoBinaryMetricSavingUpdater.h>
#include <metric/moeoContributionMetric.h>
#include <metric/moeoEntropyMetric.h>
#include <metric/moeoMetric.h>
#include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
#endif /*MOEO_*/

View file

@ -1,31 +0,0 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeo.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEO_H_
#define MOEO_H_
#include <eo>
#include <moeoArchiveFitnessSavingUpdater.h>
#include <moeoArchiveUpdater.h>
#include <moeoArchive.h>
#include <moeoCombinedMOLS.h>
#include <moeoHybridMOLS.h>
#include <moeoMOLS.h>
#include <moeoReplacement.h>
#include <moeoSelectOneFromPopAndArch.h>
#include <metric/moeoBinaryMetricSavingUpdater.h>
#include <metric/moeoContributionMetric.h>
#include <metric/moeoEntropyMetric.h>
#include <metric/moeoMetric.h>
#endif /*MOEO_H_ */

View file

@ -2,7 +2,7 @@
//-----------------------------------------------------------------------------
// moeoArchive.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
@ -14,92 +14,165 @@
#define MOEOARCHIVE_H_
#include <eoPop.h>
#include <moeoObjectiveVectorComparator.h>
/**
* An archive is a secondary population that stores non-dominated solutions
* An archive is a secondary population that stores non-dominated solutions.
*/
template < class EOT > class moeoArchive:public eoPop < EOT >
template < class MOEOT >
class moeoArchive : public eoPop < MOEOT >
{
public:
using std::vector < EOT >::size;
using std::vector < EOT >::operator[];
using std::vector < EOT >::back;
using std::vector < EOT >::pop_back;
using std::vector < MOEOT > :: size;
using std::vector < MOEOT > :: operator[];
using std::vector < MOEOT > :: back;
using std::vector < MOEOT > :: pop_back;
/**
* The fitness type of a solution
*/
typedef typename EOT::Fitness EOFitness;
/**
* Returns true if the current archive dominates _fit
* @param _fit the (Pareto) fitness to compare with the current archive
*/
bool dominates (const EOFitness & _fit) const
{
for (unsigned i = 0; i < size; i++)
if (operator[](i).fitness ().dominates (_fit))
return true;
return false;
}
/**
* The type of an objective vector for a solution
*/
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Returns true if the current archive contains _fit
* @param _fit the (Pareto) fitness to search within the current archive
*/
bool contains (const EOFitness & _fit) const
{
for (unsigned i = 0; i < size; i++)
if (operator[](i).fitness () == _fit)
return true;
return false;
}
/**
* Updates the archive with a given individual _eo
* @param _eo the given individual
*/
void update (const EOT & _eo)
{
// Removing the dominated solutions from the archive
for (unsigned j = 0; j < size ();)
{
if (_eo.fitness ().dominates (operator[](j).fitness ()))
{
operator[](j) = back ();
pop_back ();
}
else if (_eo.fitness () == operator[](j).fitness ())
{
operator[](j) = back ();
pop_back ();
}
else
j++;
}
/**
* Default ctor.
* The moeoObjectiveVectorComparator used to compare solutions is based on Pareto dominance
*/
moeoArchive() : eoPop < MOEOT >(), comparator(paretoComparator)
{}
// Dominated ?
bool dom = false;
for (unsigned j = 0; j < size (); j++)
if (operator [](j).fitness ().dominates (_eo.fitness ()))
{
dom = true;
break;
}
if (!dom)
push_back (_eo);
}
/**
* Updates the archive with a given population _pop
* @param _pop the given population
*/
void update (const eoPop < EOT > &_pop)
{
for (unsigned i = 0; i < _pop.size (); i++)
update (_pop[i]);
}
/**
* Ctor
* @param _comparator the moeoObjectiveVectorComparator used to compare solutions
*/
moeoArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator) : eoPop < MOEOT >(), comparator(_comparator)
{}
/**
* Returns true if the current archive dominates _objectiveVector according to the moeoObjectiveVectorComparator given in the constructor
* @param _objectiveVector the objective vector to compare with the current archive
*/
bool dominates (const ObjectiveVector & _objectiveVector) const
{
for (unsigned i = 0; i<size(); i++)
{
if ( comparator(operator[](i).fitness(), _objectiveVector) )
{
return true;
}
}
return false;
}
/**
* Returns true if the current archive already contains a solution with the same objective values than _objectiveVector
* @param _objectiveVector the objective vector to compare with the current archive
*/
bool contains (const ObjectiveVector & _objectiveVector) const
{
for (unsigned i = 0; i<size(); i++)
{
if (operator[](i).objectiveVector() == _objectiveVector)
{
return true;
}
}
return false;
}
/**
* Updates the archive with a given individual _moeo
* @param _moeo the given individual
*/
void update (const MOEOT & _moeo)
{
// first step: removing the dominated solutions from the archive
for (unsigned j=0; j<size();)
{
// if _moeo dominates the jth solution contained in the archive
if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
{
operator[](j) = back();
pop_back();
}
else if (_moeo.objectiveVector() == operator[](j).objectiveVector())
{
operator[](j) = back();
pop_back();
}
else
{
j++;
}
}
// second step: is _moeo dominated?
bool dom = false;
for (unsigned j=0; j<size(); j++)
{
// if the jth solution contained in the archive dominates _moeo
if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
{
dom = true;
break;
}
}
if (!dom)
{
push_back(_moeo);
}
}
/**
* Updates the archive with a given population _pop
* @param _pop the given population
*/
void update (const eoPop < MOEOT > & _pop)
{
for (unsigned i=0; i<_pop.size(); i++)
{
update(_pop[i]);
}
}
/**
* Returns true if the current archive contains the same objective vectors
* than the given archive _arch
* @param _arch the given archive
*/
bool equals (const moeoArchive < MOEOT > & _arch)
{
for (unsigned i=0; i<size(); i++)
{
if (! _arch.contains(operator[](i).objectiveVector()))
{
return false;
}
}
for (unsigned i=0; i<_arch.size() ; i++)
{
if (! contains(_arch[i].objectiveVector()))
{
return false;
}
}
return true;
}
private:
/** The moeoObjectiveVectorComparator used to compare solutions */
moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
/** A moeoObjectiveVectorComparator based on Pareto dominance (used as default) */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
};

View file

@ -1,73 +0,0 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoArchiveFitnessSavingUpdater.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOARCHIVEFITNESSSAVINGUPDATER_H_
#define MOEOARCHIVEFITNESSSAVINGUPDATER_H_
#include <fstream>
#include <string>
#include <eoPop.h>
#include <utils/eoUpdater.h>
#include <moeoArchive.h>
#define MAX_BUFFER_SIZE 1000
/**
* This class allows to save the fitnesses of solutions contained in an archive into a file at each generation.
*/
template < class EOT > class moeoArchiveFitnessSavingUpdater:public eoUpdater
{
public:
/**
* Ctor
* @param _arch local archive
* @param _filename target filename
* @param _id own ID
*/
moeoArchiveFitnessSavingUpdater (moeoArchive < EOT > &_arch, const std::string & _filename = "Res/Arch", int _id = -1):arch (_arch), filename (_filename), id (_id),
counter
(0)
{
}
/**
* Saves the fitness of the archive's members into the file
*/
void operator () ()
{
char buff[MAX_BUFFER_SIZE];
if (id == -1)
sprintf (buff, "%s.%u", filename.c_str (), counter++);
else
sprintf (buff, "%s.%u.%u", filename.c_str (), id, counter++);
std::ofstream f (buff);
for (unsigned i = 0; i < arch.size (); i++)
f << arch[i].fitness () << std::endl;
f.close ();
}
private:
/** local archive */
moeoArchive < EOT > &arch;
/** target filename */
std::string filename;
/** own ID */
int id;
/** counter */
unsigned counter;
};
#endif /*MOEOARCHIVEFITNESSSAVINGUPDATER_H_ */

View file

@ -0,0 +1,70 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoArchiveObjectiveVectorSavingUpdater.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_
#define MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_
#include <fstream>
#include <string>
#include <eoPop.h>
#include <utils/eoUpdater.h>
#include <moeoArchive.h>
#define MAX_BUFFER_SIZE 1000
/**
* This class allows to save the fitnesses of solutions contained in an archive into a file at each generation.
*/
template <class EOT>
class moeoArchiveObjectiveVectorSavingUpdater : public eoUpdater
{
public:
/**
* Ctor
* @param _arch local archive
* @param _filename target filename
* @param _id own ID
*/
moeoArchiveObjectiveVectorSavingUpdater (moeoArchive<EOT> & _arch, const std::string & _filename, int _id = -1) : arch(_arch), filename(_filename), id(_id), counter(0)
{}
/**
* Saves the fitness of the archive's members into the file
*/
void operator()() {
char buff[MAX_BUFFER_SIZE];
if (id == -1)
sprintf (buff, "%s.%u", filename.c_str(), counter ++);
else
sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++);
std::ofstream f(buff);
for (unsigned i = 0; i < arch.size (); i++)
f << arch[i].objectiveVector() << std::endl;
f.close ();
}
private:
/** local archive */
moeoArchive<EOT> & arch;
/** target filename */
std::string filename;
/** own ID */
int id;
/** counter */
unsigned counter;
};
#endif /*MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_*/

View file

@ -2,7 +2,7 @@
//-----------------------------------------------------------------------------
// moeoArchiveUpdater.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
@ -18,39 +18,37 @@
#include <moeoArchive.h>
/**
* This class allows to update the archive at each generation with newly found non-dominated solutions
* This class allows to update the archive at each generation with newly found non-dominated solutions.
*/
template < class EOT > class moeoArchiveUpdater:public eoUpdater
template < class MOEOT >
class moeoArchiveUpdater : public eoUpdater
{
public:
/**
* Ctor
* @param _arch an archive of non-dominated solutions
* @param _pop the main population
*/
moeoArchiveUpdater (moeoArchive < EOT > &_arch,
const eoPop < EOT > &_pop):arch (_arch), pop (_pop)
{
}
/**
* Ctor
* @param _arch an archive of non-dominated solutions
* @param _pop the main population
*/
moeoArchiveUpdater(moeoArchive < MOEOT > & _arch, const eoPop < MOEOT > & _pop) : arch(_arch), pop(_pop)
{}
/**
* Updates the archive with newly found non-dominated solutions contained in the main population
*/
void operator () ()
{
arch.update (pop);
}
/**
* Updates the archive with newly found non-dominated solutions contained in the main population
*/
void operator()() {
arch.update(pop);
}
private:
/** the archive of non-dominated solutions */
moeoArchive < EOT > &arch;
/** the main population */
const eoPop < EOT > &pop;
/** the archive of non-dominated solutions */
moeoArchive < MOEOT > & arch;
/** the main population */
const eoPop < MOEOT > & pop;
};
#endif /*MOEOARCHIVEUPDATER_H_ */
#endif /*MOEOARCHIVEUPDATER_H_*/

View file

@ -0,0 +1,66 @@
// -*- 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 <moeoArchive.h>
#include <moeoLS.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 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_*/

View file

@ -1,71 +0,0 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoCombinedMOLS.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOCOMBINEDMOLS_H_
#define MOEOCOMBINEDMOLS_H_
#include <eoEvalFunc.h>
#include <moeoArchive.h>
#include <moeoMOLS.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 EOT > class moeoCombinedMOLS:public moeoMOLS < EOT >
{
public:
/**
* Ctor
* @param _eval the full evaluator of a solution
* @param _first_ls the first multi-objective local search to add
*/
moeoCombinedMOLS (eoEvalFunc < EOT > &_eval, moeoMOLS < EOT > &_first_ls):eval
(_eval)
{
combinedMOLS.push_back (&_first_ls);
}
/**
* Adds a new local search to combine
* @param _ls the multi-objective local search to add
*/
void add (moeoMOLS < EOT > &_ls)
{
combinedMOLS.push_back (&_ls);
}
/**
* Gives a new solution in order to explore the neigborhood.
* The new non-dominated solutions are added to the archive
* @param _eo the solution
* @param _arch the archive of non-dominated solutions
*/
void operator () (const EOT & _eo, moeoArchive < EOT > &_arch)
{
eval (const_cast < EOT & >(_eo));
for (unsigned i = 0; i < combinedMOLS.size (); i++)
combinedMOLS[i]->operator ()(_eo, _arch);
}
private:
/** the full evaluator of a solution */
eoEvalFunc < EOT > &eval;
/** the vector that contains the combined MOLS */
std::vector < moeoMOLS < EOT > *>combinedMOLS;
};
#endif /*MOEOCOMBINEDMOLS_H_ */

View file

@ -0,0 +1,133 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOCOMPARATOR_H_
#define MOEOCOMPARATOR_H_
#include <eoFunctor.h>
/**
* Functor allowing to compare two solutions.
*/
template < class MOEOT >
class moeoComparator : public eoBF < const MOEOT &, const MOEOT &, const bool >
{};
/**
* Functor allowing to compare two solutions according to their first objective value, then their second, and so on.
*/
template < class MOEOT >
class moeoObjectiveComparator : public moeoComparator < MOEOT >
{
public:
/**
* Returns true if _moeo1 is greater than _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 _moeo1.objectiveVector() > _moeo2.objectiveVector();
}
};
/**
* Functor allowing to compare two solutions according to one objective.
*/
template < class MOEOT >
class moeoOneObjectiveComparator : public moeoComparator < MOEOT >
{
public:
/**
* Ctor.
* @param _obj the index of objective
*/
moeoOneObjectiveComparator(unsigned _obj) : obj(_obj)
{
if (obj > MOEOT::ObjectiveVector::nObjectives())
{
throw std::runtime_error("Problem with the index of objective in moeoOneObjectiveComparator");
}
}
/**
* Returns true if _moeo1 is greater than _moeo2 on the obj objective
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return _moeo1.objectiveVector()[obj] > _moeo2.objectiveVector()[obj];
}
private:
/** the index of objective */
unsigned obj;
};
/**
* Functor allowing to compare two solutions according to their fitness values, then according to their diversity values.
*/
template < class MOEOT >
class moeoFitnessThenDiversityComparator : public moeoComparator < MOEOT >
{
public:
/**
* Returns true if _moeo1 is greater than _moeo2 according to their fitness values, then according to their diversity values
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
if (_moeo1.fitness() == _moeo2.fitness())
{
return _moeo1.diversity() > _moeo2.diversity();
}
else
{
return _moeo1.fitness() > _moeo2.fitness();
}
}
};
/**
* Functor allowing to compare two solutions according to their diversity values, then according to their fitness values.
*/
template < class MOEOT >
class moeoDiversityThenFitnessComparator : public moeoComparator < MOEOT >
{
public:
/**
* Returns true if _moeo1 is greater than _moeo2 according to their diversity values, then according to their fitness values
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
if (_moeo1.diversity() == _moeo2.diversity())
{
return _moeo1.fitness() > _moeo2.fitness();
}
else
{
return _moeo1.diversity() > _moeo2.diversity();
}
}
};
#endif /*MOEOCOMPARATOR_H_*/

View file

@ -0,0 +1,42 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoConvertPopToObjectiveVectors.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOPOPTOOBJECTIVEVECTORS_H_
#define MOEOPOPTOOBJECTIVEVECTORS_H_
#include <eoFunctor.h>
/**
* Functor allowing to get a vector of objective vectors from a population
*/
template < class MOEOT, class ObjectiveVector = typename MOEOT::ObjectiveVector >
class moeoConvertPopToObjectiveVectors : public eoUF < const eoPop < MOEOT >, const std::vector < ObjectiveVector > >
{
public:
/**
* Returns a vector of the objective vectors from the population _pop
* @param _pop the population
*/
const std::vector < ObjectiveVector > operator()(const eoPop < MOEOT > _pop)
{
std::vector < ObjectiveVector > result;
result.resize(_pop.size());
for (unsigned i=0; i<_pop.size(); i++)
{
result.push_back(_pop[i].objectiveVector());
}
return result;
}
};
#endif /*MOEOPOPTOOBJECTIVEVECTORS_H_*/

View file

@ -0,0 +1,114 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoCrowdingDistanceDiversityAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOCROWDINGDISTANCEDIVERSITYASSIGNMENT_H_
#define MOEOCROWDINGDISTANCEDIVERSITYASSIGNMENT_H_
#include <eoPop.h>
#include <moeoComparator.h>
#include <moeoDiversityAssignment.h>
/**
* Diversity assignment sheme based on crowding distance proposed in:
* K. Deb, A. Pratap, S. Agarwal, T. Meyarivan, "A Fast and Elitist Multi-Objective Genetic Algorithm: NSGA-II", IEEE Transactions on Evolutionary Computation, vol. 6, no. 2 (2002).
* This strategy is, for instance, used in NSGA-II.
*/
template < class MOEOT >
class moeoCrowdingDistanceDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{
public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Returns a big value (regarded as infinite)
*/
double inf() const
{
return std::numeric_limits<double>::max();
}
/**
* Computes diversity values for every solution contained in the population _pop
* @param _pop the population
*/
void operator()(eoPop < MOEOT > & _pop)
{
if (_pop.size() <= 2)
{
for (unsigned i=0; i<_pop.size(); i++)
{
_pop[i].diversity(inf());
}
}
else
{
setDistances(_pop);
}
}
/**
* @warning NOT IMPLEMENTED, DO NOTHING !
* Updates the diversity values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
* @param _pop the population
* @param _objVec the objective vector
* @warning NOT IMPLEMENTED, DO NOTHING !
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << endl;
}
private:
/**
* Sets the distance values
* @param _pop the population
*/
void setDistances (eoPop < MOEOT > & _pop)
{
double min, max, distance;
unsigned nObjectives = MOEOT::ObjectiveVector::nObjectives();
// set diversity to 0
for (unsigned i=0; i<_pop.size(); i++)
{
_pop[i].diversity(0);
}
// for each objective
for (unsigned obj=0; obj<nObjectives; obj++)
{
// comparator
moeoOneObjectiveComparator < MOEOT > comp(obj);
// sort
std::sort(_pop.begin(), _pop.end(), comp);
// 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 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);
}
}
}
};
#endif /*MOEOCROWDINGDISTANCEDIVERSITYASSIGNMENT_H_*/

View file

@ -0,0 +1,84 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoDetTournamentSelect.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEODETTOURNAMENTSELECT_H_
#define MOEODETTOURNAMENTSELECT_H_
#include <moeoComparator.h>
#include <moeoSelectOne.h>
#include <moeoSelectors.h>
/**
* Selection strategy that selects ONE individual by deterministic tournament.
*/
template < class MOEOT > class moeoDetTournamentSelect:public moeoSelectOne <
MOEOT >
{
public:
/**
* Full Ctor.
* @param _comparator the comparator (used to compare 2 individuals)
* @param _tSize the number of individuals in the tournament (default: 2)
*/
moeoDetTournamentSelect (moeoComparator < MOEOT > &_comparator, unsigned _tSize = 2):
comparator (_comparator), tSize (_tSize)
{
// consistency check
if (tSize < 2)
{
std::
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
tSize = 2;
}
}
/**
* Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default.
* @param _tSize the number of individuals in the tournament (default: 2)
*/
moeoDetTournamentSelect (unsigned _tSize = 2):
comparator (*(new moeoFitnessThenDiversityComparator < MOEOT > ())),
tSize (_tSize)
{
// consistency check
if (tSize < 2)
{
std::
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
tSize = 2;
}
}
/**
* Apply the tournament to the given population
* @param _pop the population
*/
const MOEOT & operator () (const eoPop < MOEOT > &_pop)
{
// use the selector
return mo_deterministic_tournament (_pop, tSize, comparator);
}
protected:
/** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > &comparator;
/** the number of individuals in the tournament */
unsigned tSize;
};
#endif /*MOEODETTOURNAMENTSELECT_H_ */

View file

@ -0,0 +1,93 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoDiversityAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEODIVERSITYASSIGNMENT_H_
#define MOEODIVERSITYASSIGNMENT_H_
#include <eoFunctor.h>
#include <eoPop.h>
/**
* Functor that sets the diversity values of a whole population.
*/
template < class MOEOT >
class moeoDiversityAssignment : public eoUF < eoPop < MOEOT > &, void >
{
public:
/** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Updates the diversity values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
* @param _pop the population
* @param _objVec the objective vector
*/
virtual void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) = 0;
/**
* Updates the diversity values of the whole population _pop by taking the deletion of the individual _moeo into account.
* @param _pop the population
* @param _moeo the individual
*/
void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo)
{
updateByDeleting(_pop, _moeo.objectiveVector());
}
};
/**
* moeoDummyDiversityAssignment is a moeoDiversityAssignment that gives the value '0' as the individual's diversity for a whole population if it is invalid.
*/
template < class MOEOT >
class moeoDummyDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{
public:
/** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Sets the diversity to '0' for every individuals of the population _pop if it is invalid
* @param _pop the population
*/
void operator () (eoPop < MOEOT > & _pop)
{
for (unsigned idx = 0; idx<_pop.size (); idx++)
{
if (_pop[idx].invalidDiversity())
{
// set the diversity to 0
_pop[idx].diversity(0.0);
}
}
}
/**
* Updates the diversity values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
* @param _pop the population
* @param _objVec the objective vector
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
// nothing to do... ;-)
}
};
#endif /*MOEODIVERSITYASSIGNMENT_H_*/

View 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>
/**
* Abstract class for multi-objective evolutionary algorithms.
*/
template < class MOEOT >
class moeoEA : public eoAlgo < MOEOT > {};
#endif /*MOEOEA_H_*/

View file

@ -0,0 +1,120 @@
// -*- 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 <eoPopEvalFunc.h>
#include <eoContinue.h>
#include <eoTransform.h>
#include <eoBreed.h>
#include <eoMergeReduce.h>
#include <moeoEA.h>
#include <eoReplacement.h>
#include <moeoFitnessAssignment.h>
#include <moeoDiversityAssignment.h>
/**
* An easy class to design multi-objective evolutionary algorithms.
*/
template < class MOEOT >
class moeoEasyEA: public moeoEA < MOEOT >
{
public:
/**
* Ctor.
* @param _continuator the stopping criteria
* @param _eval the evaluation functions
* @param _breed the breeder
* @param _replace the replacment 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, eoReplacement < MOEOT > & _replace,
moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
:
continuator(_continuator), eval (_eval), loopEval(_eval), popEval(loopEval), breed(_breed), replace(_replace), 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 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;
/** the breeder */
eoBreed < MOEOT > & breed;
/** the replacment strategy */
eoReplacement < 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;
};
#endif /*MOEOEASYEA_H_*/

View file

@ -0,0 +1,137 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoElitistReplacement.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOELITISTREPLACEMENT_H_
#define MOEOELITISTREPLACEMENT_H_
#include <moeoReplacement.h>
#include <moeoComparator.h>
#include <moeoFitnessAssignment.h>
#include <moeoDiversityAssignment.h>
/**
* Elitist replacement strategy that consists in keeping the N best individuals.
*/
template < class MOEOT > class moeoElitistReplacement:public moeoReplacement < MOEOT >
{
public:
/**
* Full constructor.
* @param _evalFitness the fitness assignment strategy
* @param _evalDiversity the diversity assignment strategy
* @param _comparator the comparator (used to compare 2 individuals)
*/
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity, moeoComparator < MOEOT > & _comparator) :
evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (_comparator)
{}
/**
* Constructor without comparator. A moeoFitThenDivComparator is used as default.
* @param _evalFitness the fitness assignment strategy
* @param _evalDiversity the diversity assignment strategy
*/
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity) :
evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (*(new moeoFitnessThenDiversityComparator < MOEOT >))
{}
/**
* Constructor without moeoDiversityAssignement. A dummy diversity is used as default.
* @param _evalFitness the fitness assignment strategy
* @param _comparator the comparator (used to compare 2 individuals)
*/
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoComparator < MOEOT > & _comparator) :
evalFitness (_evalFitness), evalDiversity (*(new moeoDummyDiversityAssignment < MOEOT >)), comparator (_comparator)
{}
/**
* Constructor without moeoDiversityAssignement nor moeoComparator.
* A moeoFitThenDivComparator and a dummy diversity are used as default.
* @param _evalFitness the fitness assignment strategy
*/
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness) :
evalFitness (_evalFitness), evalDiversity (*(new moeoDummyDiversityAssignment < MOEOT >)), comparator (*(new moeoFitnessThenDiversityComparator < MOEOT >))
{}
/**
* Replaces the first population by adding the individuals of the second one, sorting with a moeoComparator and resizing the whole population obtained.
* @param _parents the population composed of the parents (the population you want to replace)
* @param _offspring the offspring population
*/
void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring)
{
unsigned sz = _parents.size ();
// merges offspring and parents into a global population
_parents.reserve (_parents.size () + _offspring.size ());
copy (_offspring.begin (), _offspring.end (), back_inserter (_parents));
// evaluates the fitness and the diversity of this global population
evalFitness (_parents);
evalDiversity (_parents);
// sorts the whole population according to the comparator
Cmp cmp(comparator);
std::sort(_parents.begin(), _parents.end(), cmp);
// finally, resize this global population
_parents.resize (sz);
// and clear the offspring population
_offspring.clear ();
}
protected:
/** the fitness assignment strategy */
moeoFitnessAssignment < MOEOT > & evalFitness;
/** the diversity assignment strategy */
moeoDiversityAssignment < MOEOT > & evalDiversity;
/** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > & comparator;
/**
* This class is used to compare solutions in order to sort the population.
*/
class Cmp
{
public:
/**
* Ctor.
* @param _comparator the comparator
*/
Cmp(moeoComparator < MOEOT > & _comparator) : comparator(_comparator)
{}
/**
* Returns true if _moeo1 is greater than _moeo2 according to the comparator
* _moeo1 the first individual
* _moeo2 the first individual
*/
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return comparator(_moeo1,_moeo2);
}
private:
/** the comparator */
moeoComparator < MOEOT > & comparator;
};
};
#endif /*MOEOELITISTREPLACEMENT_H_ */

View file

@ -0,0 +1,149 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoEnvironmentalReplacement.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOENVIRONMENTALREPLACEMENT_H_
#define MOEOENVIRONMENTALREPLACEMENT_H_
#include <moeoReplacement.h>
#include <moeoComparator.h>
#include <moeoFitnessAssignment.h>
#include <moeoDiversityAssignment.h>
/**
* Environmental replacement strategy that consists in keeping the N best individuals by deleting individuals 1 by 1
* and by updating the fitness and diversity values after each deletion.
*/
template < class MOEOT > class moeoEnvironmentalReplacement:public moeoReplacement < MOEOT >
{
public:
/** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Full constructor.
* @param _evalFitness the fitness assignment strategy
* @param _evalDiversity the diversity assignment strategy
* @param _comparator the comparator (used to compare 2 individuals)
*/
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity, moeoComparator < MOEOT > & _comparator) :
evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (_comparator)
{}
/**
* Constructor without comparator. A moeoFitThenDivComparator is used as default.
* @param _evalFitness the fitness assignment strategy
* @param _evalDiversity the diversity assignment strategy
*/
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity) :
evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (*(new moeoFitnessThenDiversityComparator < MOEOT >))
{}
/**
* Constructor without moeoDiversityAssignement. A dummy diversity is used as default.
* @param _evalFitness the fitness assignment strategy
* @param _comparator the comparator (used to compare 2 individuals)
*/
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoComparator < MOEOT > & _comparator) :
evalFitness (_evalFitness), evalDiversity (*(new moeoDummyDiversityAssignment < MOEOT >)), comparator (_comparator)
{}
/**
* Constructor without moeoDiversityAssignement nor moeoComparator.
* A moeoFitThenDivComparator and a dummy diversity are used as default.
* @param _evalFitness the fitness assignment strategy
*/
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness) :
evalFitness (_evalFitness), evalDiversity (*(new moeoDummyDiversityAssignment < MOEOT >)), comparator (*(new moeoFitnessThenDiversityComparator < MOEOT >))
{}
/**
* Replaces the first population by adding the individuals of the second one, sorting with a moeoComparator and resizing the whole population obtained.
* @param _parents the population composed of the parents (the population you want to replace)
* @param _offspring the offspring population
*/
void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring)
{
unsigned sz = _parents.size();
// merges offspring and parents into a global population
_parents.reserve (_parents.size() + _offspring.size());
copy (_offspring.begin(), _offspring.end(), back_inserter(_parents));
// evaluates the fitness and the diversity of this global population
evalFitness (_parents);
evalDiversity (_parents);
// remove individuals 1 by 1 and update the fitness values
Cmp cmp(comparator);
ObjectiveVector worstObjVec;
while (_parents.size() > sz)
{
std::sort (_parents.begin(), _parents.end(), cmp);
worstObjVec = _parents[_parents.size()-1].objectiveVector();
_parents.resize(_parents.size()-1);
evalFitness.updateByDeleting(_parents, worstObjVec);
evalDiversity.updateByDeleting(_parents, worstObjVec);
}
// clear the offspring population
_offspring.clear ();
}
protected:
/** the fitness assignment strategy */
moeoFitnessAssignment < MOEOT > & evalFitness;
/** the diversity assignment strategy */
moeoDiversityAssignment < MOEOT > & evalDiversity;
/** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > & comparator;
/**
* This class is used to compare solutions in order to sort the population.
*/
class Cmp
{
public:
/**
* Ctor.
* @param _comparator the comparator
*/
Cmp(moeoComparator < MOEOT > & _comparator) : comparator(_comparator)
{}
/**
* Returns true if _moeo1 is greater than _moeo2 according to the comparator
* _moeo1 the first individual
* _moeo2 the first individual
*/
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return comparator(_moeo1,_moeo2);
}
private:
/** the comparator */
moeoComparator < MOEOT > & comparator;
};
};
#endif /*MOEOENVIRONMENTALREPLACEMENT_H_ */

View file

@ -0,0 +1,24 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoEvalFunc.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOEVALFUNC_H_
#define MOEOEVALFUNC_H_
#include <eoEvalFunc.h>
/*
* Functor that evaluates one MOEO by setting all its objective values.
*/
template < class MOEOT >
class moeoEvalFunc : public eoEvalFunc< MOEOT > {};
#endif /*MOEOEVALFUNC_H_*/

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