From f2c7c06651ecb71b734183039b596aa179ccc82b Mon Sep 17 00:00:00 2001 From: liefooga Date: Thu, 21 Jun 2007 14:28:32 +0000 Subject: [PATCH] add distance git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@345 331e1502-861f-0410-8da2-ba01fb791d7f --- .../src/distance/moeoDistance.h | 84 +++++++++---------- .../src/distance/moeoDistanceMatrix.h | 78 ++++++++--------- 2 files changed, 81 insertions(+), 81 deletions(-) diff --git a/branches/paradiseo-moeo-1.0/src/distance/moeoDistance.h b/branches/paradiseo-moeo-1.0/src/distance/moeoDistance.h index c15e886f8..0b55890c0 100644 --- a/branches/paradiseo-moeo-1.0/src/distance/moeoDistance.h +++ b/branches/paradiseo-moeo-1.0/src/distance/moeoDistance.h @@ -26,13 +26,13 @@ class moeoDistance : public eoBF < const MOEOT &, const MOEOT &, const Type > public: - /** - * Nothing to do - * @param _pop the population - */ + /** + * Nothing to do + * @param _pop the population + */ virtual void setup(const eoPop < MOEOT > & _pop) {} - + /** * Nothing to do * @param _min lower bound @@ -43,14 +43,14 @@ public: {} - /** - * Nothing to do - * @param _realInterval the eoRealInterval object - * @param _obj the objective index - */ + /** + * Nothing to do + * @param _realInterval the eoRealInterval object + * @param _obj the objective index + */ virtual void setup(eoRealInterval _realInterval, unsigned _obj) {} - + }; @@ -62,7 +62,7 @@ class moeoNormalizedDistance : public moeoDistance < MOEOT , Type > { public: - /** the objective vector type of the solutions */ + /** the objective vector type of the solutions */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -84,7 +84,7 @@ public: */ static double tiny() { - return 1e-6; + return 1e-6; } @@ -110,12 +110,12 @@ public: } - /** - * Sets the lower bound (_min) and the upper bound (_max) for the objective _obj - * @param _min lower bound - * @param _max upper bound - * @param _obj the objective index - */ + /** + * Sets the lower bound (_min) and the upper bound (_max) for the objective _obj + * @param _min lower bound + * @param _max upper bound + * @param _obj the objective index + */ virtual void setup(double _min, double _max, unsigned _obj) { if (_min == _max) @@ -127,11 +127,11 @@ public: } - /** - * Sets the lower bound and the upper bound for the objective _obj using a eoRealInterval object - * @param _realInterval the eoRealInterval object - * @param _obj the objective index - */ + /** + * Sets the lower bound and the upper bound for the objective _obj using a eoRealInterval object + * @param _realInterval the eoRealInterval object + * @param _obj the objective index + */ virtual void setup(eoRealInterval _realInterval, unsigned _obj) { bounds[_obj] = _realInterval; @@ -155,24 +155,24 @@ class moeoEuclideanDistance : public moeoNormalizedDistance < MOEOT > { public: - /** the objective vector type of the solutions */ + /** the objective vector type of the solutions */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; - - + + /** * Returns the euclidian distance between _moeo1 and _moeo2 in the objective space * @param _moeo1 the first solution * @param _moeo2 the second solution */ - const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) + const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - double result = 0.0; - double tmp1, tmp2; + double result = 0.0; + double tmp1, tmp2; for (unsigned i=0; i { public: - /** the objective vector type of the solutions */ + /** the objective vector type of the solutions */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; - - + + /** * Returns the Manhattan distance between _moeo1 and _moeo2 in the objective space * @param _moeo1 the first solution * @param _moeo2 the second solution */ - const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) + const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - double result = 0.0; - double tmp1, tmp2; + double result = 0.0; + double tmp1, tmp2; for (unsigned i=0; i /** - * A matrix to compute distances between every pair of individuals contained in a population. + * A matrix to compute distances between every pair of individuals contained in a population. */ template < class MOEOT , class Type > class moeoDistanceMatrix : public eoUF < const eoPop < MOEOT > &, void > , public std::vector< std::vector < Type > > { public: - using std::vector< std::vector < Type > > :: size; + using std::vector< std::vector < Type > > :: size; using std::vector< std::vector < Type > > :: operator[]; - - - /** - * Ctor - * @param _size size for every dimension of the matrix - * @param _distance the distance to use - */ - moeoDistanceMatrix (unsigned _size, moeoDistance < MOEOT , Type > & _distance) : distance(_distance) - { - this->resize(_size); - for(unsigned i=0; i<_size; i++) - { - this->operator[](i).resize(_size); - } - } - - - /** - * Sets the distance between every pair of individuals contained in the population _pop - * @param _pop the population - */ - void operator()(const eoPop < MOEOT > & _pop) + + + /** + * Ctor + * @param _size size for every dimension of the matrix + * @param _distance the distance to use + */ + moeoDistanceMatrix (unsigned _size, moeoDistance < MOEOT , Type > & _distance) : distance(_distance) { - // 1 - setup the bounds (if necessary) - distance.setup(_pop); - // 2 - compute distances - this->operator[](0).operator[](0) = Type(); - for (unsigned i=0; ioperator[](i).operator[](i) = Type(); - for (unsigned j=0; joperator[](i).operator[](j) = distance(_pop[i], _pop[j]); - this->operator[](j).operator[](i) = this->operator[](i).operator[](j); - } - } + this->resize(_size); + for (unsigned i=0; i<_size; i++) + { + this->operator[](i).resize(_size); + } + } + + + /** + * Sets the distance between every pair of individuals contained in the population _pop + * @param _pop the population + */ + void operator()(const eoPop < MOEOT > & _pop) + { + // 1 - setup the bounds (if necessary) + distance.setup(_pop); + // 2 - compute distances + this->operator[](0).operator[](0) = Type(); + for (unsigned i=0; ioperator[](i).operator[](i) = Type(); + for (unsigned j=0; joperator[](i).operator[](j) = distance(_pop[i], _pop[j]); + this->operator[](j).operator[](i) = this->operator[](i).operator[](j); + } + } } private: - /** the distance to use */ - moeoDistance < MOEOT , Type > & distance; + /** the distance to use */ + moeoDistance < MOEOT , Type > & distance; };