Migration from SVN
This commit is contained in:
parent
d7d6c3a217
commit
8cd56f37db
29069 changed files with 0 additions and 4096888 deletions
147
moeo/src/diversity/moeoCrowdingDiversityAssignment.h
Normal file
147
moeo/src/diversity/moeoCrowdingDiversityAssignment.h
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* <moeoCrowdingDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
*
|
||||
* Arnaud Liefooghe
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.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.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_*/
|
||||
76
moeo/src/diversity/moeoDiversityAssignment.h
Normal file
76
moeo/src/diversity/moeoDiversityAssignment.h
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* <moeoDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
*
|
||||
* Arnaud Liefooghe
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEODIVERSITYASSIGNMENT_H_
|
||||
#define MOEODIVERSITYASSIGNMENT_H_
|
||||
|
||||
#include <eoFunctor.h>
|
||||
#include <eoPop.h>
|
||||
|
||||
/**
|
||||
* Functor that sets the diversity values of a whole population.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoDiversityAssignment : public eoUF < eoPop < MOEOT > &, void >
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type for objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
virtual void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Updates the diversity values of the whole population _pop by taking the deletion of the individual _moeo into account.
|
||||
* @param _pop the population
|
||||
* @param _moeo the individual
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo)
|
||||
{
|
||||
updateByDeleting(_pop, _moeo.objectiveVector());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEODIVERSITYASSIGNMENT_H_*/
|
||||
84
moeo/src/diversity/moeoDummyDiversityAssignment.h
Normal file
84
moeo/src/diversity/moeoDummyDiversityAssignment.h
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* <moeoDummyDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
*
|
||||
* Arnaud Liefooghe
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEODUMMYDIVERSITYASSIGNMENT_H_
|
||||
#define MOEODUMMYDIVERSITYASSIGNMENT_H_
|
||||
|
||||
#include<diversity/moeoDiversityAssignment.h>
|
||||
|
||||
/**
|
||||
* moeoDummyDiversityAssignment is a moeoDiversityAssignment that gives the value '0' as the individual's diversity for a whole population if it is invalid.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoDummyDiversityAssignment : public moeoDiversityAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type for objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the diversity to '0' for every individuals of the population _pop if it is invalid
|
||||
* @param _pop the population
|
||||
*/
|
||||
void operator () (eoPop < MOEOT > & _pop)
|
||||
{
|
||||
for (unsigned int idx = 0; idx<_pop.size (); idx++)
|
||||
{
|
||||
if (_pop[idx].invalidDiversity())
|
||||
{
|
||||
// set the diversity to 0
|
||||
_pop[idx].diversity(0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
// nothing to do... ;-)
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEODUMMYDIVERSITYASSIGNMENT_H_*/
|
||||
175
moeo/src/diversity/moeoFrontByFrontCrowdingDiversityAssignment.h
Normal file
175
moeo/src/diversity/moeoFrontByFrontCrowdingDiversityAssignment.h
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* <moeoFrontByFrontCrowdingDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2009
|
||||
* (C) OPAC Team, LIFL, 2002-2009
|
||||
*
|
||||
* Arnaud Liefooghe, Waldo Cancino
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOFRONTBYFRONTCROWDINGDIVERSITYASSIGNMENT2_H_
|
||||
#define MOEOFRONTBYFRONTCROWDINGDIVERSITYASSIGNMENT2_H_
|
||||
|
||||
#include <diversity/moeoCrowdingDiversityAssignment.h>
|
||||
#include <comparator/moeoFitnessThenDiversityComparator.h>
|
||||
#include <comparator/moeoPtrComparator.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::vector<MOEOT *> sortedptrpop;
|
||||
sortedptrpop.resize(_pop.size());
|
||||
// due to intensive sort operations for this diversity assignment,
|
||||
// it is more efficient to perform sorts using only pointers to the
|
||||
// population members in order to avoid copy of individuals
|
||||
for(unsigned int i=0; i< _pop.size(); i++) sortedptrpop[i] = & (_pop[i]);
|
||||
//sort the pointers to population members
|
||||
moeoPtrComparator<MOEOT> cmp2( fitnessComparator);
|
||||
std::sort(sortedptrpop.begin(), sortedptrpop.end(), cmp2);
|
||||
// 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(sortedptrpop,a); // the front ends at b
|
||||
//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++)
|
||||
{
|
||||
sortedptrpop[i]->diversity(inf());
|
||||
//_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);
|
||||
moeoPtrComparator<MOEOT> cmp2( objComp );
|
||||
std::sort(sortedptrpop.begin(), sortedptrpop.end(), cmp2);
|
||||
// min & max
|
||||
min = (sortedptrpop[b])->objectiveVector()[obj];
|
||||
max = (sortedptrpop[a])->objectiveVector()[obj];
|
||||
|
||||
// avoid extreme case
|
||||
if (min == max)
|
||||
{
|
||||
min -= tiny();
|
||||
max += tiny();
|
||||
}
|
||||
// set the diversity value to infiny for min and max
|
||||
sortedptrpop[a]->diversity(inf());
|
||||
sortedptrpop[b]->diversity(inf());
|
||||
// set the diversity values for the other individuals
|
||||
for (unsigned int i=a+1; i<b; i++)
|
||||
{
|
||||
distance = ( sortedptrpop[i-1]->objectiveVector()[obj] - sortedptrpop[i+1]->objectiveVector()[obj] ) / (max-min);
|
||||
sortedptrpop[i]->diversity(sortedptrpop[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 vector of pointers to population individuals
|
||||
* @param _start the index to start from
|
||||
*/
|
||||
|
||||
unsigned int lastIndex (std::vector<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_*/
|
||||
130
moeo/src/diversity/moeoFrontByFrontSharingDiversityAssignment.h
Normal file
130
moeo/src/diversity/moeoFrontByFrontSharingDiversityAssignment.h
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* <moeoFrontByFrontSharingDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
*
|
||||
* Arnaud Liefooghe
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOFRONTBYFRONTSHARINGDIVERSITYASSIGNMENT_H_
|
||||
#define MOEOFRONTBYFRONTSHARINGDIVERSITYASSIGNMENT_H_
|
||||
|
||||
#include <diversity/moeoSharingDiversityAssignment.h>
|
||||
|
||||
/**
|
||||
* Sharing assignment scheme on the way it is used in NSGA.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoFrontByFrontSharingDiversityAssignment : public moeoSharingDiversityAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
|
||||
/** the objective vector type of the solutions */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
* @param _distance the distance used to compute the neighborhood of solutions (can be related to the decision space or the objective space)
|
||||
* @param _nicheSize neighborhood size in terms of radius distance (closely related to the way the distances are computed)
|
||||
* @param _alpha parameter used to regulate the shape of the sharing function
|
||||
*/
|
||||
moeoFrontByFrontSharingDiversityAssignment(moeoDistance<MOEOT,double> & _distance, double _nicheSize = 0.5, double _alpha = 2.0) : moeoSharingDiversityAssignment < MOEOT >(_distance, _nicheSize, _alpha)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Ctor with an euclidean distance (with normalized objective values) in the objective space is used as default
|
||||
* @param _nicheSize neighborhood size in terms of radius distance (closely related to the way the distances are computed)
|
||||
* @param _alpha parameter used to regulate the shape of the sharing function
|
||||
*/
|
||||
moeoFrontByFrontSharingDiversityAssignment(double _nicheSize = 0.5, double _alpha = 2.0) : moeoSharingDiversityAssignment < MOEOT >(_nicheSize, _alpha)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* @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 moeoSharingDiversityAssignment" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
using moeoSharingDiversityAssignment < MOEOT >::distance;
|
||||
using moeoSharingDiversityAssignment < MOEOT >::nicheSize;
|
||||
using moeoSharingDiversityAssignment < MOEOT >::sh;
|
||||
|
||||
|
||||
/**
|
||||
* Sets similarities FRONT BY FRONT for every solution contained in the population _pop
|
||||
* @param _pop the population
|
||||
*/
|
||||
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++)
|
||||
{
|
||||
for (unsigned int j=0; j<i; j++)
|
||||
{
|
||||
if (_pop[i].fitness() != _pop[j].fitness())
|
||||
{
|
||||
dMatrix[i][j] = nicheSize;
|
||||
dMatrix[j][i] = nicheSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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 += sh(dMatrix[i][j]);
|
||||
}
|
||||
_pop[i].diversity(sum);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOFRONTBYFRONTSHARINGDIVERSITYASSIGNMENT_H_*/
|
||||
173
moeo/src/diversity/moeoNearestNeighborDiversityAssignment.h
Normal file
173
moeo/src/diversity/moeoNearestNeighborDiversityAssignment.h
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* <moeoNearestNeighborDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008
|
||||
* (C) OPAC Team, LIFL, 2002-2008
|
||||
*
|
||||
* Arnaud Liefooghe
|
||||
* Jeremie Humeau
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoNearestNeighborDiversityAssignment.h
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef MOEONEARESTNEIGHBORDIVERSITYASSIGNMENT_H_
|
||||
#define MOEONEARESTNEIGHBORDIVERSITYASSIGNMENT_H_
|
||||
|
||||
#include <list>
|
||||
#include <diversity/moeoDiversityAssignment.h>
|
||||
#include <archive/moeoUnboundedArchive.h>
|
||||
#include <archive/moeoArchive.h>
|
||||
|
||||
/**
|
||||
* moeoNearestNeighborDiversityAssignment is a moeoDiversityAssignment using distance between individuals to assign diversity.
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoNearestNeighborDiversityAssignment : public moeoDiversityAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
|
||||
/** The type for objective vector */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
||||
|
||||
/**
|
||||
* Default ctor
|
||||
* @param _index index for find the k-ieme nearest neighbor, _index correspond to k
|
||||
*/
|
||||
moeoNearestNeighborDiversityAssignment(unsigned int _index=1):distance(defaultDistance), archive(defaultArchive), index(_index)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Ctor where you can choose your own archive
|
||||
* @param _archive the archive used
|
||||
* @param _index index for find the k-ieme nearest neighbor, _index correspond to k
|
||||
*/
|
||||
moeoNearestNeighborDiversityAssignment(moeoArchive <MOEOT>& _archive, unsigned int _index=1) : distance(defaultDistance), archive(_archive), index(_index)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Ctor where you can choose your own distance
|
||||
* @param _dist the distance used
|
||||
* @param _index index for find the k-ieme nearest neighbor, _index correspond to k
|
||||
*/
|
||||
moeoNearestNeighborDiversityAssignment(moeoDistance <MOEOT, double>& _dist, unsigned int _index=1) : distance(_dist), archive(defaultArchive), index(_index)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Ctor where you can choose your own distance and archive
|
||||
* @param _dist the distance used
|
||||
* @param _archive the archive used
|
||||
* @param _index index for find the k-ieme nearest neighbor, _index correspond to k
|
||||
*/
|
||||
moeoNearestNeighborDiversityAssignment(moeoDistance <MOEOT, double>& _dist, moeoArchive <MOEOT>& _archive, unsigned int _index=1) : distance(_dist), archive(_archive), index(_index)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Affect the diversity to the pop, diversity corresponding to the k-ieme nearest neighbor.
|
||||
* @param _pop the population
|
||||
*/
|
||||
void operator () (eoPop < MOEOT > & _pop)
|
||||
{
|
||||
unsigned int i = _pop.size();
|
||||
unsigned int j = archive.size();
|
||||
double tmp=0;
|
||||
std::vector< std::list<double> > matrice(i+j);
|
||||
if (i+j>0)
|
||||
{
|
||||
for (unsigned k=0; k<i+j-1; k++)
|
||||
{
|
||||
for (unsigned l=k+1; l<i+j; l++)
|
||||
{
|
||||
if ( (k<i) && (l<i) )
|
||||
tmp=distance(_pop[k], _pop[l]);
|
||||
else if ( (k<i) && (l>=i) )
|
||||
tmp=distance(_pop[k], archive[l-i]);
|
||||
else
|
||||
tmp=distance(archive[k-i], archive[l-i]);
|
||||
matrice[k].push_back(tmp);
|
||||
matrice[l].push_back(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (unsigned int k=0; k<i+j; k++)
|
||||
matrice[k].sort();
|
||||
for (unsigned int k=0; k<i; k++)
|
||||
_pop[k].diversity(-1 * 1/(2+getElement(matrice[k])));
|
||||
for (unsigned int k=i; k<i+j; k++)
|
||||
archive[k-i].diversity(-1 * 1/(2+getElement(matrice[k])));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @warning NOT IMPLEMENTED, DOES 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, DOES NOTHING !
|
||||
*/
|
||||
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
|
||||
{
|
||||
std::cout << "WARNING : updateByDeleting not implemented in moeoNearestNeighborDiversityAssignment" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** Distance */
|
||||
moeoDistance <MOEOT, double> & distance;
|
||||
/** Default distance */
|
||||
moeoEuclideanDistance < MOEOT > defaultDistance;
|
||||
/** Archive */
|
||||
moeoArchive < MOEOT > & archive;
|
||||
/** Default archive */
|
||||
moeoUnboundedArchive < MOEOT > defaultArchive;
|
||||
/** the index corresponding to k for search the k-ieme nearest neighbor */
|
||||
unsigned int index;
|
||||
|
||||
|
||||
/**
|
||||
* Return the index-th element of the list _myList
|
||||
* @param _myList the list which contains distances
|
||||
*/
|
||||
double getElement(std::list<double> _myList)
|
||||
{
|
||||
std::list<double>::iterator it= _myList.begin();
|
||||
for (unsigned int i=1; i< std::min((unsigned int)_myList.size(),index); i++)
|
||||
it++;
|
||||
return *it;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEONEARESTNEIGHBORDIVERSITYASSIGNEMENT_H_*/
|
||||
167
moeo/src/diversity/moeoSharingDiversityAssignment.h
Normal file
167
moeo/src/diversity/moeoSharingDiversityAssignment.h
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* <moeoSharingDiversityAssignment.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
*
|
||||
* Arnaud Liefooghe
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOSHARINGDIVERSITYASSIGNMENT_H_
|
||||
#define MOEOSHARINGDIVERSITYASSIGNMENT_H_
|
||||
|
||||
#include <eoPop.h>
|
||||
#include <comparator/moeoDiversityThenFitnessComparator.h>
|
||||
#include <distance/moeoDistance.h>
|
||||
#include <distance/moeoDistanceMatrix.h>
|
||||
#include <distance/moeoEuclideanDistance.h>
|
||||
#include <diversity/moeoDiversityAssignment.h>
|
||||
|
||||
/**
|
||||
* Sharing assignment scheme originally porposed by:
|
||||
* D. E. Goldberg, "Genetic Algorithms in Search, Optimization and Machine Learning", Addision-Wesley, MA, USA (1989).
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoSharingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
|
||||
{
|
||||
public:
|
||||
|
||||
/** the objective vector type of the solutions */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
* @param _distance the distance used to compute the neighborhood of solutions (can be related to the decision space or the objective space)
|
||||
* @param _nicheSize neighborhood size in terms of radius distance (closely related to the way the distances are computed)
|
||||
* @param _alpha parameter used to regulate the shape of the sharing function
|
||||
*/
|
||||
moeoSharingDiversityAssignment(moeoDistance<MOEOT,double> & _distance, double _nicheSize = 0.5, double _alpha = 1.0) : distance(_distance), nicheSize(_nicheSize), alpha(_alpha)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Ctor with an euclidean distance (with normalized objective values) in the objective space is used as default
|
||||
* @param _nicheSize neighborhood size in terms of radius distance (closely related to the way the distances are computed)
|
||||
* @param _alpha parameter used to regulate the shape of the sharing function
|
||||
*/
|
||||
moeoSharingDiversityAssignment(double _nicheSize = 0.5, double _alpha = 1.0) : distance(defaultDistance), nicheSize(_nicheSize), alpha(_alpha)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Sets diversity values for every solution contained in the population _pop
|
||||
* @param _pop the population
|
||||
*/
|
||||
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++)
|
||||
{
|
||||
_pop[i].diversity(max - _pop[i].diversity());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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 moeoSharingDiversityAssignment" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** the distance used to compute the neighborhood of solutions */
|
||||
moeoDistance < MOEOT , double > & distance;
|
||||
/** euclidean distancein the objective space (can be used as default) */
|
||||
moeoEuclideanDistance < MOEOT > defaultDistance;
|
||||
/** neighborhood size in terms of radius distance */
|
||||
double nicheSize;
|
||||
/** parameter used to regulate the shape of the sharing function */
|
||||
double alpha;
|
||||
|
||||
|
||||
/**
|
||||
* Sets similarities for every solution contained in the population _pop
|
||||
* @param _pop the population
|
||||
*/
|
||||
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++)
|
||||
{
|
||||
sum = 0.0;
|
||||
for (unsigned int j=0; j<_pop.size(); j++)
|
||||
{
|
||||
sum += sh(dMatrix[i][j]);
|
||||
}
|
||||
_pop[i].diversity(sum);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sharing function
|
||||
* @param _dist the distance value
|
||||
*/
|
||||
double sh(double _dist)
|
||||
{
|
||||
double result;
|
||||
if (_dist < nicheSize)
|
||||
{
|
||||
result = 1.0 - pow(_dist / nicheSize, alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0.0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /*MOEOSHARINGDIVERSITYASSIGNMENT_H_*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue