update doc

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@198 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
liefooga 2007-02-23 15:04:48 +00:00
commit ebd175c05b
5 changed files with 220 additions and 225 deletions

View file

@ -17,141 +17,133 @@
#include <moeoSelectors.h> #include <moeoSelectors.h>
/** /**
* moeoDetTournamentSelect: a selection method that selects ONE individual by * Selection strategy that selects ONE individual by deterministic tournament.
* deterministic tournament
*/ */
template < class MOEOT > template < class MOEOT >
class moeoDetTournamentSelect:public moeoSelectOne <MOEOT> class moeoDetTournamentSelect:public moeoSelectOne <MOEOT>
{ {
public: public:
/** /**
* Full Ctor * Full Ctor.
* @param _evalFitness the population fitness assignment * @param _evalFitness the fitness assignment strategy
* @param _evalDiversity the population diversity assignment * @param _evalDiversity the diversity assignment strategy
* @param _comparator the comparator to compare the individuals$ * @param _comparator the comparator (used to compare 2 individuals)
* @param _tSize the number of individuals in the tournament (default: 2) * @param _tSize the number of individuals in the tournament (default: 2)
*/ */
moeoDetTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDiversityAssignment < MOEOT > &_evalDiversity, moeoComparator < MOEOT > &_comparator, unsigned _tSize = 2):evalFitness (_evalFitness), evalDiversity (_evalDiversity), moeoDetTournamentSelect (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity, moeoComparator < MOEOT > & _comparator, unsigned _tSize = 2) :
comparator (_comparator), tSize (_tSize) evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (_comparator), tSize (_tSize)
{ {
// consistency check // consistency check
if (tSize < 2) if (tSize < 2)
{ {
std:: cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n"; tSize = 2;
tSize = 2; }
} }
}
/**
/** * Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default.
* Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default. * @param _evalFitness the fitness assignment strategy
* @param _evalFitness the population fitness assignment * @param _evalDiversity the diversity assignment strategy
* @param _evalDiversity the population diversity assignme * @param _tSize the number of individuals in the tournament (default: 2)
* @param _tSize the number of individuals in the tournament (default: 2)
*/ */
moeoDetTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDiversityAssignment < MOEOT > &_evalDiversity, unsigned _tSize = 2) moeoDetTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDiversityAssignment < MOEOT > &_evalDiversity, unsigned _tSize = 2) :
:evalFitness (_evalFitness),evalDiversity(_evalDiversity),tSize(_tSize) evalFitness (_evalFitness),evalDiversity(_evalDiversity),tSize(_tSize)
{ {
// a moeoFitThenDivComparator is used as default // a moeoFitThenDivComparator is used as default
moeoFitnessThenDiversityComparator < MOEOT > &fitThenDivComparator; moeoFitnessThenDiversityComparator < MOEOT > & fitThenDivComparator;
comparator = fitThenDivComparator; comparator = fitThenDivComparator;
// consistency check // consistency check
if (tSize < 2) if (tSize < 2)
{ {
std:: cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n"; tSize = 2;
tSize = 2; }
} }
}
/** /**
* Ctor without diversity assignment. A dummy diversity assignment is used. * Ctor without diversity assignment. A dummy diversity assignment is used.
* @param _evalFitness the population fitness assignment * @param _evalFitness the fitness assignment strategy
* @param _comparator the comparator to compare the individuals * @param _comparator the comparator (used to compare 2 individuals)
* @param _tSize the number of individuals in the tournament (default: 2) * @param _tSize the number of individuals in the tournament (default: 2)
*/ */
moeoDetTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoComparator < MOEOT > &_comparator, unsigned _tSize = 2):evalFitness (_evalFitness), comparator (_comparator), moeoDetTournamentSelect (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoComparator < MOEOT > & _comparator, unsigned _tSize = 2) :
tSize evalFitness (_evalFitness), comparator (_comparator), tSize (_tSize)
(_tSize) {
{ // a dummy diversity is used as default
// a dummy diversity is used as default moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment;
moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment; evalDiversity = dummyDiversityAssignment;
evalDiversity = dummyDiversityAssignment; // consistency check
if (tSize < 2)
// consistency check {
if (tSize < 2) cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
{ tSize = 2;
std:: }
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n"; }
tSize = 2;
}
} /**
* Ctor without diversity assignment nor comparator.
* A moeoDummyDiversityAssignment and a moeoFitnessThenDiversityComparator are used as default.
/** * @param _evalFitness the fitness assignment strategy
* Ctor without diversity assignment nor comparator. A moeoDummyDiversityAssignment and a moeoFitnessThenDiversityComparator are used as default.
* @param _evalFitness the population fitness assignment
* @param _tSize the number of individuals in the tournament (default: 2) * @param _tSize the number of individuals in the tournament (default: 2)
*/ */
moeoDetTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, unsigned _tSize = 2):evalFitness (_evalFitness), moeoDetTournamentSelect (moeoFitnessAssignment < MOEOT > & _evalFitness, unsigned _tSize = 2) :
tSize evalFitness (_evalFitness), tSize (_tSize)
(_tSize) {
{ // a dummy diversity is used as default
// a dummy diversity is used as default moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment;
moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment; evalDiversity = dummyDiversityAssignment;
evalDiversity = dummyDiversityAssignment; // a moeoFitThenDivComparator is used as default
moeoFitnessThenDiversityComparator < MOEOT > &fitThenDivComparator;
// a moeoFitThenDivComparator is used as default comparator = fitThenDivComparator;
moeoFitnessThenDiversityComparator < MOEOT > &fitThenDivComparator; // consistency check
comparator = fitThenDivComparator; if (tSize < 2)
{
// consistency check cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
if (tSize < 2) tSize = 2;
{ }
std:: }
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
tSize = 2;
} /**
} * Evaluate the fitness and the diversity of each individual of the population _pop.
* @param _pop the population
*/
/*
* Evaluate the fitness and the diversity of each individual of the population.
*/
void setup (eoPop<MOEOT>& _pop) void setup (eoPop<MOEOT>& _pop)
{ {
// eval fitness // eval fitness
evalFitness(_pop); evalFitness(_pop);
// eval diversity
// eval diversity evalDiversity(_pop);
evalDiversity(_pop); }
}
/** /**
* Apply the tournament to the given population * Apply the tournament to the given population
*/ * @param _pop the population
const MOEOT & operator () (const eoPop < MOEOT > &_pop) */
{ const MOEOT & operator () (const eoPop < MOEOT > &_pop)
// use the selector {
return mo_deterministic_tournament(_pop,tSize,comparator); // use the selector
} return mo_deterministic_tournament(_pop,tSize,comparator);
}
protected: protected:
moeoFitnessAssignment < MOEOT > &evalFitness; /** the fitness assignment strategy */
moeoFitnessAssignment < MOEOT > & evalFitness;
moeoDiversityAssignment < MOEOT > &evalDiversity; /** the diversity assignment strategy */
moeoDiversityAssignment < MOEOT > & evalDiversity;
moeoComparator < MOEOT > &comparator; /** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > & comparator;
/** the number of individuals in the tournament */
unsigned tSize; unsigned tSize;
}; };
#endif /*MOEODETTOURNAMENTSELECT_H_ */ #endif /*MOEODETTOURNAMENTSELECT_H_*/

View file

@ -10,105 +10,106 @@
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef MOEOELITISTREPLACEMENT_H_ #ifndef MOEOELITISTREPLACEMENT_H_
#define MOEOELITISTREPLACEMENT_H_ #define MOEOELITISTREPLACEMENT_H_
//-----------------------------------------------------------------------------
#include <moeoReplacement.h> #include <moeoReplacement.h>
#include <moeoComparator.h> #include <moeoComparator.h>
#include <moeoFitnessAssignment.h> #include <moeoFitnessAssignment.h>
#include <moeoDiversityAssignment.h> #include <moeoDiversityAssignment.h>
//-----------------------------------------------------------------------------
/** /**
* Elitist replacement strategy for multi-objective optimization. * Elitist replacement strategy for multi-objective optimization.
*/ */
template < class MOEOT > class moeoElitistReplacement:public moeoReplacement < template < class MOEOT > class moeoElitistReplacement:public moeoReplacement < MOEOT >
MOEOT >
{ {
public: public:
/** Full constructor */ /**
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDiversityAssignment < MOEOT > &_evalDiversity, moeoComparator < MOEOT > _comparator):evalFitness (_evalFitness), evalDiversity (_evalDiversity), * Full constructor.
comparator * @param _evalFitness the fitness assignment strategy
(_comparator) * @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) :
/** constructor without comparator */ evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (_comparator)
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDiversityAssignment < MOEOT > &_evalDiversity) {}
:evalFitness (_evalFitness), evalDiversity (_evalDiversity)
{ /**
// a moeoFitThenDivComparator is used as default * 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)
{
// a moeoFitThenDivComparator is used as default
moeoFitnessThenDiversityComparator < MOEOT > &fitThenDivComparator; moeoFitnessThenDiversityComparator < MOEOT > &fitThenDivComparator;
comparator = fitThenDivComparator; comparator = fitThenDivComparator;
} }
/**
* 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), comparator (_comparator)
{
// a dummy diversity is used as default
moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment;
evalDiversity = dummyDiversityAssignment;
}
/**
* 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)
{
// a dummy diversity is used as default
moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment;
evalDiversity = dummyDiversityAssignment;
// a moeoFitThenDivComparator is used as default
moeoFitnessThenDiversityComparator < MOEOT > &fitThenDivComparator;
comparator = fitThenDivComparator;
}
/**
* 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
std::sort (_parents.begin (), _parents.end (), comparator);
// finally, resize this global population
_parents.resize (sz);
// and clear the offspring population
_offspring.clear ();
}
/** Constructor without moeoDiversityAssignement */
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoComparator < MOEOT > _comparator):evalFitness (_evalFitness),
comparator
(_comparator)
{
// a dummy diversity is used as default
moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment;
evalDiversity = dummyDiversityAssignment;
}
/** Constructor without moeoDiversityAssignement nor moeoComparator */
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > &_evalFitness):evalFitness
(_evalFitness)
{
// a dummy diversity is used as default
moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment;
evalDiversity = dummyDiversityAssignment;
// a moeoFitThenDivComparator is used as default
moeoFitnessThenDiversityComparator < MOEOT > &fitThenDivComparator;
comparator = fitThenDivComparator;
}
/**
* Replace 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
*/
void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring)
{
unsigned sz = _parents.size ();
// merge offspring and parents into a global population ...
_parents.reserve (_parents.size () + _offspring.size ());
copy (_offspring.begin (), _offspring.end (), back_inserter (_parents));
// evaluate the fitness and the diversity of this global population
evalFitness (_parents);
evalDiversity (_parents);
// ... that we sort according to the comparator
std::sort (_parents.begin (), _parents.end (), comparator);
// finally, resize this global population
_parents.resize (sz);
_offspring.clear ();
}
protected: protected:
moeoFitnessAssignment < MOEOT > &evalFitness; /** the fitness assignment strategy */
moeoFitnessAssignment < MOEOT > &evalFitness;
/** the diversity assignment strategy */
moeoDiversityAssignment < MOEOT > &evalDiversity;
/** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > &comparator;.
moeoDiversityAssignment < MOEOT > &evalDiversity;
moeoComparator < MOEOT > &comparator;
}; };
#endif /*MOEOELITISTREPLACEMENT_H_ */ #endif /*MOEOELITISTREPLACEMENT_H_ */

