New style for MOEO

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@788 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
canape 2007-11-16 11:29:25 +00:00
commit 39709d3d12
103 changed files with 2607 additions and 2521 deletions

View file

@ -1,4 +1,4 @@
/*
/*
* <moeoCrowdingDiversityAssignment.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -48,8 +48,8 @@
*/
template < class MOEOT >
class moeoCrowdingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{
public:
{
public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -59,18 +59,18 @@ public:
* Returns a big value (regarded as infinite)
*/
double inf() const
{
{
return std::numeric_limits<double>::max();
}
}
/**
* Returns a very small value that can be used to avoid extreme cases (where the min bound == the max bound)
*/
double tiny() const
{
{
return 1e-6;
}
}
/**
@ -79,16 +79,16 @@ public:
*/
void operator()(eoPop < MOEOT > & _pop)
{
if (_pop.size() <= 2)
if (_pop.size() <= 2)
{
for (unsigned int i=0; i<_pop.size(); i++)
for (unsigned int i=0; i<_pop.size(); i++)
{
_pop[i].diversity(inf());
_pop[i].diversity(inf());
}
}
else
else
{
setDistances(_pop);
setDistances(_pop);
}
}
@ -102,11 +102,11 @@ public:
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
std::cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << std::endl;
std::cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << std::endl;
}
protected:
protected:
/**
* Sets the distance values
@ -114,34 +114,34 @@ protected:
*/
virtual void setDistances (eoPop < MOEOT > & _pop)
{
double min, max, distance;
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
// set diversity to 0
for (unsigned int i=0; i<_pop.size(); i++)
double min, max, distance;
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
// set diversity to 0
for (unsigned int i=0; i<_pop.size(); i++)
{
_pop[i].diversity(0);
_pop[i].diversity(0);
}
// for each objective
for (unsigned int obj=0; obj<nObjectives; obj++)
// for each objective
for (unsigned int obj=0; obj<nObjectives; obj++)
{
// comparator
moeoOneObjectiveComparator < MOEOT > objComp(obj);
// sort
std::sort(_pop.begin(), _pop.end(), objComp);
// min & max
min = _pop[0].objectiveVector()[obj];
max = _pop[_pop.size()-1].objectiveVector()[obj];
// set the diversity value to infiny for min and max
_pop[0].diversity(inf());
_pop[_pop.size()-1].diversity(inf());
for (unsigned int i=1; i<_pop.size()-1; i++)
// comparator
moeoOneObjectiveComparator < MOEOT > objComp(obj);
// sort
std::sort(_pop.begin(), _pop.end(), objComp);
// min & max
min = _pop[0].objectiveVector()[obj];
max = _pop[_pop.size()-1].objectiveVector()[obj];
// set the diversity value to infiny for min and max
_pop[0].diversity(inf());
_pop[_pop.size()-1].diversity(inf());
for (unsigned int i=1; i<_pop.size()-1; i++)
{
distance = (_pop[i+1].objectiveVector()[obj] - _pop[i-1].objectiveVector()[obj]) / (max-min);
_pop[i].diversity(_pop[i].diversity() + distance);
distance = (_pop[i+1].objectiveVector()[obj] - _pop[i-1].objectiveVector()[obj]) / (max-min);
_pop[i].diversity(_pop[i].diversity() + distance);
}
}
}
};
};
#endif /*MOEOCROWDINGDIVERSITYASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <moeoDiversityAssignment.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -46,8 +46,8 @@
*/
template < class MOEOT >
class moeoDiversityAssignment : public eoUF < eoPop < MOEOT > &, void >
{
public:
{
public:
/** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -68,9 +68,9 @@ public:
*/
void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo)
{
updateByDeleting(_pop, _moeo.objectiveVector());
updateByDeleting(_pop, _moeo.objectiveVector());
}
};
};
#endif /*MOEODIVERSITYASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <moeoDummyDiversityAssignment.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -45,8 +45,8 @@
*/
template < class MOEOT >
class moeoDummyDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{
public:
{
public:
/** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -58,12 +58,12 @@ public:
*/
void operator () (eoPop < MOEOT > & _pop)
{
for (unsigned int idx = 0; idx<_pop.size (); idx++)
for (unsigned int idx = 0; idx<_pop.size (); idx++)
{
if (_pop[idx].invalidDiversity())
if (_pop[idx].invalidDiversity())
{
// set the diversity to 0
_pop[idx].diversity(0.0);
// set the diversity to 0
_pop[idx].diversity(0.0);
}
}
}
@ -76,9 +76,9 @@ public:
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
// nothing to do... ;-)
// nothing to do... ;-)
}
};
};
#endif /*MOEODUMMYDIVERSITYASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <moeoFrontByFrontCrowdingDiversityAssignment.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -48,8 +48,8 @@
*/
template < class MOEOT >
class moeoFrontByFrontCrowdingDiversityAssignment : public moeoCrowdingDiversityAssignment < MOEOT >
{
public:
{
public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -64,11 +64,11 @@ public:
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
std::cout << "WARNING : updateByDeleting not implemented in moeoFrontByFrontCrowdingDistanceDiversityAssignment" << std::endl;
std::cout << "WARNING : updateByDeleting not implemented in moeoFrontByFrontCrowdingDistanceDiversityAssignment" << std::endl;
}
private:
private:
using moeoCrowdingDiversityAssignment < MOEOT >::inf;
using moeoCrowdingDiversityAssignment < MOEOT >::tiny;
@ -79,61 +79,61 @@ private:
*/
void setDistances (eoPop < MOEOT > & _pop)
{
unsigned int a,b;
double min, max, distance;
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
// set diversity to 0 for every individual
for (unsigned int i=0; i<_pop.size(); i++)
unsigned int a,b;
double min, max, distance;
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
// set diversity to 0 for every individual
for (unsigned int i=0; i<_pop.size(); i++)
{
_pop[i].diversity(0.0);
_pop[i].diversity(0.0);
}
// sort the whole pop according to fitness values
moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator;
std::sort(_pop.begin(), _pop.end(), fitnessComparator);
// compute the crowding distance values for every individual "front" by "front" (front : from a to b)
a = 0; // the front starts at a
while (a < _pop.size())
// sort the whole pop according to fitness values
moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator;
std::sort(_pop.begin(), _pop.end(), fitnessComparator);
// compute the crowding distance values for every individual "front" by "front" (front : from a to b)
a = 0; // the front starts at a
while (a < _pop.size())
{
b = lastIndex(_pop,a); // the front ends at b
// if there is less than 2 individuals in the front...
if ((b-a) < 2)
b = lastIndex(_pop,a); // the front ends at b
// if there is less than 2 individuals in the front...
if ((b-a) < 2)
{
for (unsigned int i=a; i<=b; i++)
for (unsigned int i=a; i<=b; i++)
{
_pop[i].diversity(inf());
_pop[i].diversity(inf());
}
}
// else...
else
// else...
else
{
// for each objective
for (unsigned int obj=0; obj<nObjectives; obj++)
// for each objective
for (unsigned int obj=0; obj<nObjectives; obj++)
{
// sort in the descending order using the values of the objective 'obj'
moeoOneObjectiveComparator < MOEOT > objComp(obj);
std::sort(_pop.begin()+a, _pop.begin()+b+1, objComp);
// min & max
min = _pop[b].objectiveVector()[obj];
max = _pop[a].objectiveVector()[obj];
// avoid extreme case
if (min == max)
// sort in the descending order using the values of the objective 'obj'
moeoOneObjectiveComparator < MOEOT > objComp(obj);
std::sort(_pop.begin()+a, _pop.begin()+b+1, objComp);
// min & max
min = _pop[b].objectiveVector()[obj];
max = _pop[a].objectiveVector()[obj];
// avoid extreme case
if (min == max)
{
min -= tiny();
max += tiny();
min -= tiny();
max += tiny();
}
// set the diversity value to infiny for min and max
_pop[a].diversity(inf());
_pop[b].diversity(inf());
// set the diversity values for the other individuals
for (unsigned int i=a+1; i<b; i++)
// set the diversity value to infiny for min and max
_pop[a].diversity(inf());
_pop[b].diversity(inf());
// set the diversity values for the other individuals
for (unsigned int i=a+1; i<b; i++)
{
distance = (_pop[i-1].objectiveVector()[obj] - _pop[i+1].objectiveVector()[obj]) / (max-min);
_pop[i].diversity(_pop[i].diversity() + distance);
distance = (_pop[i-1].objectiveVector()[obj] - _pop[i+1].objectiveVector()[obj]) / (max-min);
_pop[i].diversity(_pop[i].diversity() + distance);
}
}
}
// go to the next front
a = b+1;
// go to the next front
a = b+1;
}
}
@ -145,14 +145,14 @@ private:
*/
unsigned int lastIndex (eoPop < MOEOT > & _pop, unsigned int _start)
{
unsigned int i=_start;
while ( (i<_pop.size()-1) && (_pop[i].fitness()==_pop[i+1].fitness()) )
unsigned int i=_start;
while ( (i<_pop.size()-1) && (_pop[i].fitness()==_pop[i+1].fitness()) )
{
i++;
i++;
}
return i;
return i;
}
};
};
#endif /*MOEOFRONTBYFRONTCROWDINGDIVERSITYASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <moeoFrontByFrontSharingDiversityAssignment.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -45,8 +45,8 @@
*/
template < class MOEOT >
class moeoFrontByFrontSharingDiversityAssignment : public moeoSharingDiversityAssignment < MOEOT >
{
public:
{
public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -80,11 +80,11 @@ public:
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl;
std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl;
}
private:
private:
using moeoSharingDiversityAssignment < MOEOT >::distance;
using moeoSharingDiversityAssignment < MOEOT >::nicheSize;
@ -98,34 +98,34 @@ private:
*/
void setSimilarities(eoPop < MOEOT > & _pop)
{
// compute distances between every individuals
moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
dMatrix(_pop);
// sets the distance to bigger than the niche size for every couple of solutions that do not belong to the same front
for (unsigned int i=0; i<_pop.size(); i++)
// compute distances between every individuals
moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
dMatrix(_pop);
// sets the distance to bigger than the niche size for every couple of solutions that do not belong to the same front
for (unsigned int i=0; i<_pop.size(); i++)
{
for (unsigned int j=0; j<i; j++)
for (unsigned int j=0; j<i; j++)
{
if (_pop[i].fitness() != _pop[j].fitness())
if (_pop[i].fitness() != _pop[j].fitness())
{
dMatrix[i][j] = nicheSize;
dMatrix[j][i] = nicheSize;
dMatrix[i][j] = nicheSize;
dMatrix[j][i] = nicheSize;
}
}
}
// compute similarities
double sum;
for (unsigned int i=0; i<_pop.size(); i++)
// compute similarities
double sum;
for (unsigned int i=0; i<_pop.size(); i++)
{
sum = 0.0;
for (unsigned int j=0; j<_pop.size(); j++)
sum = 0.0;
for (unsigned int j=0; j<_pop.size(); j++)
{
sum += sh(dMatrix[i][j]);
sum += sh(dMatrix[i][j]);
}
_pop[i].diversity(sum);
_pop[i].diversity(sum);
}
}
};
};
#endif /*MOEOFRONTBYFRONTSHARINGDIVERSITYASSIGNMENT_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <moeoSharingDiversityAssignment.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -51,8 +51,8 @@
*/
template < class MOEOT >
class moeoSharingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{
public:
{
public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -83,14 +83,14 @@ public:
*/
void operator()(eoPop < MOEOT > & _pop)
{
// 1 - set simuilarities
setSimilarities(_pop);
// 2 - a higher diversity is better, so the values need to be inverted
moeoDiversityThenFitnessComparator < MOEOT > divComparator;
double max = std::max_element(_pop.begin(), _pop.end(), divComparator)->diversity();
for (unsigned int i=0 ; i<_pop.size() ; i++)
// 1 - set simuilarities
setSimilarities(_pop);
// 2 - a higher diversity is better, so the values need to be inverted
moeoDiversityThenFitnessComparator < MOEOT > divComparator;
double max = std::max_element(_pop.begin(), _pop.end(), divComparator)->diversity();
for (unsigned int i=0 ; i<_pop.size() ; i++)
{
_pop[i].diversity(max - _pop[i].diversity());
_pop[i].diversity(max - _pop[i].diversity());
}
}
@ -104,11 +104,11 @@ public:
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl;
std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl;
}
protected:
protected:
/** the distance used to compute the neighborhood of solutions */
moeoDistance < MOEOT , double > & distance;
@ -126,19 +126,19 @@ protected:
*/
virtual void setSimilarities(eoPop < MOEOT > & _pop)
{
// compute distances between every individuals
moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
dMatrix(_pop);
// compute similarities
double sum;
for (unsigned int i=0; i<_pop.size(); i++)
// compute distances between every individuals
moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
dMatrix(_pop);
// compute similarities
double sum;
for (unsigned int i=0; i<_pop.size(); i++)
{
sum = 0.0;
for (unsigned int j=0; j<_pop.size(); j++)
sum = 0.0;
for (unsigned int j=0; j<_pop.size(); j++)
{
sum += sh(dMatrix[i][j]);
sum += sh(dMatrix[i][j]);
}
_pop[i].diversity(sum);
_pop[i].diversity(sum);
}
}
@ -149,19 +149,19 @@ protected:
*/
double sh(double _dist)
{
double result;
if (_dist < nicheSize)
double result;
if (_dist < nicheSize)
{
result = 1.0 - pow(_dist / nicheSize, alpha);
result = 1.0 - pow(_dist / nicheSize, alpha);
}
else
else
{
result = 0.0;
result = 0.0;
}
return result;
return result;
}
};
};
#endif /*MOEOSHARINGDIVERSITYASSIGNMENT_H_*/