From bda48533e86fba81f92cb64d13522c0cbfbc8808 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Wed, 20 Mar 2013 17:42:04 +0100 Subject: [PATCH] Suppress warnings when compiling MOEO functions returning const When compiling whith --Wignored-qualifiers, g++ no more warns about ignoring const in methods *returning* a const, which isn't logical. --- .../comparator/moeoAggregativeComparator.h | 2 +- .../moeoDiversityThenFitnessComparator.h | 2 +- .../moeoEpsilonObjectiveVectorComparator.h | 2 +- moeo/src/comparator/moeoFitnessComparator.h | 2 +- .../moeoFitnessThenDiversityComparator.h | 2 +- .../moeoGDominanceObjectiveVectorComparator.h | 2 +- .../moeoObjectiveObjectiveVectorComparator.h | 2 +- .../comparator/moeoOneObjectiveComparator.h | 2 +- .../moeoParetoObjectiveVectorComparator.h | 2 +- moeo/src/comparator/moeoPtrComparator.h | 37 +++++++++---------- .../moeoStrictObjectiveVectorComparator.h | 2 +- .../moeoWeakObjectiveVectorComparator.h | 2 +- moeo/src/distance/moeoManhattanDistance.h | 6 +-- .../moeoDominanceDepthFitnessAssignment.h | 2 +- 14 files changed, 33 insertions(+), 34 deletions(-) diff --git a/moeo/src/comparator/moeoAggregativeComparator.h b/moeo/src/comparator/moeoAggregativeComparator.h index d684c54eb..e969f27d9 100644 --- a/moeo/src/comparator/moeoAggregativeComparator.h +++ b/moeo/src/comparator/moeoAggregativeComparator.h @@ -62,7 +62,7 @@ class moeoAggregativeComparator : public moeoComparator < MOEOT > * @param _moeo1 the first solution * @param _moeo2 the second solution */ - const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) + bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { return ( weightFitness * _moeo1.fitness() + weightDiversity * _moeo1.diversity() ) < ( weightFitness * _moeo2.fitness() + weightDiversity * _moeo2.diversity() ); } diff --git a/moeo/src/comparator/moeoDiversityThenFitnessComparator.h b/moeo/src/comparator/moeoDiversityThenFitnessComparator.h index db58f936f..b094a7787 100644 --- a/moeo/src/comparator/moeoDiversityThenFitnessComparator.h +++ b/moeo/src/comparator/moeoDiversityThenFitnessComparator.h @@ -53,7 +53,7 @@ class moeoDiversityThenFitnessComparator : public moeoComparator < MOEOT > * @param _moeo1 the first solution * @param _moeo2 the second solution */ - const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) + bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { if (_moeo1.diversity() == _moeo2.diversity()) { diff --git a/moeo/src/comparator/moeoEpsilonObjectiveVectorComparator.h b/moeo/src/comparator/moeoEpsilonObjectiveVectorComparator.h index 54f373583..8d7639fc3 100644 --- a/moeo/src/comparator/moeoEpsilonObjectiveVectorComparator.h +++ b/moeo/src/comparator/moeoEpsilonObjectiveVectorComparator.h @@ -60,7 +60,7 @@ public: * @param _objectiveVector1 the first objective vector * @param _objectiveVector2 the second objective vector */ - const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) + bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) { for (unsigned int i=0; i * @param _moeo1 the first solution * @param _moeo2 the second solution */ - const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) + bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { return _moeo1.fitness() < _moeo2.fitness(); } diff --git a/moeo/src/comparator/moeoFitnessThenDiversityComparator.h b/moeo/src/comparator/moeoFitnessThenDiversityComparator.h index cf6c4004b..910e5458f 100644 --- a/moeo/src/comparator/moeoFitnessThenDiversityComparator.h +++ b/moeo/src/comparator/moeoFitnessThenDiversityComparator.h @@ -53,7 +53,7 @@ class moeoFitnessThenDiversityComparator : public moeoComparator < MOEOT > * @param _moeo1 the first solution * @param _moeo2 the second solution */ - const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) + bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { if (_moeo1.fitness() == _moeo2.fitness()) { diff --git a/moeo/src/comparator/moeoGDominanceObjectiveVectorComparator.h b/moeo/src/comparator/moeoGDominanceObjectiveVectorComparator.h index c51e26c02..ecdb54064 100644 --- a/moeo/src/comparator/moeoGDominanceObjectiveVectorComparator.h +++ b/moeo/src/comparator/moeoGDominanceObjectiveVectorComparator.h @@ -64,7 +64,7 @@ class moeoGDominanceObjectiveVectorComparator : public moeoObjectiveVectorCompar * @param _objectiveVector1 the first objective vector * @param _objectiveVector2 the second objective vector */ - const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) + bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) { unsigned int flag1 = flag(_objectiveVector1); unsigned int flag2 = flag(_objectiveVector2); diff --git a/moeo/src/comparator/moeoObjectiveObjectiveVectorComparator.h b/moeo/src/comparator/moeoObjectiveObjectiveVectorComparator.h index 751b4b282..86ff74e86 100644 --- a/moeo/src/comparator/moeoObjectiveObjectiveVectorComparator.h +++ b/moeo/src/comparator/moeoObjectiveObjectiveVectorComparator.h @@ -53,7 +53,7 @@ class moeoObjectiveObjectiveVectorComparator : public moeoObjectiveVectorCompara * @param _objectiveVector1 the first objective vector * @param _objectiveVector2 the second objective vector */ - const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) + bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) { for (unsigned int i=0; i * @param _moeo1 the first solution * @param _moeo2 the second solution */ - const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) + bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { return _moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj]; } diff --git a/moeo/src/comparator/moeoParetoObjectiveVectorComparator.h b/moeo/src/comparator/moeoParetoObjectiveVectorComparator.h index fca1614f9..34757114e 100644 --- a/moeo/src/comparator/moeoParetoObjectiveVectorComparator.h +++ b/moeo/src/comparator/moeoParetoObjectiveVectorComparator.h @@ -53,7 +53,7 @@ class moeoParetoObjectiveVectorComparator : public moeoObjectiveVectorComparator * @param _objectiveVector1 the first objective vector * @param _objectiveVector2 the second objective vector */ - const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) + bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) { bool dom = false; for (unsigned int i=0; i -class moeoPtrComparator : public eoBF < const MOEOT *, const MOEOT *, const bool > - { - public: +class moeoPtrComparator : public eoBF < const MOEOT *, const MOEOT *, bool > +{ +public: /** * Ctor with a comparator * @param _cmp comparator to be employed + */ + moeoPtrComparator( moeoComparator & _cmp) : cmp(_cmp) {} - */ - moeoPtrComparator( moeoComparator & _cmp) : cmp(_cmp) {} + /** compare two const individuals */ + bool operator() (const MOEOT *ptr1, const MOEOT *ptr2) + { + return cmp(*ptr1, *ptr2); + } - /** compare two const individuals */ - const bool operator() (const MOEOT *ptr1, const MOEOT *ptr2) - { - return cmp(*ptr1, *ptr2); - } + /** compare two non const individuals */ + bool operator() (MOEOT *ptr1, MOEOT *ptr2) + { + return cmp(*ptr1, *ptr2); + } - /** compare two non const individuals */ - const bool operator() (MOEOT *ptr1, MOEOT *ptr2) - { - return cmp(*ptr1, *ptr2); - } - - private: - moeoComparator &cmp; - }; +private: + moeoComparator &cmp; +}; #endif /*MOEOPTRCOMPARATOR_H_*/ diff --git a/moeo/src/comparator/moeoStrictObjectiveVectorComparator.h b/moeo/src/comparator/moeoStrictObjectiveVectorComparator.h index 9a017690d..55863e427 100644 --- a/moeo/src/comparator/moeoStrictObjectiveVectorComparator.h +++ b/moeo/src/comparator/moeoStrictObjectiveVectorComparator.h @@ -53,7 +53,7 @@ public: * @param _objectiveVector1 the first objective vector * @param _objectiveVector2 the second objective vector */ - const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) + bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) { for (unsigned int i=0; i @param _normalizer the normalizer used for every ObjectiveVector */ moeoManhattanDistance (moeoObjectiveVectorNormalizer &_normalizer):normalizer(_normalizer) - {} + {} /** default ctr */ moeoManhattanDistance ():normalizer(defaultNormalizer) - {} + {} /** * Returns the Manhattan distance between _obj1 and _obj2 in the objective space * @param _obj1 the first objective vector * @param _obj2 the second objective vector */ - const double operator()(const ObjectiveVector & _obj1, const ObjectiveVector & _obj2) + double operator()(const ObjectiveVector & _obj1, const ObjectiveVector & _obj2) { double result = 0.0; double tmp1, tmp2; diff --git a/moeo/src/fitness/moeoDominanceDepthFitnessAssignment.h b/moeo/src/fitness/moeoDominanceDepthFitnessAssignment.h index 7d214b66c..345048c2c 100644 --- a/moeo/src/fitness/moeoDominanceDepthFitnessAssignment.h +++ b/moeo/src/fitness/moeoDominanceDepthFitnessAssignment.h @@ -151,7 +151,7 @@ class moeoDominanceDepthFitnessAssignment : public moeoDominanceBasedFitnessAssi * @param _moeo1 the first solution * @param _moeo2 the second solution */ - const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) + bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { return cmp(_moeo1.objectiveVector(), _moeo2.objectiveVector()); }