Modifications 22/02/2007
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@183 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
dccd731ad3
commit
8312d91a84
19 changed files with 930 additions and 805 deletions
|
|
@ -31,8 +31,9 @@
|
||||||
* operator '<' et '>' ???
|
* operator '<' et '>' ???
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!
|
* !!!!!!!!!!!!!!!!!!!!!!!
|
||||||
*/
|
*/
|
||||||
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
|
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity > class MOEO:public EO <
|
||||||
class MOEO : public EO < MOEOFitness >
|
MOEOFitness
|
||||||
|
>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -63,7 +64,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* Virtual dtor
|
* Virtual dtor
|
||||||
*/
|
*/
|
||||||
virtual ~MOEO() {};
|
virtual ~ MOEO ()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,11 @@
|
||||||
#define MOEOARCHIVE_H_
|
#define MOEOARCHIVE_H_
|
||||||
|
|
||||||
#include <eoPop.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 MOEOT >
|
template < class MOEOT > class moeoArchive:public eoPop < MOEOT >
|
||||||
class moeoArchive : public eoPop < MOEOT >
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -41,15 +39,19 @@ public:
|
||||||
* The moeoObjectiveVectorComparator used to compare solutions is based on Pareto dominance
|
* The moeoObjectiveVectorComparator used to compare solutions is based on Pareto dominance
|
||||||
*/
|
*/
|
||||||
moeoArchive ():eoPop < MOEOT > (), comparator (paretoComparator)
|
moeoArchive ():eoPop < MOEOT > (), comparator (paretoComparator)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor
|
* Ctor
|
||||||
* @param _comparator the moeoObjectiveVectorComparator used to compare solutions
|
* @param _comparator the moeoObjectiveVectorComparator used to compare solutions
|
||||||
*/
|
*/
|
||||||
moeoArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator) : eoPop < MOEOT >(), comparator(_comparator)
|
moeoArchive (moeoObjectiveVectorComparator < ObjectiveVector > &_comparator):eoPop < MOEOT > (),
|
||||||
{}
|
comparator
|
||||||
|
(_comparator)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -75,7 +77,7 @@ public:
|
||||||
*/
|
*/
|
||||||
bool contains (const ObjectiveVector & _objectiveVector) const
|
bool contains (const ObjectiveVector & _objectiveVector) const
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i<size(); i++)
|
for (unsigned i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
if (operator[](i).fitness () == _objectiveVector)
|
if (operator[](i).fitness () == _objectiveVector)
|
||||||
{
|
{
|
||||||
|
|
@ -95,12 +97,15 @@ public:
|
||||||
// first step: removing the dominated solutions from the archive
|
// first step: removing the dominated solutions from the archive
|
||||||
for (unsigned j = 0; j < size ();)
|
for (unsigned j = 0; j < size ();)
|
||||||
{
|
{
|
||||||
// if _moeo dominates the jth solution contanied in the archive
|
// if _moeo.fitness() dominates operator[](j).fitness()
|
||||||
if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector())==1 )
|
//if ( comparator(_moeo.fitness(), operator[](j).fitness())==1 )
|
||||||
|
if (comparator
|
||||||
|
(_moeo.objectiveVector (), operator[](j).objectiveVector ()) == 1)
|
||||||
{
|
{
|
||||||
operator[](j) = back ();
|
operator[](j) = back ();
|
||||||
pop_back ();
|
pop_back ();
|
||||||
}
|
}
|
||||||
|
//else if (_moeo.fitness() == operator[](j).fitness())
|
||||||
else if (_moeo.objectiveVector () == operator[](j).objectiveVector ())
|
else if (_moeo.objectiveVector () == operator[](j).objectiveVector ())
|
||||||
{
|
{
|
||||||
operator[](j) = back ();
|
operator[](j) = back ();
|
||||||
|
|
@ -115,8 +120,10 @@ public:
|
||||||
bool dom = false;
|
bool dom = false;
|
||||||
for (unsigned j = 0; j < size (); j++)
|
for (unsigned j = 0; j < size (); j++)
|
||||||
{
|
{
|
||||||
// if the jth solution contanied in the archive dominates _moeo
|
// if operator[](j).fitness() dominates _moeo.fitness()
|
||||||
if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) == 1 )
|
//if ( comparator(operator[](j).fitness(), _moeo.fitness())==1 )
|
||||||
|
if (comparator
|
||||||
|
(operator[](j).objectiveVector (), _moeo.objectiveVector ()) == 1)
|
||||||
{
|
{
|
||||||
dom = true;
|
dom = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,7 @@
|
||||||
/**
|
/**
|
||||||
* This class allows to save the fitnesses of solutions contained in an archive into a file at each generation.
|
* This class allows to save the fitnesses of solutions contained in an archive into a file at each generation.
|
||||||
*/
|
*/
|
||||||
template <class EOT>
|
template < class EOT > class moeoArchiveFitnessSavingUpdater:public eoUpdater
|
||||||
class moeoArchiveFitnessSavingUpdater : public eoUpdater
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -35,13 +34,17 @@ public:
|
||||||
* @param _filename target filename
|
* @param _filename target filename
|
||||||
* @param _id own ID
|
* @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)
|
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
|
* Saves the fitness of the archive's members into the file
|
||||||
*/
|
*/
|
||||||
void operator()() {
|
void operator () ()
|
||||||
|
{
|
||||||
char buff[MAX_BUFFER_SIZE];
|
char buff[MAX_BUFFER_SIZE];
|
||||||
if (id == -1)
|
if (id == -1)
|
||||||
sprintf (buff, "%s.%u", filename.c_str (), counter++);
|
sprintf (buff, "%s.%u", filename.c_str (), counter++);
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,9 @@
|
||||||
#include <moeoArchive.h>
|
#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 >
|
template < class EOT > class moeoArchiveUpdater:public eoUpdater
|
||||||
class moeoArchiveUpdater : public eoUpdater
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -30,14 +29,17 @@ public:
|
||||||
* @param _arch an archive of non-dominated solutions
|
* @param _arch an archive of non-dominated solutions
|
||||||
* @param _pop the main population
|
* @param _pop the main population
|
||||||
*/
|
*/
|
||||||
moeoArchiveUpdater(moeoArchive <EOT> & _arch, const eoPop<EOT> & _pop) : arch(_arch), pop(_pop)
|
moeoArchiveUpdater (moeoArchive < EOT > &_arch,
|
||||||
{}
|
const eoPop < EOT > &_pop):arch (_arch), pop (_pop)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the archive with newly found non-dominated solutions contained in the main population
|
* Updates the archive with newly found non-dominated solutions contained in the main population
|
||||||
*/
|
*/
|
||||||
void operator()() {
|
void operator () ()
|
||||||
|
{
|
||||||
arch.update (pop);
|
arch.update (pop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,43 +19,43 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class allows to embed a set of local searches that are sequentially applied,
|
* 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.
|
* and so working and updating the same archive of non-dominated solutions
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoCombinedLS:public moeoLS < MOEOT >
|
||||||
class moeoCombinedLS : public moeoLS < MOEOT >
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor
|
* Ctor
|
||||||
* @param _eval the full evaluator of a solution
|
* @param _eval the full evaluator of a solution
|
||||||
* @param _first_mols the first multi-objective local search to add
|
* @param _first_ls the first multi-objective local search to add
|
||||||
*/
|
*/
|
||||||
moeoCombinedLS(moeoEvalFunc < MOEOT > & _eval, moeoLS < MOEOT > & _first_mols) : eval (_eval)
|
moeoCombinedLS (moeoEvalFunc < MOEOT > &_eval, moeoLS < MOEOT > &_first_ls):eval
|
||||||
|
(_eval)
|
||||||
{
|
{
|
||||||
combinedLS.push_back (& _first_mols);
|
combinedLS.push_back (&_first_ls);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new local search to combine
|
* Adds a new local search to combine
|
||||||
* @param _mols the multi-objective local search to add
|
* @param _ls the multi-objective local search to add
|
||||||
*/
|
*/
|
||||||
void add(moeoLS < MOEOT > & _mols)
|
void add (moeoLS < MOEOT > &_ls)
|
||||||
{
|
{
|
||||||
combinedMOLS.push_back(& _mols);
|
combinedMOLS.push_back (&_ls);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives a new solution in order to explore the neigborhood.
|
* Gives a new solution in order to explore the neigborhood.
|
||||||
* The new non-dominated solutions are added to the archive
|
* The new non-dominated solutions are added to the archive
|
||||||
* @param _moeo the solution
|
* @param _eo the solution
|
||||||
* @param _arch the archive of non-dominated solutions
|
* @param _arch the archive of non-dominated solutions
|
||||||
*/
|
*/
|
||||||
void operator () (const MOEOT & _moeo, moeoArchive < MOEOT > & _arch)
|
void operator () (const MOEOT & _eo, moeoArchive < MOEOT > &_arch)
|
||||||
{
|
{
|
||||||
eval(const_cast < MOEOT & > (_moeo));
|
eval (const_cast < MOEOT & >(_eo));
|
||||||
for (unsigned i = 0; i < combinedLS.size (); i++)
|
for (unsigned i = 0; i < combinedLS.size (); i++)
|
||||||
combinedLS[i] -> operator()(_moeo, _arch);
|
combinedLS[i]->operator ()(_eo, _arch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,20 +14,24 @@
|
||||||
#define MOEOCOMPARATOR_H_
|
#define MOEOCOMPARATOR_H_
|
||||||
|
|
||||||
#include <eoFunctor.h>
|
#include <eoFunctor.h>
|
||||||
|
#include <eoPop.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor allowing to compare two solutions.
|
* Functor allowing to compare two solutions
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoComparator:public eoBF < const MOEOT &, const MOEOT &,
|
||||||
class moeoComparator : public eoBF < const MOEOT &, const MOEOT &, const bool >
|
const bool >
|
||||||
{};
|
{
|
||||||
|
public:
|
||||||
|
// virtual const bool operator () (const MOEOT & _moeo1, const MOEOT & _moeo){}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor allowing to compare two solutions according to their first objective value, then their second, and so on.
|
* Functor allowing to compare two solutions according to their first objective value, then their second, and so on
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoObjectiveComparator:public moeoComparator <
|
||||||
class moeoObjectiveComparator : public moeoComparator < MOEOT >
|
MOEOT >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
@ -43,48 +47,48 @@ public:
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor allowing to compare two solutions according to their fitness values.
|
* Functor allowing to compare two solutions according to their fitness values
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
//template < class MOEOT >
|
||||||
class moeoFitnessComparator : public moeoComparator < MOEOT >
|
//class moeoFitnessComparator : public moeoComparator < MOEOT >
|
||||||
{
|
//{
|
||||||
public:
|
//public:
|
||||||
/**
|
// /**
|
||||||
* Returns true if the fitness value of _moeo1 is smaller than the fitness value of _moeo2
|
// * Returns true if the fitness value of _moeo1 is smaller than the fitness value of _moeo2
|
||||||
* @param _moeo1 the first solution
|
// * @param _moeo1 the first solution
|
||||||
* @param _moeo2 the second solution
|
// * @param _moeo2 the second solution
|
||||||
*/
|
// */
|
||||||
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
// const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
||||||
{
|
// {
|
||||||
return _moeo1.fitness() < _moeo2.fitness();
|
// return _moeo1.fitness() < _moeo2.fitness();
|
||||||
}
|
// }
|
||||||
};
|
//};
|
||||||
|
//
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * Functor allowing to compare two solutions according to their diversity values
|
||||||
|
// */
|
||||||
|
//template < class MOEOT >
|
||||||
|
//class moeoDiversityComparator : public moeoComparator < MOEOT >
|
||||||
|
//{
|
||||||
|
//public:
|
||||||
|
// /**
|
||||||
|
// * Returns true if the diversity value of _moeo1 is smaller than the diversity value of _moeo2
|
||||||
|
// * @param _moeo1 the first solution
|
||||||
|
// * @param _moeo2 the second solution
|
||||||
|
// */
|
||||||
|
// const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
||||||
|
// {
|
||||||
|
// return _moeo1.diversity() < _moeo2.diversity();
|
||||||
|
// }
|
||||||
|
//};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor allowing to compare two solutions according to their diversity values.
|
* Functor allowing to compare two solutions according to their fitness values, then according to their diversity values
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoFitnessThenDiversityComparator:public moeoComparator <
|
||||||
class moeoDiversityComparator : public moeoComparator < MOEOT >
|
MOEOT >
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Returns true if the diversity value of _moeo1 is smaller than the diversity value of _moeo2
|
|
||||||
* @param _moeo1 the first solution
|
|
||||||
* @param _moeo2 the second solution
|
|
||||||
*/
|
|
||||||
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
|
||||||
{
|
|
||||||
return _moeo1.diversity() < _moeo2.diversity();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
@ -107,10 +111,10 @@ public:
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor allowing to compare two solutions according to their diversity values, then according to their fitness values.
|
* Functor allowing to compare two solutions according to their diversity values, then according to their fitness values
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoDiversityThenFitnessComparator:public moeoComparator <
|
||||||
class moeoDiversityThenFitnessComparator : public moeoComparator < MOEOT >
|
MOEOT >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
@ -133,7 +137,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor allowing to compare two solutions according to Pareto dominance relation. => USEFULL ???
|
* Functor allowing to compare two solutions according to Pareto dominance relation => USEFULL ???
|
||||||
*
|
*
|
||||||
template < class MOEOT >
|
template < class MOEOT >
|
||||||
class moeoParetoDominanceComparator : public moeoComparator < MOEOT >
|
class moeoParetoDominanceComparator : public moeoComparator < MOEOT >
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,32 @@
|
||||||
#include <eoPop.h>
|
#include <eoPop.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor that sets the diversity values of a whole population.
|
* Functor that sets the diversity values of a whole population
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoDiversityAssignment:public eoUF < eoPop < MOEOT > &,
|
||||||
class moeoDiversityAssignment : public eoUF < eoPop < MOEOT > &, void >
|
void >
|
||||||
{};
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* moeoDummyDiversityAssignment is a moeoDiversityAssignment which gives 0 as the diversity for the whole population.
|
||||||
|
*/
|
||||||
|
template < class MOEOT > class moeoDummyDiversityAssignment:public moeoDiversityAssignment <
|
||||||
|
MOEOT >
|
||||||
|
{
|
||||||
|
// main operator
|
||||||
|
void operator () (eoPop < MOEOT > &_pop)
|
||||||
|
{
|
||||||
|
for (int idx = 0; idx < _pop.size (); idx++)
|
||||||
|
{
|
||||||
|
// set the diversity to 0
|
||||||
|
_pop[idx].diversity (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /*MOEODIVERSITYASSIGNMENT_H_ */
|
#endif /*MOEODIVERSITYASSIGNMENT_H_ */
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,11 @@
|
||||||
#include <eoAlgo.h>
|
#include <eoAlgo.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class for multi-objective evolutionary algorithms.
|
* Abstract class for multi-objective evolutionary algorithms
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoEA:public eoAlgo < MOEOT >
|
||||||
class moeoEA : public eoAlgo < MOEOT > {};
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /*MOEOEA_H_ */
|
#endif /*MOEOEA_H_ */
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@
|
||||||
/*
|
/*
|
||||||
* Functor that evaluates one MOEO by setting all its objective values.
|
* Functor that evaluates one MOEO by setting all its objective values.
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoEvalFunc:public eoEvalFunc < MOEOT >
|
||||||
class moeoEvalFunc : public eoEvalFunc< MOEOT > {};
|
{
|
||||||
|
};
|
||||||
|
|
||||||
#endif /*MOEOEVALFUNC_H_ */
|
#endif /*MOEOEVALFUNC_H_ */
|
||||||
|
|
|
||||||
|
|
@ -14,26 +14,29 @@
|
||||||
#define MOEOFASTNONDOMINATEDSORTINGFITNESSASSIGNMENT_H_
|
#define MOEOFASTNONDOMINATEDSORTINGFITNESSASSIGNMENT_H_
|
||||||
|
|
||||||
#include <eoPop.h>
|
#include <eoPop.h>
|
||||||
#include <moeoComparator.h>
|
|
||||||
#include <moeoFitnessAssignment.h>
|
#include <moeoFitnessAssignment.h>
|
||||||
|
#include <moeoComparator.h>
|
||||||
#include <moeoObjectiveVectorComparator.h>
|
#include <moeoObjectiveVectorComparator.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fitness assignment sheme based on Pareto-dominance count proposed in:
|
* Fitness assignment sheme based on Pareto-dominance count proposed in
|
||||||
* *N. Srinivas, K. Deb, "Multiobjective Optimization Using Nondominated Sorting in Genetic Algorithms", Evolutionary Computation vol. 2, no. 3, pp. 221-248 (1994)*
|
* N. Srinivas, K. Deb, "Multiobjective Optimization Using Nondominated Sorting in Genetic Algorithms", Evolutionary Computation vol. 2, no. 3, pp. 221-248 (1994)
|
||||||
* and in:
|
* and 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)*.
|
* 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 and NSGA-II.
|
* This strategy is, for instance, used in NSGA and NSGA-II.
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoFastNonDominatedSortingFitnessAssignment:public moeoParetoBasedFitnessAssignment <
|
||||||
class moeoFastNonDominatedSortingFitnessAssignment : public moeoParetoBasedFitnessAssignment < MOEOT >
|
MOEOT
|
||||||
|
>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor
|
* Ctor
|
||||||
*/
|
*/
|
||||||
moeoFastNonDominatedSortingFitnessAssignment() {}
|
moeoFastNonDominatedSortingFitnessAssignment ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -51,7 +54,7 @@ public:
|
||||||
}
|
}
|
||||||
else if (nObjectives == 2)
|
else if (nObjectives == 2)
|
||||||
{
|
{
|
||||||
// two objectives (the two objectives function is still to implement)
|
// two objectives (the two objectives function is still to do)
|
||||||
mObjectives (_pop);
|
mObjectives (_pop);
|
||||||
}
|
}
|
||||||
else if (nObjectives > 2)
|
else if (nObjectives > 2)
|
||||||
|
|
@ -62,7 +65,9 @@ public:
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// problem with the number of objectives
|
// problem with the number of objectives
|
||||||
throw std::runtime_error("Problem with the number of objectives in moeoFastNonDominatedSortingFitnessAssignment");
|
throw std::
|
||||||
|
runtime_error
|
||||||
|
("Problem with the number of objectives in moeoFastNonDominatedSortingFitnessAssignment");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,7 +127,9 @@ private:
|
||||||
for (unsigned q = 0; q < _pop.size (); q++)
|
for (unsigned q = 0; q < _pop.size (); q++)
|
||||||
{
|
{
|
||||||
// comparison of the 2 solutions according to Pareto dominance
|
// comparison of the 2 solutions according to Pareto dominance
|
||||||
comparatorFlag = comparator(_pop[p].objectiveVector(), _pop[q].objectiveVector());
|
comparatorFlag =
|
||||||
|
comparator (_pop[p].objectiveVector (),
|
||||||
|
_pop[q].objectiveVector ());
|
||||||
// if p dominates q
|
// if p dominates q
|
||||||
if (comparatorFlag == 1)
|
if (comparatorFlag == 1)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,35 +17,46 @@
|
||||||
#include <eoPop.h>
|
#include <eoPop.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor that sets the fitness values of a whole population.
|
* Functor that sets the fitness values of a whole population
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoFitnessAssignment:public eoUF < eoPop < MOEOT > &,
|
||||||
class moeoFitnessAssignment : public eoUF < eoPop < MOEOT > &, void >
|
void >
|
||||||
{};
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* moeoScalarFitnessAssignment is a moeoFitnessAssignment for scalar strategies.
|
* moeoScalarFitnessAssignment is a moeoFitnessAssignment for scalar strategies
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoScalarFitnessAssignment:public moeoFitnessAssignment <
|
||||||
class moeoScalarFitnessAssignment : public moeoFitnessAssignment < MOEOT >
|
MOEOT >
|
||||||
{};
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* moeoCriterionBasedFitnessAssignment is a moeoFitnessAssignment for criterion-based strategies.
|
* moeoCriterionBasedFitnessAssignment is a moeoFitnessAssignment for criterion-based strategies
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoCriterionBasedFitnessAssignment:public moeoFitnessAssignment <
|
||||||
class moeoCriterionBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
|
MOEOT >
|
||||||
{};
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* moeoParetoBasedFitnessAssignment is a moeoFitnessAssignment for Pareto-based strategies.
|
* moeoParetoBasedFitnessAssignment is a moeoFitnessAssignment for Pareto-based strategies
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoParetoBasedFitnessAssignment:public moeoFitnessAssignment <
|
||||||
class moeoParetoBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
|
MOEOT >
|
||||||
{};
|
{
|
||||||
|
void operator () (eoPop < MOEOT > &_pop)
|
||||||
|
{
|
||||||
|
// do nothing for the moment ...
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /*MOEOFITNESSASSIGNMENT_H_ */
|
#endif /*MOEOFITNESSASSIGNMENT_H_ */
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,12 @@
|
||||||
#include <moeoGenerationalReplacement.h>
|
#include <moeoGenerationalReplacement.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generational replacement: only the new individuals are preserved.
|
* Generational replacement: only the new individuals are preserved
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoGenerationalReplacement:public moeoReplacement < MOEOT >,
|
||||||
class moeoGenerationalReplacement : public moeoReplacement < MOEOT >, public eoGenerationalReplacement < MOEOT > {};
|
public eoGenerationalReplacement <
|
||||||
|
MOEOT >
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
#endif /*MOEOGENERATIONALREPLACEMENT_H_ */
|
#endif /*MOEOGENERATIONALREPLACEMENT_H_ */
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,7 @@
|
||||||
* This class allows to apply a multi-objective local search to a number of selected individuals contained in the archive
|
* 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.
|
* at every generation until a stopping criteria is verified.
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoHybridLS:public eoUpdater
|
||||||
class moeoHybridLS : public eoUpdater
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -33,11 +32,14 @@ public:
|
||||||
* Ctor
|
* Ctor
|
||||||
* @param _term stopping criteria
|
* @param _term stopping criteria
|
||||||
* @param _select selector
|
* @param _select selector
|
||||||
* @param _mols a multi-objective local search
|
* @param _ls a multi-objective local search
|
||||||
* @param _arch the archive
|
* @param _arch the archive
|
||||||
*/
|
*/
|
||||||
eoHybridLS (eoContinue < MOEOT > & _term, eoSelect < MOEOT > & _select, moeoLS < MOEOT > & _mols, moeoArchive < MOEOT > & _arch) : term(_term), select(_select), mols(_mols), arch(_arch)
|
eoHybridLS (eoContinue < MOEOT > &_term, eoSelect < MOEOT > &_select, moeoLS < MOEOT > &_ls, moeoArchive < MOEOT > &_arch):term (_term), select (_select), ls (_ls),
|
||||||
{}
|
arch
|
||||||
|
(_arch)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the multi-objective local search to selected individuals contained in the archive if the stopping criteria is not verified
|
* Applies the multi-objective local search to selected individuals contained in the archive if the stopping criteria is not verified
|
||||||
|
|
@ -52,7 +54,7 @@ public:
|
||||||
// apply the local search to every selected solution
|
// apply the local search to every selected solution
|
||||||
for (unsigned i = 0; i < selectedSolutions.size (); i++)
|
for (unsigned i = 0; i < selectedSolutions.size (); i++)
|
||||||
{
|
{
|
||||||
mols(selectedSolutions[i], arch);
|
ls (selectedSolutions[i], arch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -65,7 +67,7 @@ private:
|
||||||
/** selector */
|
/** selector */
|
||||||
eoSelect < MOEOT > &select;
|
eoSelect < MOEOT > &select;
|
||||||
/** multi-objective local search */
|
/** multi-objective local search */
|
||||||
moeoLS < MOEOT > & mols;
|
moeoLS < MOEOT > &ls;
|
||||||
/** archive */
|
/** archive */
|
||||||
moeoArchive < MOEOT > &arch;
|
moeoArchive < MOEOT > &arch;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,9 @@
|
||||||
* Abstract class for local searches applied to multi-objective optimization.
|
* Abstract class for local searches applied to multi-objective optimization.
|
||||||
* Starting from only one solution, it produces a set of new non-dominated solutions.
|
* Starting from only one solution, it produces a set of new non-dominated solutions.
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoLS:public eoBF < const MOEOT &, moeoArchive < MOEOT > &,
|
||||||
class moeoLS: public eoBF < const MOEOT &, moeoArchive < MOEOT > &, void >
|
void >
|
||||||
{};
|
{
|
||||||
|
};
|
||||||
|
|
||||||
#endif /*MOEOLS_H_ */
|
#endif /*MOEOLS_H_ */
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,7 @@
|
||||||
* but it can be replaced at will by any other class that implements the static functions defined therein.
|
* but it can be replaced at will by any other class that implements the static functions defined therein.
|
||||||
* Some static funtions to access to the traits characteristics are re-defined in order not to write a lot of typedef's.
|
* Some static funtions to access to the traits characteristics are re-defined in order not to write a lot of typedef's.
|
||||||
*/
|
*/
|
||||||
template < class ObjectiveVectorTraits >
|
template < class ObjectiveVectorTraits > class moeoObjectiveVector
|
||||||
class moeoObjectiveVector
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -38,7 +37,8 @@ public:
|
||||||
* @param _nObjectives the number of objectives
|
* @param _nObjectives the number of objectives
|
||||||
* @param _bObjectives the min/max vector (true = min / false = max)
|
* @param _bObjectives the min/max vector (true = min / false = max)
|
||||||
*/
|
*/
|
||||||
static void setup(unsigned _nObjectives, std::vector < bool > & _bObjectives)
|
static void setup (unsigned _nObjectives,
|
||||||
|
std::vector < bool > &_bObjectives)
|
||||||
{
|
{
|
||||||
ObjectiveVectorTraits::setup (_nObjectives, _bObjectives);
|
ObjectiveVectorTraits::setup (_nObjectives, _bObjectives);
|
||||||
}
|
}
|
||||||
|
|
@ -57,7 +57,8 @@ public:
|
||||||
* Returns true if the _ith objective have to be minimized
|
* Returns true if the _ith objective have to be minimized
|
||||||
* @param _i the index
|
* @param _i the index
|
||||||
*/
|
*/
|
||||||
static bool minimizing(unsigned _i) {
|
static bool minimizing (unsigned _i)
|
||||||
|
{
|
||||||
return ObjectiveVectorTraits::minimizing (_i);
|
return ObjectiveVectorTraits::minimizing (_i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,7 +67,8 @@ public:
|
||||||
* Returns true if the _ith objective have to be maximized
|
* Returns true if the _ith objective have to be maximized
|
||||||
* @param _i the index
|
* @param _i the index
|
||||||
*/
|
*/
|
||||||
static bool maximizing(unsigned _i) {
|
static bool maximizing (unsigned _i)
|
||||||
|
{
|
||||||
return ObjectiveVectorTraits::maximizing (_i);
|
return ObjectiveVectorTraits::maximizing (_i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,25 +79,34 @@ public:
|
||||||
* This class allows to represent a solution in the objective space (phenotypic representation) by a std::vector of doubles,
|
* This class allows to represent a solution in the objective space (phenotypic representation) by a std::vector of doubles,
|
||||||
* i.e. that an objective value is represented using a double, and this for any objective.
|
* i.e. that an objective value is represented using a double, and this for any objective.
|
||||||
*/
|
*/
|
||||||
template < class ObjectiveVectorTraits >
|
template < class ObjectiveVectorTraits > class moeoObjectiveVectorDouble:public moeoObjectiveVector < ObjectiveVectorTraits >,
|
||||||
class moeoObjectiveVectorDouble : public moeoObjectiveVector < ObjectiveVectorTraits >, public std::vector < double >
|
public std::vector <
|
||||||
|
double >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using std::vector< double >::size;
|
using
|
||||||
using std::vector< double >::operator[];
|
std::vector < double >::size;
|
||||||
|
using
|
||||||
|
std::vector < double >::operator[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor
|
* Ctor
|
||||||
*/
|
*/
|
||||||
moeoObjectiveVectorDouble() : std::vector < double > (ObjectiveVectorTraits::nObjectives(), 0.0) {}
|
moeoObjectiveVectorDouble ():
|
||||||
|
std::vector < double >(ObjectiveVectorTraits::nObjectives (), 0.0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor from a vector of doubles
|
* Ctor from a vector of doubles
|
||||||
* @param _v the std::vector < double >
|
* @param _v the std::vector < double >
|
||||||
*/
|
*/
|
||||||
moeoObjectiveVectorDouble(std::vector <double> & _v) : std::vector < double > (_v) {}
|
moeoObjectiveVectorDouble (std::vector < double >&_v):
|
||||||
|
std::vector < double >(_v)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -103,10 +114,16 @@ public:
|
||||||
* (but it's better to use a moeoObjectiveVectorComparator object to compare solutions)
|
* (but it's better to use a moeoObjectiveVectorComparator object to compare solutions)
|
||||||
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
||||||
*/
|
*/
|
||||||
bool dominates(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
|
bool
|
||||||
|
dominates (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
|
||||||
|
&_other) const
|
||||||
{
|
{
|
||||||
moeoParetoObjectiveVectorComparator < moeoObjectiveVectorDouble<ObjectiveVectorTraits> > comparator;
|
moeoParetoObjectiveVectorComparator <
|
||||||
return comparator(*this, _other)==1;
|
moeoObjectiveVectorDouble <
|
||||||
|
ObjectiveVectorTraits > >
|
||||||
|
comparator;
|
||||||
|
return
|
||||||
|
comparator (*this, _other) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -114,16 +131,20 @@ public:
|
||||||
* Returns true if the current objective vector is equal to _other (according to a tolerance value)
|
* Returns true if the current objective vector is equal to _other (according to a tolerance value)
|
||||||
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
||||||
*/
|
*/
|
||||||
bool operator==(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
|
bool
|
||||||
|
operator== (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
|
||||||
|
&_other) const
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < size (); i++)
|
for (unsigned i = 0; i < size (); i++)
|
||||||
{
|
{
|
||||||
if ( fabs(operator[](i) - _other[i]) > ObjectiveVectorTraits::tolerance() )
|
if (fabs (operator[](i) - _other[i]) >
|
||||||
|
ObjectiveVectorTraits::tolerance ())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return
|
||||||
|
true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -131,9 +152,12 @@ public:
|
||||||
* Returns true if the current objective vector is different than _other (according to a tolerance value)
|
* Returns true if the current objective vector is different than _other (according to a tolerance value)
|
||||||
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
||||||
*/
|
*/
|
||||||
bool operator!=(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
|
bool
|
||||||
|
operator!= (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
|
||||||
|
&_other) const
|
||||||
{
|
{
|
||||||
return ! operator==(_other);
|
return !
|
||||||
|
operator== (_other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -142,11 +166,14 @@ public:
|
||||||
* (can be usefull for sorting/printing)
|
* (can be usefull for sorting/printing)
|
||||||
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
||||||
*/
|
*/
|
||||||
bool operator<(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
|
bool
|
||||||
|
operator< (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
|
||||||
|
&_other) const
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < size (); i++)
|
for (unsigned i = 0; i < size (); i++)
|
||||||
{
|
{
|
||||||
if ( fabs(operator[](i) - _other[i]) > ObjectiveVectorTraits::tolerance() )
|
if (fabs (operator[](i) - _other[i]) >
|
||||||
|
ObjectiveVectorTraits::tolerance ())
|
||||||
{
|
{
|
||||||
if (operator[](i) < _other[i])
|
if (operator[](i) < _other[i])
|
||||||
{
|
{
|
||||||
|
|
@ -167,9 +194,13 @@ public:
|
||||||
* (can be usefull for sorting/printing)
|
* (can be usefull for sorting/printing)
|
||||||
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
||||||
*/
|
*/
|
||||||
bool operator>(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
|
bool
|
||||||
|
operator> (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
|
||||||
|
&_other) const
|
||||||
{
|
{
|
||||||
return _other < *this;
|
return
|
||||||
|
_other < *
|
||||||
|
this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -178,9 +209,13 @@ public:
|
||||||
* (can be usefull for sorting/printing)
|
* (can be usefull for sorting/printing)
|
||||||
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
||||||
*/
|
*/
|
||||||
bool operator<=(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
|
bool
|
||||||
|
operator<= (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
|
||||||
|
&_other) const
|
||||||
{
|
{
|
||||||
return operator==(_other) || operator<(_other);
|
return
|
||||||
|
operator== (_other) ||
|
||||||
|
operator< (_other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -189,9 +224,13 @@ public:
|
||||||
* (can be usefull for sorting/printing)
|
* (can be usefull for sorting/printing)
|
||||||
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
* @param _other the other moeoObjectiveVectorDouble object to compare with
|
||||||
*/
|
*/
|
||||||
bool operator>=(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
|
bool
|
||||||
|
operator>= (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
|
||||||
|
&_other) const
|
||||||
{
|
{
|
||||||
return operator==(_other) || operator>(_other);
|
return
|
||||||
|
operator== (_other) ||
|
||||||
|
operator> (_other);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -203,7 +242,9 @@ public:
|
||||||
* @param _objectiveVector the objective vector to write
|
* @param _objectiveVector the objective vector to write
|
||||||
*/
|
*/
|
||||||
template < class ObjectiveVectorTraits >
|
template < class ObjectiveVectorTraits >
|
||||||
std::ostream & operator<<(std::ostream & _os, const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _objectiveVector)
|
std::ostream & operator<< (std::ostream & _os,
|
||||||
|
const moeoObjectiveVectorDouble <
|
||||||
|
ObjectiveVectorTraits > &_objectiveVector)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < _objectiveVector.size (); i++)
|
for (unsigned i = 0; i < _objectiveVector.size (); i++)
|
||||||
{
|
{
|
||||||
|
|
@ -218,7 +259,9 @@ std::ostream & operator<<(std::ostream & _os, const moeoObjectiveVectorDouble <
|
||||||
* @param _objectiveVector the objective vector to read
|
* @param _objectiveVector the objective vector to read
|
||||||
*/
|
*/
|
||||||
template < class ObjectiveVectorTraits >
|
template < class ObjectiveVectorTraits >
|
||||||
std::istream & operator>>(std::istream & _is, moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _objectiveVector)
|
std::istream & operator>> (std::istream & _is,
|
||||||
|
moeoObjectiveVectorDouble <
|
||||||
|
ObjectiveVectorTraits > &_objectiveVector)
|
||||||
{
|
{
|
||||||
_objectiveVector = moeoObjectiveVectorDouble < ObjectiveVectorTraits > ();
|
_objectiveVector = moeoObjectiveVectorDouble < ObjectiveVectorTraits > ();
|
||||||
for (unsigned i = 0; i < _objectiveVector.size (); i++)
|
for (unsigned i = 0; i < _objectiveVector.size (); i++)
|
||||||
|
|
|
||||||
|
|
@ -20,16 +20,18 @@
|
||||||
* Abstract class allowing to compare 2 objective vectors.
|
* Abstract class allowing to compare 2 objective vectors.
|
||||||
* The template argument ObjectiveVector have to be a moeoObjectiveVector.
|
* The template argument ObjectiveVector have to be a moeoObjectiveVector.
|
||||||
*/
|
*/
|
||||||
template < class ObjectiveVector >
|
template < class ObjectiveVector > class moeoObjectiveVectorComparator:public eoBF < const ObjectiveVector &, const ObjectiveVector &,
|
||||||
class moeoObjectiveVectorComparator : public eoBF < const ObjectiveVector &, const ObjectiveVector &, int >
|
int >
|
||||||
{};
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This functor class allows to compare 2 objective vectors according to Pareto dominance.
|
* This functor class allows to compare 2 objective vectors according to Pareto dominance
|
||||||
*/
|
*/
|
||||||
template < class ObjectiveVector >
|
template < class ObjectiveVector > class moeoParetoObjectiveVectorComparator:public moeoObjectiveVectorComparator <
|
||||||
class moeoParetoObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
|
ObjectiveVector
|
||||||
|
>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -38,14 +40,16 @@ public:
|
||||||
* @param _objectiveVector1 the first objective vector
|
* @param _objectiveVector1 the first objective vector
|
||||||
* @param _objectiveVector2 the second objective vector
|
* @param _objectiveVector2 the second objective vector
|
||||||
*/
|
*/
|
||||||
int operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
|
int operator () (const ObjectiveVector & _objectiveVector1,
|
||||||
|
const ObjectiveVector & _objectiveVector2)
|
||||||
{
|
{
|
||||||
bool dom1 = false;
|
bool dom1 = false;
|
||||||
bool dom2 = false;
|
bool dom2 = false;
|
||||||
for (unsigned i = 0; i < ObjectiveVector::nObjectives (); i++)
|
for (unsigned i = 0; i < ObjectiveVector::nObjectives (); i++)
|
||||||
{
|
{
|
||||||
// first, we have to check if the 2 objective values are not equal for the ith objective
|
// first, we have to check if the 2 objective values are not equal for the ith objective
|
||||||
if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() )
|
if (fabs (_objectiveVector1[i] - _objectiveVector2[i]) >
|
||||||
|
ObjectiveVector::Traits::tolerance ())
|
||||||
{
|
{
|
||||||
// if the ith objective have to be minimized...
|
// if the ith objective have to be minimized...
|
||||||
if (ObjectiveVector::minimizing (i))
|
if (ObjectiveVector::minimizing (i))
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A traits class for moeoObjectiveVector to specify the number of objectives and which ones have to be minimized or maximized.
|
* A traits class for moeoObjectiveVector to specify the number of objectives and which ones have to be minimized or maximized
|
||||||
*/
|
*/
|
||||||
class moeoObjectiveVectorTraits
|
class moeoObjectiveVectorTraits
|
||||||
{
|
{
|
||||||
|
|
@ -32,13 +32,16 @@ public:
|
||||||
* @param _nObjectives the number of objectives
|
* @param _nObjectives the number of objectives
|
||||||
* @param _bObjectives the min/max vector (true = min / false = max)
|
* @param _bObjectives the min/max vector (true = min / false = max)
|
||||||
*/
|
*/
|
||||||
static void setup(unsigned _nObjectives, std::vector < bool > & _bObjectives)
|
static void setup (unsigned _nObjectives,
|
||||||
|
std::vector < bool > &_bObjectives)
|
||||||
{
|
{
|
||||||
// in case the number of objectives was already set to a different value
|
// in case the number of objectives was already set to a different value
|
||||||
if ( nObj && (nObj != _nObjectives) ) {
|
if (nObj && (nObj != _nObjectives))
|
||||||
|
{
|
||||||
std::cout << "WARNING\n";
|
std::cout << "WARNING\n";
|
||||||
std::cout << "WARNING : the number of objectives are changing\n";
|
std::cout << "WARNING : the number of objectives are changing\n";
|
||||||
std::cout << "ARNING : Make sure all existing objects are destroyed\n";
|
std::
|
||||||
|
cout << "WARNING : Make sure all existing objects are destroyed\n";
|
||||||
std::cout << "WARNING\n";
|
std::cout << "WARNING\n";
|
||||||
}
|
}
|
||||||
// number of objectives
|
// number of objectives
|
||||||
|
|
@ -47,7 +50,9 @@ public:
|
||||||
bObj = _bObjectives;
|
bObj = _bObjectives;
|
||||||
// in case the number of objectives and the min/max vector size don't match
|
// in case the number of objectives and the min/max vector size don't match
|
||||||
if (nObj != bObj.size ())
|
if (nObj != bObj.size ())
|
||||||
throw std::runtime_error("Number of objectives and min/max size don't match in moeoObjectiveVectorTraits::setup");
|
throw std::
|
||||||
|
runtime_error
|
||||||
|
("Number of objectives and min/max size don't match in moeoObjectiveVectorTraits::setup");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -57,7 +62,9 @@ public:
|
||||||
{
|
{
|
||||||
// in case the number of objectives would not be assigned yet
|
// in case the number of objectives would not be assigned yet
|
||||||
if (!nObj)
|
if (!nObj)
|
||||||
throw std::runtime_error("Number of objectives not assigned in moeoObjectiveVectorTraits");
|
throw std::
|
||||||
|
runtime_error
|
||||||
|
("Number of objectives not assigned in moeoObjectiveVectorTraits");
|
||||||
return nObj;
|
return nObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +76,9 @@ public:
|
||||||
{
|
{
|
||||||
// in case the min/max vector would not be assigned yet
|
// in case the min/max vector would not be assigned yet
|
||||||
if (!bObj[_i])
|
if (!bObj[_i])
|
||||||
throw std::runtime_error("We don't know if the ith objective have to be minimized or maximized in moeoObjectiveVectorTraits");
|
throw std::
|
||||||
|
runtime_error
|
||||||
|
("We don't know if the ith objective have to be minimized or maximized in moeoObjectiveVectorTraits");
|
||||||
// in case there would be a wrong index
|
// in case there would be a wrong index
|
||||||
if (_i >= bObj.size ())
|
if (_i >= bObj.size ())
|
||||||
throw std::runtime_error ("Wrong index in moeoObjectiveVectorTraits");
|
throw std::runtime_error ("Wrong index in moeoObjectiveVectorTraits");
|
||||||
|
|
@ -80,7 +89,8 @@ public:
|
||||||
* Returns true if the _ith objective have to be maximized
|
* Returns true if the _ith objective have to be maximized
|
||||||
* @param _i the index
|
* @param _i the index
|
||||||
*/
|
*/
|
||||||
static bool maximizing(unsigned _i) {
|
static bool maximizing (unsigned _i)
|
||||||
|
{
|
||||||
return (!minimizing (_i));
|
return (!minimizing (_i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,5 +117,6 @@ private:
|
||||||
|
|
||||||
// The static variables of the moeoObjectiveVectorTraits class need to be allocated
|
// The static variables of the moeoObjectiveVectorTraits class need to be allocated
|
||||||
// (maybe it would have been better to put this on a moeoObjectiveVectorTraits.cpp file)
|
// (maybe it would have been better to put this on a moeoObjectiveVectorTraits.cpp file)
|
||||||
unsigned moeoObjectiveVectorTraits::nObj;
|
unsigned
|
||||||
|
moeoObjectiveVectorTraits::nObj;
|
||||||
std::vector < bool > moeoObjectiveVectorTraits::bObj;
|
std::vector < bool > moeoObjectiveVectorTraits::bObj;
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,10 @@
|
||||||
#include <eoReplacement.h>
|
#include <eoReplacement.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replacement strategy for multi-objective optimization.
|
* Replacement strategy for multi-objective optimization
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoReplacement:public eoReplacement < MOEOT >
|
||||||
class moeoReplacement : public eoReplacement < MOEOT > {};
|
{
|
||||||
|
};
|
||||||
|
|
||||||
#endif /*MOEOREPLACEMENT_H_ */
|
#endif /*MOEOREPLACEMENT_H_ */
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,8 @@
|
||||||
#include <eoSelectOne.h>
|
#include <eoSelectOne.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selection strategy for multi-objective optimization that selects only one element from a whole population.
|
* Selection strategy for multi-objective optimization that selects only one element from a whole population
|
||||||
*/
|
*/
|
||||||
template < class MOEOT >
|
template < class MOEOT > class moeoSelectOne : public eoSelectOne < MOEOT > {};
|
||||||
class moeoSelectOne : public eoSelectOne < MOEOT > {};
|
|
||||||
|
|
||||||
#endif /*MOEOSELECTONE_H_ */
|
#endif /*MOEOSELECTONE_H_ */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue