rm fit and div, replace constructors and indent
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@214 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
3fcb41da44
commit
d710dc0d6c
1 changed files with 51 additions and 120 deletions
|
|
@ -14,140 +14,71 @@
|
|||
#define MOEODETTOURNAMENTSELECT_H_
|
||||
|
||||
#include <moeoComparator.h>
|
||||
#include <moeoDiversityAssignment.h>
|
||||
#include <moeoFitnessAssignment.h>
|
||||
#include <moeoSelectOne.h>
|
||||
#include <moeoSelectors.h>
|
||||
|
||||
/**
|
||||
* Selection strategy that selects ONE individual by deterministic tournament.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoDetTournamentSelect : public moeoSelectOne <MOEOT>
|
||||
template < class MOEOT > class moeoDetTournamentSelect:public moeoSelectOne <
|
||||
MOEOT >
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Full Ctor.
|
||||
* @param _evalFitness the fitness assignment strategy
|
||||
* @param _evalDiversity the diversity assignment strategy
|
||||
* @param _comparator the comparator (used to compare 2 individuals)
|
||||
* @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), comparator (_comparator), tSize (_tSize)
|
||||
{
|
||||
// consistency check
|
||||
if (tSize < 2)
|
||||
{
|
||||
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
|
||||
tSize = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default.
|
||||
* @param _evalFitness the fitness assignment strategy
|
||||
* @param _evalDiversity the diversity assignment strategy
|
||||
* @param _tSize the number of individuals in the tournament (default: 2)
|
||||
*/
|
||||
moeoDetTournamentSelect (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity, unsigned _tSize = 2) :
|
||||
evalFitness (_evalFitness),evalDiversity(_evalDiversity),tSize(_tSize)
|
||||
{
|
||||
// a moeoFitThenDivComparator is used as default
|
||||
moeoFitnessThenDiversityComparator < MOEOT > & fitThenDivComparator;
|
||||
comparator = fitThenDivComparator;
|
||||
// consistency check
|
||||
if (tSize < 2)
|
||||
{
|
||||
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
|
||||
tSize = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ctor without diversity assignment. A dummy diversity assignment is used.
|
||||
* @param _evalFitness the fitness assignment strategy
|
||||
* @param _comparator the comparator (used to compare 2 individuals)
|
||||
* @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), tSize (_tSize)
|
||||
{
|
||||
// a dummy diversity is used as default
|
||||
moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment;
|
||||
evalDiversity = dummyDiversityAssignment;
|
||||
// consistency check
|
||||
if (tSize < 2)
|
||||
{
|
||||
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
|
||||
* @param _tSize the number of individuals in the tournament (default: 2)
|
||||
*/
|
||||
moeoDetTournamentSelect (moeoFitnessAssignment < MOEOT > & _evalFitness, unsigned _tSize = 2) :
|
||||
evalFitness (_evalFitness), tSize (_tSize)
|
||||
{
|
||||
// a dummy diversity is used as default
|
||||
moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment;
|
||||
evalDiversity = dummyDiversityAssignment;
|
||||
// a moeoFitThenDivComparator is used as default
|
||||
moeoFitnessThenDiversityComparator < MOEOT > &fitThenDivComparator;
|
||||
comparator = fitThenDivComparator;
|
||||
// consistency check
|
||||
if (tSize < 2)
|
||||
{
|
||||
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
|
||||
*/
|
||||
//void setup (eoPop<MOEOT>& _pop)
|
||||
virtual void setup(const eoPop<MOEOT>& _pop)
|
||||
{
|
||||
// eval fitness
|
||||
//evalFitness(_pop);
|
||||
// eval diversity
|
||||
//evalDiversity(_pop);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
* 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 fitness assignment strategy */
|
||||
moeoFitnessAssignment < MOEOT > & evalFitness;
|
||||
/** the diversity assignment strategy */
|
||||
moeoDiversityAssignment < MOEOT > & evalDiversity;
|
||||
/** the comparator (used to compare 2 individuals) */
|
||||
moeoComparator < MOEOT > & comparator;
|
||||
/** the number of individuals in the tournament */
|
||||
unsigned tSize;
|
||||
|
||||
/** the comparator (used to compare 2 individuals) */
|
||||
moeoComparator < MOEOT > &comparator;
|
||||
|
||||
/** the number of individuals in the tournament */
|
||||
unsigned tSize;
|
||||
};
|
||||
|
||||
#endif /*MOEODETTOURNAMENTSELECT_H_*/
|
||||
#endif /*MOEODETTOURNAMENTSELECT_H_ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue