add distance
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@345 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
e9cae8bdae
commit
f2c7c06651
2 changed files with 81 additions and 81 deletions
|
|
@ -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<ObjectiveVector::nObjectives(); i++)
|
||||
{
|
||||
tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
result += (tmp1-tmp2) * (tmp1-tmp2);
|
||||
tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
result += (tmp1-tmp2) * (tmp1-tmp2);
|
||||
}
|
||||
return sqrt(result);
|
||||
}
|
||||
|
|
@ -194,24 +194,24 @@ class moeoManhattanDistance : 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 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<ObjectiveVector::nObjectives(); i++)
|
||||
{
|
||||
tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
result += fabs(tmp1-tmp2);
|
||||
tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
result += fabs(tmp1-tmp2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,58 +17,58 @@
|
|||
#include <distance/moeoDistance.h>
|
||||
|
||||
/**
|
||||
* 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; i<size(); i++)
|
||||
{
|
||||
this->operator[](i).operator[](i) = Type();
|
||||
for (unsigned j=0; j<i; j++)
|
||||
{
|
||||
this->operator[](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; i<size(); i++)
|
||||
{
|
||||
this->operator[](i).operator[](i) = Type();
|
||||
for (unsigned j=0; j<i; j++)
|
||||
{
|
||||
this->operator[](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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue