diff --git a/branches/paradiseo-moeo-1.0/src/moeoComparator.h b/branches/paradiseo-moeo-1.0/src/moeoComparator.h index 064c0f78a..259dae142 100644 --- a/branches/paradiseo-moeo-1.0/src/moeoComparator.h +++ b/branches/paradiseo-moeo-1.0/src/moeoComparator.h @@ -30,17 +30,27 @@ template < class MOEOT > class moeoObjectiveComparator : public moeoComparator < MOEOT > { public: + /** - * Returns true if _moeo1 is greater than _moeo2 on the first objective, then on the second, and so on + * Returns true if _moeo1 < _moeo2 on the first objective, then on the second, and so on * @param _moeo1 the first solution * @param _moeo2 the second solution */ const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - return _moeo1.objectiveVector() > _moeo2.objectiveVector(); + return cmp(_moeo1.objectiveVector(), _moeo2.objectiveVector()); } + +private: + + /** the objective vector type of the solutions */ + typedef typename MOEOT::ObjectiveVector ObjectiveVector; + /** the corresponding comparator for objective vectors */ + moeoObjectiveObjectiveVectorComparator < ObjectiveVector > cmp; + }; + /** * Functor allowing to compare two solutions according to one objective. */ @@ -62,17 +72,17 @@ public: } /** - * Returns true if _moeo1 is greater than _moeo2 on the obj objective + * Returns true if _moeo1 < _moeo2 on the obj objective * @param _moeo1 the first solution * @param _moeo2 the second solution */ const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - return _moeo1.objectiveVector()[obj] > _moeo2.objectiveVector()[obj]; + return _moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj]; } private: - /** the index of objective */ + /** the index of objective */ unsigned obj; }; @@ -85,8 +95,9 @@ template < class MOEOT > class moeoFitnessThenDiversityComparator : public moeoComparator < MOEOT > { public: + /** - * Returns true if _moeo1 is greater than _moeo2 according to their fitness values, then according to their diversity values + * Returns true if _moeo1 < _moeo2 according to their fitness values, then according to their diversity values * @param _moeo1 the first solution * @param _moeo2 the second solution */ @@ -94,13 +105,14 @@ public: { if (_moeo1.fitness() == _moeo2.fitness()) { - return _moeo1.diversity() > _moeo2.diversity(); + return _moeo1.diversity() < _moeo2.diversity(); } else { - return _moeo1.fitness() > _moeo2.fitness(); + return _moeo1.fitness() < _moeo2.fitness(); } } + }; @@ -111,8 +123,9 @@ template < class MOEOT > class moeoDiversityThenFitnessComparator : public moeoComparator < MOEOT > { public: + /** - * Returns true if _moeo1 is greater than _moeo2 according to their diversity values, then according to their fitness values + * Returns true if _moeo1 < _moeo2 according to their diversity values, then according to their fitness values * @param _moeo1 the first solution * @param _moeo2 the second solution */ @@ -120,13 +133,14 @@ public: { if (_moeo1.diversity() == _moeo2.diversity()) { - return _moeo1.fitness() > _moeo2.fitness(); + return _moeo1.fitness() < _moeo2.fitness(); } else { - return _moeo1.diversity() > _moeo2.diversity(); + return _moeo1.diversity() < _moeo2.diversity(); } } + };