change 'crowding distance' to 'crowding'
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@491 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
dd93a8cdc3
commit
afa6195c6a
3 changed files with 17 additions and 17 deletions
|
|
@ -22,7 +22,7 @@
|
||||||
#include <eoPopEvalFunc.h>
|
#include <eoPopEvalFunc.h>
|
||||||
#include <eoSGAGenOp.h>
|
#include <eoSGAGenOp.h>
|
||||||
#include <algo/moeoEA.h>
|
#include <algo/moeoEA.h>
|
||||||
#include <diversity/moeoFrontByFrontCrowdingDistanceDiversityAssignment.h>
|
#include <diversity/moeoFrontByFrontCrowdingDiversityAssignment.h>
|
||||||
#include <fitness/moeoFastNonDominatedSortingFitnessAssignment.h>
|
#include <fitness/moeoFastNonDominatedSortingFitnessAssignment.h>
|
||||||
#include <replacement/moeoElitistReplacement.h>
|
#include <replacement/moeoElitistReplacement.h>
|
||||||
#include <selection/moeoDetTournamentSelect.h>
|
#include <selection/moeoDetTournamentSelect.h>
|
||||||
|
|
@ -138,7 +138,7 @@ protected:
|
||||||
/** fitness assignment used in NSGA-II */
|
/** fitness assignment used in NSGA-II */
|
||||||
moeoFastNonDominatedSortingFitnessAssignment < MOEOT > fitnessAssignment;
|
moeoFastNonDominatedSortingFitnessAssignment < MOEOT > fitnessAssignment;
|
||||||
/** diversity assignment used in NSGA-II */
|
/** diversity assignment used in NSGA-II */
|
||||||
moeoFrontByFrontCrowdingDistanceDiversityAssignment < MOEOT > diversityAssignment;
|
moeoFrontByFrontCrowdingDiversityAssignment < MOEOT > diversityAssignment;
|
||||||
/** elitist replacement */
|
/** elitist replacement */
|
||||||
moeoElitistReplacement < MOEOT > replace;
|
moeoElitistReplacement < MOEOT > replace;
|
||||||
/** an object for genetic operators (used as default) */
|
/** an object for genetic operators (used as default) */
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,122 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoCrowdingDiversityAssignment.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEOCROWDINGDIVERSITYASSIGNMENT_H_
|
||||||
|
#define MOEOCROWDINGDIVERSITYASSIGNMENT_H_
|
||||||
|
|
||||||
|
#include <eoPop.h>
|
||||||
|
#include <comparator/moeoOneObjectiveComparator.h>
|
||||||
|
#include <diversity/moeoDiversityAssignment.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diversity assignment sheme based on crowding proposed in:
|
||||||
|
* K. Deb, A. Pratap, S. Agarwal, T. Meyarivan, "A Fast and Elitist Multi-Objective Genetic Algorithm: NSGA-II", IEEE Transactions on Evolutionary Computation, vol. 6, no. 2 (2002).
|
||||||
|
*/
|
||||||
|
template < class MOEOT >
|
||||||
|
class moeoCrowdingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** the objective vector type of the solutions */
|
||||||
|
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes diversity values for every solution contained in the population _pop
|
||||||
|
* @param _pop the population
|
||||||
|
*/
|
||||||
|
void operator()(eoPop < MOEOT > & _pop)
|
||||||
|
{
|
||||||
|
if (_pop.size() <= 2)
|
||||||
|
{
|
||||||
|
for (unsigned int i=0; i<_pop.size(); i++)
|
||||||
|
{
|
||||||
|
_pop[i].diversity(inf());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setDistances(_pop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @warning NOT IMPLEMENTED, DO NOTHING !
|
||||||
|
* Updates the diversity values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
|
||||||
|
* @param _pop the population
|
||||||
|
* @param _objVec the objective vector
|
||||||
|
* @warning NOT IMPLEMENTED, DO NOTHING !
|
||||||
|
*/
|
||||||
|
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||||
|
{
|
||||||
|
std::cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the distance values
|
||||||
|
* @param _pop the population
|
||||||
|
*/
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
_pop[i].diversity(0);
|
||||||
|
}
|
||||||
|
// 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++)
|
||||||
|
{
|
||||||
|
distance = (_pop[i+1].objectiveVector()[obj] - _pop[i-1].objectiveVector()[obj]) / (max-min);
|
||||||
|
_pop[i].diversity(_pop[i].diversity() + distance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*MOEOCROWDINGDIVERSITYASSIGNMENT_H_*/
|
||||||
|
|
@ -0,0 +1,133 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoFrontByFrontCrowdingDiversityAssignment.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEOFRONTBYFRONTCROWDINGDIVERSITYASSIGNMENT_H_
|
||||||
|
#define MOEOFRONTBYFRONTCROWDINGDIVERSITYASSIGNMENT_H_
|
||||||
|
|
||||||
|
#include <diversity/moeoCrowdingDiversityAssignment.h>
|
||||||
|
#include <comparator/moeoFitnessThenDiversityComparator.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diversity assignment sheme based on crowding proposed in:
|
||||||
|
* K. Deb, A. Pratap, S. Agarwal, T. Meyarivan, "A Fast and Elitist Multi-Objective Genetic Algorithm: NSGA-II", IEEE Transactions on Evolutionary Computation, vol. 6, no. 2 (2002).
|
||||||
|
* Tis strategy assigns diversity values FRONT BY FRONT. It is, for instance, used in NSGA-II.
|
||||||
|
*/
|
||||||
|
template < class MOEOT >
|
||||||
|
class moeoFrontByFrontCrowdingDiversityAssignment : public moeoCrowdingDiversityAssignment < MOEOT >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** the objective vector type of the solutions */
|
||||||
|
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @warning NOT IMPLEMENTED, DO NOTHING !
|
||||||
|
* Updates the diversity values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
|
||||||
|
* @param _pop the population
|
||||||
|
* @param _objVec the objective vector
|
||||||
|
* @warning NOT IMPLEMENTED, DO NOTHING !
|
||||||
|
*/
|
||||||
|
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||||
|
{
|
||||||
|
std::cout << "WARNING : updateByDeleting not implemented in moeoFrontByFrontCrowdingDistanceDiversityAssignment" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
using moeoCrowdingDiversityAssignment < MOEOT >::inf;
|
||||||
|
using moeoCrowdingDiversityAssignment < MOEOT >::tiny;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the distance values
|
||||||
|
* @param _pop the population
|
||||||
|
*/
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
_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())
|
||||||
|
{
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
_pop[i].diversity(inf());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// else...
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the index of the last individual having the same fitness value than _pop[_start]
|
||||||
|
* @param _pop the population
|
||||||
|
* @param _start the index to start from
|
||||||
|
*/
|
||||||
|
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()) )
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*MOEOFRONTBYFRONTCROWDINGDIVERSITYASSIGNMENT_H_*/
|
||||||
Loading…
Reference in a new issue