View file

@ -24,24 +24,23 @@ template < class MOEOT > class moeoRandomSelect:public moeoSelectOne < MOEOT >,
public: public:
/** /**
* CTor. * Ctor.
*/ */
moeoRandomSelect(){} moeoRandomSelect(){}
/* /**
* Do nothing: we don't need to evaluate the fitness and the diversity; we only select one individual at random. * Do nothing: we don't need to evaluate the fitness and the diversity; we only select one individual randomly.
*/ */
void setup (eoPop < MOEOT > &_pop) void setup (eoPop < MOEOT > &_pop)
{ {
// do nothing // nothing to do
} }
/** /**
* Return one individual at random. // Need to have a "const" pop ? * Return one individual at random.
*/ */
const MOEOT & operator () (const eoPop < MOEOT > &_pop) const MOEOT & operator () (const eoPop < MOEOT > &_pop)
{ {
eoRandomSelect < MOEOT >::operator ()(_pop); eoRandomSelect < MOEOT >::operator ()(_pop);
} }

View file

@ -17,13 +17,13 @@
#include <moeoSelectors.h> #include <moeoSelectors.h>
/** /**
* moeoRouletteSelect: a selection method that selects ONE individual by * Selection strategy that selects ONE individual by using roulette wheel process.
* using roulette wheel process
*/ */
template < class MOEOT > template < class MOEOT >
class moeoRouletteSelect:public moeoSelectOne <MOEOT> class moeoRouletteSelect:public moeoSelectOne <MOEOT>
{ {
public: public:
/** /**
* Full Ctor * Full Ctor
* @param _evalFitness the population fitness assignment * @param _evalFitness the population fitness assignment

View file

@ -17,22 +17,22 @@
#include <moeoSelectors.h> #include <moeoSelectors.h>
/** /**
* ??? * Selection strategy that selects ONE individual by stochastic tournament.
*/ */
template < class MOEOT > class moeoStochTournamentSelect:public moeoSelectOne <MOEOT> template < class MOEOT > class moeoStochTournamentSelect:public moeoSelectOne <MOEOT>
{ {
public: public:
/** /**
* Full Ctor * Full Ctor
* @param _evalFitness the population fitness assignment * @param _evalFitness the fitness assignment strategy
* @param _evalDiversity the population diversity assignment * @param _evalDiversity the diversity assignment strategy
* @param _comparator the comparator to compare the individuals * @param _comparator the comparator (used to compare 2 individuals)
* @param _tRate the tournament rate * @param _tRate the tournament rate
*/ */
moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDiversityAssignment < MOEOT > &_evalDiversity, moeoComparator < MOEOT > &_comparator, double _tRate = 1.0):evalFitness (_evalFitness), evalDiversity (_evalDiversity), moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity, moeoComparator < MOEOT > & _comparator, double _tRate = 1.0) :
comparator (_comparator), evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (_comparator), tRate (_tRate)
tRate (_tRate) {
{
// consistency checks // consistency checks
if (tRate < 0.5) if (tRate < 0.5)
{ {
@ -51,12 +51,12 @@ moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDi
/** /**
* Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default. * Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default.
* @param _evalFitness the population fitness assignment * @param _evalFitness the fitness assignment strategy
* @param _evalDiversity the population diversity assignment * @param _evalDiversity the diversity assignment strategy
* @param _tRate the tournament rate * @param _tRate the tournament rate
*/ */
moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDiversityAssignment < MOEOT > &_evalDiversity) moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDiversityAssignment < MOEOT > &_evalDiversity, double _tRate = 1.0)
:evalFitness (_evalFitness), evalDiversity (_evalDiversity) :evalFitness (_evalFitness), evalDiversity (_evalDiversity), tRate (_tRate)
{ {
// a moeoFitThenDivComparator is used as default // a moeoFitThenDivComparator is used as default
@ -67,8 +67,9 @@ moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDi
/** /**
* Ctor without diversity assignment. A dummy diversity assignment is used. * Ctor without diversity assignment. A dummy diversity assignment is used.
* @param _evalFitness the population fitness assignment * @param _evalFitness the fitness assignment strategy
* @param _comparator the comparator to compare the individuals * @param _comparator the comparator (used to compare 2 individuals)
* @param _tRate the tournament rate
*/ */
moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoComparator < MOEOT > &_comparator, double _tRate = 1.0):evalFitness (_evalFitness), comparator (_comparator), moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoComparator < MOEOT > &_comparator, double _tRate = 1.0):evalFitness (_evalFitness), comparator (_comparator),
tRate tRate
@ -97,7 +98,8 @@ moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoCo
/** /**
* Ctor without diversity assignment nor comparator. A moeoDummyDiversityAssignment and a moeoFitnessThenDiversityComparator are used as default. * Ctor without diversity assignment nor comparator. A moeoDummyDiversityAssignment and a moeoFitnessThenDiversityComparator are used as default.
* @param _evalFitness the population fitness assignment * @param _evalFitness the fitness assignment strategy
* @param _tRate the tournament rate
*/ */
moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, double _tRate = 1.0):evalFitness (_evalFitness), moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, double _tRate = 1.0):evalFitness (_evalFitness),
tRate tRate
@ -128,20 +130,21 @@ moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, double
} }
/* /**
* Evaluate the fitness and the diversity of each individual of the population. * Evaluate the fitness and the diversity of each individual of the population.
* @param _pop the population
*/ */
void setup (eoPop<MOEOT>& _pop) void setup (eoPop<MOEOT>& _pop)
{ {
// eval fitness // eval fitness
evalFitness(_pop); evalFitness(_pop);
// eval diversity // eval diversity
evalDiversity(_pop); evalDiversity(_pop);
} }
/** /**
* Apply the tournament to the given population * Apply the tournament to the given population
* @param _pop the population
*/ */
const MOEOT & operator() (const eoPop < MOEOT > &_pop) const MOEOT & operator() (const eoPop < MOEOT > &_pop)
{ {
@ -152,15 +155,15 @@ moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, double
protected: protected:
/** the fitness assignment strategy */
moeoFitnessAssignment < MOEOT > & evalFitness;
/** the diversity assignment strategy */
moeoDiversityAssignment < MOEOT > & evalDiversity;
/** the diversity assignment strategy */
moeoComparator < MOEOT > & comparator;
/** the tournament rate */
double tRate;
moeoFitnessAssignment < MOEOT > &evalFitness;
moeoDiversityAssignment < MOEOT > &evalDiversity;
moeoComparator < MOEOT > &comparator;
double tRate;
}; };
#endif /*MOEOSTOCHTOURNAMENTSELECT_H_ */ #endif /*MOEOSTOCHTOURNAMENTSELECT_H_ */