rm fit and div, replace constructors and indent
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@216 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
f9d9271618
commit
337b09950f
1 changed files with 63 additions and 136 deletions
|
|
@ -23,146 +23,73 @@ template < class MOEOT > class moeoStochTournamentSelect:public moeoSelectOne <M
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full Ctor
|
* Full Ctor
|
||||||
* @param _evalFitness the fitness assignment strategy
|
* @param _comparator the comparator (used to compare 2 individuals)
|
||||||
* @param _evalDiversity the diversity assignment strategy
|
* @param _tRate the tournament rate
|
||||||
* @param _comparator the comparator (used to compare 2 individuals)
|
*/
|
||||||
* @param _tRate the tournament rate
|
moeoStochTournamentSelect (moeoComparator < MOEOT > & _comparator, double _tRate = 1.0) :
|
||||||
*/
|
comparator (_comparator), tRate (_tRate)
|
||||||
moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity, moeoComparator < MOEOT > & _comparator, double _tRate = 1.0) :
|
{
|
||||||
evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (_comparator), tRate (_tRate)
|
// consistency checks
|
||||||
{
|
if (tRate < 0.5)
|
||||||
// consistency checks
|
{
|
||||||
if (tRate < 0.5)
|
std::
|
||||||
{
|
cerr <<
|
||||||
std::
|
"Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
|
||||||
cerr <<
|
tRate = 0.55;
|
||||||
"Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
|
}
|
||||||
tRate = 0.55;
|
if (tRate > 1)
|
||||||
}
|
{
|
||||||
if (tRate > 1)
|
std::
|
||||||
{
|
cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
|
||||||
std::
|
tRate = 1;
|
||||||
cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
|
}
|
||||||
tRate = 1;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 _tRate the tournament rate
|
||||||
* @param _evalDiversity the diversity assignment strategy
|
*/
|
||||||
* @param _tRate the tournament rate
|
moeoStochTournamentSelect (double _tRate = 1.0)
|
||||||
*/
|
:comparator (*(new moeoFitnessThenDiversityComparator < MOEOT > ())), tRate (_tRate)
|
||||||
moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDiversityAssignment < MOEOT > &_evalDiversity, double _tRate = 1.0)
|
|
||||||
:evalFitness (_evalFitness), evalDiversity (_evalDiversity), tRate (_tRate)
|
|
||||||
|
|
||||||
{
|
|
||||||
// a moeoFitThenDivComparator is used as default
|
|
||||||
moeoFitnessThenDiversityComparator < MOEOT > &fitThenDivComparator;
|
|
||||||
comparator = fitThenDivComparator;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
{
|
||||||
* Ctor without diversity assignment. A dummy diversity assignment is used.
|
// consistency checks
|
||||||
* @param _evalFitness the fitness assignment strategy
|
if (tRate < 0.5)
|
||||||
* @param _comparator the comparator (used to compare 2 individuals)
|
{
|
||||||
* @param _tRate the tournament rate
|
std::
|
||||||
*/
|
cerr <<
|
||||||
moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoComparator < MOEOT > &_comparator, double _tRate = 1.0):evalFitness (_evalFitness), comparator (_comparator),
|
"Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
|
||||||
tRate
|
tRate = 0.55;
|
||||||
(_tRate)
|
}
|
||||||
{
|
if (tRate > 1)
|
||||||
// a dummy diversity is used as default
|
{
|
||||||
moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment;
|
std::
|
||||||
evalDiversity = dummyDiversityAssignment;
|
cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
|
||||||
|
tRate = 1;
|
||||||
// consistency checks
|
}
|
||||||
if (tRate < 0.5)
|
}
|
||||||
{
|
|
||||||
std::
|
|
||||||
cerr <<
|
|
||||||
"Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
|
|
||||||
tRate = 0.55;
|
|
||||||
}
|
|
||||||
if (tRate > 1)
|
|
||||||
{
|
|
||||||
std::
|
|
||||||
cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
|
|
||||||
tRate = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor without diversity assignment nor comparator. A moeoDummyDiversityAssignment and a moeoFitnessThenDiversityComparator are used as default.
|
* Apply the tournament to the given population
|
||||||
* @param _evalFitness the fitness assignment strategy
|
* @param _pop the population
|
||||||
* @param _tRate the tournament rate
|
*/
|
||||||
*/
|
const MOEOT & operator() (const eoPop < MOEOT > &_pop)
|
||||||
moeoStochTournamentSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, double _tRate = 1.0):evalFitness (_evalFitness),
|
{
|
||||||
tRate
|
// use the selector
|
||||||
(_tRate)
|
return mo_stochastic_tournament(_pop,tRate,comparator);
|
||||||
{
|
}
|
||||||
// a dummy diversity is used as default
|
|
||||||
moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment;
|
|
||||||
evalDiversity = dummyDiversityAssignment;
|
|
||||||
|
|
||||||
// a moeoFitThenDivComparator is used as default
|
|
||||||
moeoFitnessThenDiversityComparator < MOEOT > &fitThenDivComparator;
|
|
||||||
comparator = fitThenDivComparator;
|
|
||||||
|
|
||||||
// consistency checks
|
|
||||||
if (tRate < 0.5)
|
|
||||||
{
|
|
||||||
std::
|
|
||||||
cerr <<
|
|
||||||
"Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
|
|
||||||
tRate = 0.55;
|
|
||||||
}
|
|
||||||
if (tRate > 1)
|
|
||||||
{
|
|
||||||
std::
|
|
||||||
cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
|
|
||||||
tRate = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Evaluate the fitness and the diversity of each individual of the population.
|
|
||||||
* @param _pop the population
|
|
||||||
*/
|
|
||||||
void setup (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_stochastic_tournament(_pop,tRate,comparator);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** the fitness assignment strategy */
|
|
||||||
moeoFitnessAssignment < MOEOT > & evalFitness;
|
/** the diversity assignment strategy */
|
||||||
/** the diversity assignment strategy */
|
moeoComparator < MOEOT > & comparator;
|
||||||
moeoDiversityAssignment < MOEOT > & evalDiversity;
|
/** the tournament rate */
|
||||||
/** the diversity assignment strategy */
|
double tRate;
|
||||||
moeoComparator < MOEOT > & comparator;
|
|
||||||
/** the tournament rate */
|
|
||||||
double tRate;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue