From 3298fadc1e093edd89c8e731a6d2e2fb40f74bc1 Mon Sep 17 00:00:00 2001 From: legrand Date: Fri, 13 Apr 2007 13:11:23 +0000 Subject: [PATCH] rm fit and div, replace constructors and indent git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@217 331e1502-861f-0410-8da2-ba01fb791d7f --- .../src/moeoRouletteSelect.h | 102 ++++++------------ 1 file changed, 32 insertions(+), 70 deletions(-) diff --git a/branches/paradiseo-moeo-1.0/src/moeoRouletteSelect.h b/branches/paradiseo-moeo-1.0/src/moeoRouletteSelect.h index 8ea1ef10e..b22879e3d 100644 --- a/branches/paradiseo-moeo-1.0/src/moeoRouletteSelect.h +++ b/branches/paradiseo-moeo-1.0/src/moeoRouletteSelect.h @@ -24,75 +24,41 @@ template < class MOEOT > { public: - /** - * Full Ctor - * @param _evalFitness the population fitness assignment - * @param _evalDiversity the population diversity assignment - * @param _comparator the comparator to compare the individuals - * @param _total - */ - moeoRouletteSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDiversityAssignment < MOEOT > &_evalDiversity, moeoComparator < MOEOT > &_comparator, double _total=1 ):evalFitness (_evalFitness), evalDiversity (_evalDiversity), - comparator (_comparator), total (_total) {} /** - * Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default. - * @param _evalFitness the population fitness assignment - * @param _evalDiversity the population diversity assignment - * @param _total - */ - moeoRouletteSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoDiversityAssignment < MOEOT > &_evalDiversity) - :evalFitness (_evalFitness), evalDiversity (_evalDiversity) - - { - // a moeoFitThenDivComparator is used as default - moeoFitnessThenDiversityComparator < MOEOT > &fitThenDivComparator; - comparator = fitThenDivComparator; - } - - /** - * Ctor without diversity assignment. A dummy diversity assignment is used. - * @param _evalFitness the population fitness assignment - * @param _comparator the comparator to compare the individuals - * @param _total - */ -moeoRouletteSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, moeoComparator < MOEOT > &_comparator, double _total=1):evalFitness (_evalFitness), comparator (_comparator), - total - (_total) - { - // a dummy diversity is used as default - moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment; - evalDiversity = dummyDiversityAssignment; - } + * Full Ctor. + * @param _comparator the comparator (used to compare 2 individuals) + * @param _tSize the number of individuals in the tournament (default: 2) + */ + moeoRouletteSelect (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 diversity assignment nor comparator. A moeoDummyDiversityAssignment and a moeoFitnessThenDiversityComparator are used as default. - * @param _evalFitness the population fitness assignment - * @param _total - */ -moeoRouletteSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, double _total=1):evalFitness (_evalFitness), - total (_total) - { - // a dummy diversity is used as default - moeoDummyDiversityAssignment < MOEOT > &dummyDiversityAssignment; - evalDiversity = dummyDiversityAssignment; - - // a moeoFitThenDivComparator is used as default - moeoFitnessThenDiversityComparator < MOEOT > &fitThenDivComparator; - comparator = fitThenDivComparator; - } - - /* - * Evaluate the fitness and the diversity of each individual of the population. - */ - void setup (eoPop& _pop) - { - // eval fitness - evalFitness(_pop); - - // eval diversity - evalDiversity(_pop); - } + /** + * Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default. + * @param _tSize the number of individuals in the tournament (default: 2) + */ + moeoRouletteSelect (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 @@ -106,13 +72,9 @@ moeoRouletteSelect (moeoFitnessAssignment < MOEOT > &_evalFitness, double _total protected: - moeoFitnessAssignment < MOEOT > &evalFitness; - - moeoDiversityAssignment < MOEOT > &evalDiversity; - moeoComparator < MOEOT > &comparator; - double total; + double & total; };