Migration from SVN

This commit is contained in:
quemy 2012-08-30 11:30:11 +02:00
commit 8cd56f37db
29069 changed files with 0 additions and 4096888 deletions

View file

@ -0,0 +1,445 @@
// j'ai installé le svn :)
// re-test
/*
* <moeo2DMinHypervolumeArchive.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Arnaud Liefooghe
* Jérémie 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
*
*/
//-----------------------------------------------------------------------------
#ifndef MOEO2DMINHYPERVOLUMEARCHIVE_H_
#define MOEO2DMINHYPERVOLUMEARCHIVE_H_
#include <set>
#include <climits>
template < class MOEOT >
struct comp
{
// returns a "before" b
// all objectives = min
bool operator() (const MOEOT & a, const MOEOT & b)
{
return ((a.objectiveVector()[1] < b.objectiveVector()[1]) || ((a.objectiveVector()[1] == b.objectiveVector()[1]) && (a.objectiveVector()[0] < b.objectiveVector()[0])));
}
};
/** 2D (minimization) bounded archive by hypervolume , base on a set */
template < class MOEOT >
class moeo2DMinHypervolumeArchive : public std::set<MOEOT , comp < MOEOT > >
{
public:
typedef typename MOEOT::Fitness Fitness;
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
typedef typename std::set < MOEOT, comp<MOEOT> >::iterator Iterator;
using std::set < MOEOT, comp<MOEOT> > :: begin;
using std::set < MOEOT, comp<MOEOT> > :: end;
using std::set < MOEOT, comp<MOEOT> > :: insert;
using std::set < MOEOT, comp<MOEOT> > :: erase;
using std::set < MOEOT, comp<MOEOT> > :: size;
using std::set < MOEOT, comp<MOEOT> > :: upper_bound;
/**
* Ctr.
* @param _maxSize size of the archive (must be >= 2)
* @param _maxValue fitness assigned to the first and the last solution in the archive (default LONG_MAX)
*/
moeo2DMinHypervolumeArchive(unsigned int _maxSize=100, double _maxValue=LONG_MAX) : std::set < MOEOT, comp<MOEOT> > (), maxSize(_maxSize), maxValue(_maxValue)
{
maxSize = std::max((unsigned int) 2, maxSize);
}
/**
* Update the archive with a solution
* @param _moeo a solution
* @return true if _moeo has been added to the archive
*/
bool operator()(const MOEOT & _moeo)
{
//store result
bool result;
Iterator it;
//If archive is empty -> add the sol and affect its fitness value
if (size()==0)
{
result = true;
insert(_moeo);
it=begin();
fitness(it, maxValue);
}
else // test if sol can be added to the archive
{
result = insert(_moeo.objectiveVector());
if (result)
{
if(size() < maxSize)
{
// if yes, insert it and recompute fitness value of MOEOT and its neighbors
insert(hint, _moeo);
if(size() > 2)
{
//general case
hint--;
computeFitness(hint);
}
else
{
//archive size <= 2, fitness=maxValue for each sol
it=begin();
while(it!=end())
{
fitness(it, maxValue);
it++;
}
}
}
else
{
result = filter(_moeo);
}
}
}
return result;
}
/**
* update the archive with a population
* @param _pop a pop
* @return true if at least one solution of _pop has been added to the archive
*/
bool operator()(const eoPop < MOEOT > & _pop)
{
bool result = false;
bool tmp = false;
for (unsigned int i=0; i<_pop.size(); i++)
{
std::cout << "insert " << _pop[i].objectiveVector()[0] << ", " << _pop[i].objectiveVector()[1] << std::endl;
tmp = (*this)(_pop[i]);
result = tmp || result;
}
return result;
}
/**
* Test if insertion wrt Pareto-dominance is possible, and fix 'hint' if possible
* @param _objVec the objective vector of the sol to insert
* @return true if objVec can be added to the archive wrt Pareto-dominance
*/
bool insert(const ObjectiveVector & _objVec)
{
bool result = false;
Iterator it;
double min;
// set the objVec to the empty solution
empty.objectiveVector(_objVec);
// compute the position where it would possibly be added
it = upper_bound(empty);
// compute the weigth from the previous solution
min = begin()->objectiveVector()[0];
if (it != begin())
{
it--;
min = (*it).objectiveVector()[0];
it++;
}
// if it has a better weitgh, or if it's an extreme sol, let's add it
if (it == begin() || _objVec[0]<min)
{
// remove dominated solutions
remove(it,_objVec);
// set hint to the current iterator (probably modified by "remove")
hint=it;
// set result to true
result = true;
}
return result;
}
/**
* print objective vector and fitness value of the archive
*/
void print()
{
Iterator it = begin();
while(it!=end())
{
std::cout << (*it).objectiveVector()[0] << " " << (*it).objectiveVector()[1] << ", fit: " << (*it).fitness() << std::endl;
it++;
}
}
protected:
/** size max of the archive */
unsigned int maxSize;
/** fitness assigned to the first and the last solution in the archive */
double maxValue;
/** hint for the insertion */
Iterator hint;
/** an empty MOEOT used for checking insertion */
MOEOT empty;
/**
* set fitness
*/
void fitness(Iterator & _it, double _fitnessValue)
{
MOEOT* tmp;
tmp = (MOEOT*)&(*_it);
tmp->fitness(_fitnessValue);
}
/**
* remove solutions from the archive that are dominated by _objVec
* @param _it an iterator beginning on the first potentialy sol to remove
* @param _objVec the objective vector of the new solution
*/
void remove(Iterator & _it, const ObjectiveVector & _objVec)
{
Iterator itd;
while ((_it!=end()) && ((*_it).objectiveVector()[0] >= _objVec[0]))
{
itd = _it;
_it++;
erase(itd);
}
}
/**
* compute fitness value of a solution and its two neighbors
* @param _it refer to the solution
*/
void computeFitness(Iterator & _it)
{
Iterator tmp;
if(_it!=begin())
{
tmp=_it;
tmp--;
compute(tmp);
}
_it++;
if(_it!=end())
{
_it--;
tmp=_it;
tmp++;
compute(tmp);
}
else
{
_it--;
}
compute(_it);
}
/**
* compute fitness value of a solution
* @param _it refer to the solution
*/
void compute(Iterator & _it)
{
double x0, x1, y0, y1, fit;
if (_it==begin())
{
fitness(_it, maxValue);
}
else if ((++_it)==end())
{
_it--;
fitness(_it, maxValue);
}
else
{
_it--;
x0 = (*_it).objectiveVector()[0];
y0 = (*_it).objectiveVector()[1];
_it--;
x1 = (*_it).objectiveVector()[0];
_it++;
_it++;
y1 = (*_it).objectiveVector()[1];
_it--;
fit = (x1 - x0) * (y1 - y0);
fitness(_it, fit);
//tmp = (MOEOT*)&(*_it);
//tmp->fitness(fit);
}
}
double computeTmp(const ObjectiveVector & _objVec, int _where)
{
double res, tmp;
if(hint==begin() || hint==end())
res=maxValue;
else{
if(_where==0){
//on calcule la fit de celui à potentiellement inserer
res= (*hint).objectiveVector()[1] - _objVec[1];
hint--;
res*= ((*hint).objectiveVector()[0] - _objVec[0]);
hint++;
}
else if(_where <0){
// on calcule la fit de son predecesseur
res= _objVec[1] - (*hint).objectiveVector()[1];
tmp=(*hint).objectiveVector()[0];
hint--;
res*= ((*hint).objectiveVector()[0] - tmp);
hint++;
}
else{
// on calcule la fit de son successeur
res= _objVec[0] - (*hint).objectiveVector()[0];
tmp=(*hint).objectiveVector()[1];
hint++;
res*= ((*hint).objectiveVector()[1] - tmp);
hint--;
}
}
return res;
}
void filterbis()
{
Iterator it, itd;
//used to find sol with minimum fitness value
double minFit = maxValue;
// remove MOEOT with the lowest fitness value while archive size > maxSize
while (size() > maxSize)
{
//find sol with minimum fitness
for(it=begin(); it!=end(); it++)
{
if(it->fitness() < minFit)
{
minFit = it->fitness();
itd = it;
}
}
//remove it and recompute fitness of its neighbors
it = itd;
it--;
erase(itd);
compute(it);
it++;
compute(it);
}
}
/**
* iteratively removes the less-contributing solution from the acrhive
*/
bool filter(const MOEOT & _moeo)
{
bool res;
double x, y, pred, succ, tmp=0;
if(hint==begin() || hint==end())
{
insert(hint, _moeo);
hint--;
computeFitness(hint);
filterbis();
res=true;
}
else
{
//compute fitness tmp
tmp=computeTmp(_moeo.objectiveVector(), 0);
hint--;
pred=computeTmp(_moeo.objectiveVector(), -1);
hint++;
succ=computeTmp(_moeo.objectiveVector(), 1);
if(tmp>succ || tmp>pred)
{
insert(hint, _moeo);
hint--;
//ici faudrait utiliser les valeurs qu'on vient de calculer pour les affecter direct (faire attention à ou on se trouve)
computeFitness(hint);
filterbis();
res=true;
}
else
{
Iterator it;
double minFit = maxValue;
for(it=begin(); it!=end(); it++)
{
if(it->fitness() < minFit)
{
minFit = it->fitness();
}
}
if (tmp<=minFit)
{
res = false;
}
else
{
// REDONDANT arranger le code
insert(hint, _moeo);
hint--;
//ici faudrait utiliser les valeurs qu'on vient de calculer pour les affecter direct (faire attention à ou on se trouve)
computeFitness(hint);
filterbis();
res=true;
}
}
}
return res;
}
};
#endif /* MOEO2DMINHYPERVOLUMEARCHIVE_H_ */

View file

@ -0,0 +1,235 @@
/*
* <moeoArchive.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 MOEOARCHIVE_H_
#define MOEOARCHIVE_H_
#include <eoPop.h>
#include <comparator/moeoObjectiveVectorComparator.h>
#include <comparator/moeoParetoObjectiveVectorComparator.h>
/**
* Abstract class for representing an archive ;
* an archive is a secondary population that stores non-dominated solutions.
*/
template < class MOEOT >
class moeoArchive : public eoPop < MOEOT >, public eoUF < const MOEOT &, bool>, public eoUF < const eoPop < MOEOT > &, bool>
{
public:
using eoPop < MOEOT > :: size;
using eoPop < MOEOT > :: operator[];
using eoPop < MOEOT > :: back;
using eoPop < MOEOT > :: pop_back;
/**
* The type of an objective vector for a solution
*/
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Default ctor.
* The moeoObjectiveVectorComparator used to compare solutions is based on Pareto dominance
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoArchive(bool _replace=true) : eoPop < MOEOT >(), comparator(paretoComparator), replace(_replace)
{}
/**
* Ctor
* @param _comparator the moeoObjectiveVectorComparator used to compare solutions
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, bool _replace=true) : eoPop < MOEOT >(), comparator(_comparator), replace(_replace)
{}
/**
* Returns true if the current archive dominates _objectiveVector according to the moeoObjectiveVectorComparator given in the constructor
* @param _objectiveVector the objective vector to compare with the current archive
*/
bool dominates (const ObjectiveVector & _objectiveVector) const
{
for (unsigned int i = 0; i<size(); i++)
{
// if _objectiveVector is dominated by the ith individual of the archive...
if ( comparator(_objectiveVector, operator[](i).objectiveVector()) )
{
return true;
}
}
return false;
}
/**
* Returns true if the current archive already contains a solution with the same objective values than _objectiveVector
* @param _objectiveVector the objective vector to compare with the current archive
*/
bool contains (const ObjectiveVector & _objectiveVector) const
{
for (unsigned int i = 0; i<size(); i++)
{
if (operator[](i).objectiveVector() == _objectiveVector)
{
return true;
}
}
return false;
}
/**
* Updates the archive with a given individual _moeo
* @param _moeo the given individual
* @return if the _moeo is added to the archive
*/
virtual bool operator()(const MOEOT & _moeo) = 0;
/**
* Updates the archive with a given population _pop
* @param _pop the given population
* @return if at least one _pop[i] is added to the archive
*/
virtual bool operator()(const eoPop < MOEOT > & _pop) = 0;
/**
* Returns true if the current archive contains the same objective vectors than the given archive _arch
* @param _arch the given archive
*/
bool equals (const moeoArchive < MOEOT > & _arch)
{
for (unsigned int i=0; i<size(); i++)
{
if (! _arch.contains(operator[](i).objectiveVector()))
{
return false;
}
}
for (unsigned int i=0; i<_arch.size() ; i++)
{
if (! contains(_arch[i].objectiveVector()))
{
return false;
}
}
return true;
}
protected:
/**
* Updates the archive with a given individual _moeo
* @param _moeo the given individual
*/
bool update(const MOEOT & _moeo)
{
// first step: removing the dominated solutions from the archive
for (unsigned int j=0; j<size();)
{
// if the jth solution contained in the archive is dominated by _moeo
if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
{
operator[](j) = back();
pop_back();
}
else if (replace && (_moeo.objectiveVector() == operator[](j).objectiveVector()))
{
operator[](j) = back();
pop_back();
}
else
{
j++;
}
}
// second step: is _moeo dominated?
bool dom = false;
for (unsigned int j=0; j<size(); j++)
{
// if _moeo is dominated by the jth solution contained in the archive
if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
{
dom = true;
break;
}
else if (!replace && (_moeo.objectiveVector() == operator[](j).objectiveVector()) )
{
dom = true;
break;
}
}
if (!dom)
{
this->push_back(_moeo);
}
return !dom;
}
/**
* Updates the archive with a given population _pop
* @param _pop the given population
*/
bool update(const eoPop < MOEOT > & _pop)
{
bool res = false;
bool tmp = false;
for (unsigned int i=0; i<_pop.size(); i++)
{
tmp = (*this).update(_pop[i]);
res = tmp || res;
}
return res;
}
/** The moeoObjectiveVectorComparator used to compare solutions */
moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
/** A moeoObjectiveVectorComparator based on Pareto dominance (used as default) */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/** boolean */
bool replace;
};
#endif /*MOEOARCHIVE_H_ */

View file

@ -0,0 +1,81 @@
/*
* <moeoBoundedArchive.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
*
*/
//-----------------------------------------------------------------------------
// moeoBoundedArchive.h
//-----------------------------------------------------------------------------
#ifndef MOEOBOUNDEDARCHIVE_H_
#define MOEOBOUNDEDARCHIVE_H_
#include <archive/moeoArchive.h>
/**
* This class represents a bounded archive which different parameters to specify.
*/
template < class MOEOT >
class moeoBoundedArchive : public moeoArchive < MOEOT >
{
public:
/**
* The type of an objective vector for a solution
*/
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Ctor where you can choose your own moeoObjectiveVectorComparator and archive size.
* @param _comparator the functor used to compare objective vectors
* @param _maxSize the size of archive (must be smaller or egal to the population size)
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoBoundedArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, unsigned int _maxSize=100, bool _replace=true) : moeoArchive < MOEOT >(_comparator, _replace), maxSize(_maxSize){}
/**
* Ctor with moeoParetoObjectiveVectorComparator where you can choose your own archive size.
* @param _maxSize the size of archive (must be smaller or egal to the population size)
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoBoundedArchive(unsigned int _maxSize=100, bool _replace=true) : moeoArchive < MOEOT >(_replace), maxSize(_maxSize){}
protected:
/** archive max size */
unsigned int maxSize;
};
#endif /*MOEOBOUNDEDARCHIVE_H_*/

View file

@ -0,0 +1,421 @@
/*
* <moeoEpsilonHyperboxArchive.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
*
*/
//-----------------------------------------------------------------------------
// moeoEpsilonHyperboxArchive.h
//-----------------------------------------------------------------------------
#ifndef MOEOEPSILONBOXARCHIVE_H_
#define MOEOEPSILONBOXARCHIVE_H_
#include <eoPop.h>
#include <comparator/moeoComparator.h>
#include <comparator/moeoObjectiveVectorComparator.h>
#include <distance/moeoEuclideanDistance.h>
#include <utils/moeoObjectiveVectorNormalizer.h>
#include <utils/eoRealBounds.h>
/**
* This class represents an epsilon hyperbox archive.
*/
template < class MOEOT >
class moeoEpsilonHyperboxArchive : public moeoArchive < MOEOT >
{
public:
using moeoArchive < MOEOT > :: size;
using moeoArchive < MOEOT > :: resize;
using moeoArchive < MOEOT > :: operator[];
using moeoArchive < MOEOT > :: back;
using moeoArchive < MOEOT > :: pop_back;
using moeoArchive < MOEOT > :: push_back;
using moeoArchive < MOEOT > :: begin;
using moeoArchive < MOEOT > :: end;
using moeoArchive < MOEOT > :: replace;
/**
* The type of an objective vector for a solution
*/
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Ctor where you can choose your own moeoObjectiveVectorComparator
* @param _comparator the functor used to compare objective vectors
* @param _epsilon the vector contains epsilon values for each objective
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoEpsilonHyperboxArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, std::vector<double> _epsilon, bool _replace=true) : moeoArchive < MOEOT >(_comparator, _replace), epsilon(_epsilon), bounds(0.0, 1.0), normalizer(bounds, 1.0)
{}
/**
* Default Ctor
* @param _epsilon the vector contains epsilon values for each objective
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoEpsilonHyperboxArchive(std::vector<double> _epsilon, bool _replace=true) : moeoArchive < MOEOT >(paretoComparator, _replace), epsilon(_epsilon), bounds(0.0, 1.0), normalizer(bounds, 1.0)
{}
/**
* Updates the archive with a given individual _moeo
* @param _moeo the given individual
* @return true if _moeo is non-dominated (and not if it is added to the archive)
*/
bool operator()(const MOEOT & _moeo)
{
bool res=false;
unsigned int i=0;
bool nonstop = true;
bool same = true;
int change = 0;
MOEOT removed;
//if the archive is empty, we accept automaticaly _moeo
if(size()==0){
push_back(_moeo);
ideal = _moeo.objectiveVector();
nadir = _moeo.objectiveVector();
res = true;
}
else{
//change bounds if necessary
change = changeBounds(_moeo);
//if change < 0, we have detected that _moeo is bad
//else there are 4 cases:
if(change >= 0){
//calculate the hyperbox corner of _moeo
ObjectiveVector corner, tmp;
corner=hyperbox(_moeo);
//test if _moeo hyperbox corner dominates a hyperbox corner of an element of the archive
while(nonstop && (i<size())){
same = true;
//calculate the hyperbox corner of the ieme element of the archive
tmp=hyperbox(operator[](i));
//CASE 1: _moeo epsilon-domine the ieme element of the archive
if(this->comparator(tmp, corner)){
std::cout << "ENTER CASE 1" << std::endl;
//test if bounds changed
//removed=operator[](i);
//delete the ieme element of the archive
if(i==size()-1)
pop_back();
else{
operator[](i)=back();
pop_back();
i--;
}
//changeBoundsByDeleting(removed);
res = true;
}//END CASE 1
//CASE 2: the ieme element of the archive epsilon-domine _moeo
else if(this->comparator(corner, tmp)){
std::cout << "ENTER CASE 2" << std::endl;
if(change == 1)
changeBoundsByDeleting(_moeo);
//we can stop
nonstop = false;
}//END CASE 2
// _moeo is no-epsilon-dominated by archive[i] and arhcive[i] is no-epsilon-dominated by _moeo
else{
//test if the hyperbox corner are the same
for(unsigned int j=0; j<corner.size(); j++)
same = same && (corner[j] == tmp[j]);
//CASE 3: _moeo is in the same hyperbox of archive[i]
if(same){
std::cout << "ENTER CASE 3" << std::endl;
// _moeo dominates archive[i]
if(this->comparator(operator[](i).objectiveVector(), _moeo.objectiveVector())){
if(i==size()-1)
pop_back();
else{
operator[](i)=back();
pop_back();
i--;
}
// removed=operator[](i);
// operator[](i) = _moeo;
// changeBoundsByDeleting(removed);
res=true;
}
// _moeo is dominated by archive[i]
else if(this->comparator(_moeo.objectiveVector(), operator[](i).objectiveVector())){
changeBoundsByDeleting(_moeo);
nonstop=false;
}
else{
//keep the one who have the shortest euclidian distance between the corner
moeoEuclideanDistance < MOEOT > dist;
double d1 = dist(_moeo.objectiveVector(), corner);
double d2 = dist(operator[](i).objectiveVector(), corner);
if(d1 <= d2){
if(i==size()-1)
pop_back();
else{
operator[](i)=back();
pop_back();
i--;
}
// removed=operator[](i);
// operator[](i) = _moeo;
// changeBoundsByDeleting(removed);
res=true;
}
else{
nonstop=false;
// changeBoundsByDeleting(_moeo);
res=true;
}
}
}//END CASE 3
}
i++;
}
//CASE 4: _moeo have is place in a empty hyperbox
if(nonstop){
std::cout << "ENTER CASE 4" << std::endl;
push_back(_moeo);
res=true;
recalculateBounds();
}//END CASE 4
}
else{
std::cout << "ENTER CASE 5" << std::endl;
}
}
return res;
}
/**
* Updates the archive with a given population _pop
* @param _pop the given population
* @return if an archive's element is non-dominated (and not if it is added to the archive)
*/
bool operator()(const eoPop < MOEOT > & _pop)
{
bool res, tmp = false;
for(unsigned int i=0; i<_pop.size(); i++){
tmp = (*this)(_pop[i]);
res = res || tmp;
}
return res;
}
/**
* get the nadir point
* @return ObjectiveVector corresponding to the nadir point
*/
ObjectiveVector getNadir(){
return nadir;
}
/**
* get the idealpoint
* @return ObjectiveVector corresponding to the ideal point
*/
ObjectiveVector getIdeal(){
return ideal;
}
void filtre(){
eoPop<MOEOT> pop;
for(int i=0; i<size(); i++)
pop.push_back(operator[](i));
for(int i=0; i<pop.size(); i++)
(*this)(pop[i]);
}
private:
/**
* calculate the hyperbox corner of _moeo
* @param _moeo the given individual
* @return the ObjectiveVector contains the hyperbox corner values
*/
ObjectiveVector hyperbox(const MOEOT & _moeo){
//normalize _moeo's objectiveVector
ObjectiveVector res;
res = normalizer(_moeo.objectiveVector());
// std::cout << "ObjectiveVector non normalise:"<< _moeo.objectiveVector() << std::endl;
// std::cout << "ObjectiveVector normalise:"<< res << std::endl;
//calculate the hyperbox corner
for(unsigned int i=0; i<ObjectiveVector::nObjectives(); i++){
if(ObjectiveVector::minimizing(i))
res[i] = floor(res[i]*1.0/epsilon[i]);
else
res[i] = ceil(res[i]*1.0/epsilon[i]);
}
// std::cout << "ObjectiveVector epsilone:" << res << std::endl;
return res;
}
/**
* changes ideal and nadir point if _moeo is out of bounds and is not bad
* @param _moeo the given individual
* @return if bounds changed or not (1 -> changed, 0 -> not changed, -1 -> _moeo is bad)
*/
int changeBounds(const MOEOT & _moeo){
// std::cout << "changebounds objVec: "<< _moeo.objectiveVector() << std::endl;
int res = 0;
//check if an objective is better than the corresponding of the current ideal point
for(unsigned int i=0; i<ObjectiveVector::nObjectives(); i++){
if(ObjectiveVector::minimizing(i)){
if(_moeo.objectiveVector()[i] < ideal[i]){
ideal[i]=_moeo.objectiveVector()[i];
res = 1;
}
}
else{
if(_moeo.objectiveVector()[i] > ideal[i]){
ideal[i]=_moeo.objectiveVector()[i];
res = 1;
}
}
}
//check if an objective is worst than the corresponding of the current nadir point
for(unsigned int i=0; i<ObjectiveVector::nObjectives(); i++){
if(ObjectiveVector::minimizing(i)){
if(_moeo.objectiveVector()[i] > nadir[i]){
if(res == 1)
nadir[i]=_moeo.objectiveVector()[i];
else
res = -1; // no objective is better than the ideal and some are worst than nadir -> _moeo is bad
}
}
else{
if(_moeo.objectiveVector()[i] < nadir[i]){
if(res == 1)
nadir[i]=_moeo.objectiveVector()[i];
else
res = -1; // no objective is better than the ideal and some are worst than nadir -> _moeo is bad
}
}
}
//If bounds are changed, change the scale of normalizer
if(res == 1){
ObjectiveVector mini;
ObjectiveVector maxi;
for(unsigned int i=0; i<ObjectiveVector::nObjectives(); i++){
mini[i]=std::min(ideal[i], nadir[i]);
maxi[i]=std::max(ideal[i], nadir[i]);
}
normalizer.update_by_min_max(mini, maxi);
}
// std::cout << "change nadir: " << nadir << std::endl;
// std::cout << "change ideal: " << ideal << std::endl;
// std::cout << "res: " << res << std::endl;
return res;
}
/**
* when a element is deleting, change the bounds if neccesary.
* @param _moeo the deleted individual
*/
void changeBoundsByDeleting(const MOEOT & _moeo){
for(unsigned int i=0; i< ObjectiveVector::nObjectives(); i++){
if((_moeo.objectiveVector()[i]==nadir[i]) || (_moeo.objectiveVector()[i]==ideal[i]) )
return recalculateBounds();
}
}
/**
* recalculate ideal and nadir point and change scale of normalizer
*/
void recalculateBounds(){
ObjectiveVector tmp;
ideal=operator[](0).objectiveVector();
nadir=operator[](0).objectiveVector();
if (size() > 1){
for(unsigned int i=0; i< ObjectiveVector::nObjectives(); i++){
for(unsigned int j=1; j<size(); j++){
tmp=operator[](j).objectiveVector();
if(ObjectiveVector::minimizing(i)){
if(tmp[i] < ideal[i])
ideal[i] = tmp[i];
else if(tmp[i] > nadir[i])
nadir[i] = tmp[i];
}
else{
if(tmp[i] > ideal[i]){
ideal[i] = tmp[i];
}
else if(tmp[i] < nadir[i]){
nadir[i] = tmp[i];
}
}
}
}
}
ObjectiveVector mini;
ObjectiveVector maxi;
for(unsigned int i=0; i<ObjectiveVector::nObjectives(); i++){
mini[i]=std::min(ideal[i], nadir[i]);
maxi[i]=std::max(ideal[i], nadir[i]);
}
normalizer.update_by_min_max(mini, maxi);
}
/** A moeoObjectiveVectorComparator based on Pareto dominance (used as default) */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/** epsilon values */
std::vector <double> epsilon;
/** ideal point of the archive */
ObjectiveVector ideal;
/** nadir point of the archive */
ObjectiveVector nadir;
/** bounds use by default to initialize the normalizer */
eoRealInterval bounds;
/** the objective vector normalizer */
moeoObjectiveVectorNormalizer <MOEOT> normalizer;
};
#endif /*MOEOEPSILONBOXARCHIVE_H_*/

View file

@ -0,0 +1,174 @@
/*
* <moeoFitDivBoundedArchive.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
*
*/
//-----------------------------------------------------------------------------
// moeoFitDivBoundedArchive.h
//-----------------------------------------------------------------------------
#ifndef MOEOFITDIVBOUNDEDARCHIVE_H_
#define MOEOFITDIVBOUNDEDARCHIVE_H_
#include <list>
#include <eoPop.h>
#include <comparator/moeoComparator.h>
#include <comparator/moeoObjectiveVectorComparator.h>
#include <diversity/moeoDiversityAssignment.h>
#include <fitness/moeoFitnessAssignment.h>
/**
* This class represents a bounded archive which different parameters to specify.
*/
template < class MOEOT >
class moeoFitDivBoundedArchive : public moeoBoundedArchive < MOEOT >
{
public:
using moeoArchive < MOEOT > :: size;
using moeoArchive < MOEOT > :: resize;
using moeoArchive < MOEOT > :: operator[];
using moeoArchive < MOEOT > :: back;
using moeoArchive < MOEOT > :: pop_back;
using moeoArchive < MOEOT > :: push_back;
using moeoArchive < MOEOT > :: begin;
using moeoArchive < MOEOT > :: end;
using moeoArchive < MOEOT > :: replace;
using moeoBoundedArchive < MOEOT > :: maxSize;
/**
* The type of an objective vector for a solution
*/
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Ctor where you can choose your own moeoComparator, moeoObjectiveVectorComparator, moeoFitnessAssignment, moeoDiversityAssignment and archive size.
* @param _indiComparator the functor used to compare MOEOT
* @param _comparator the functor used to compare objective vectors
* @param _fitness the assignment fitness method
* @param _diversity the diversity assignment method
* @param _maxSize the size of archive (must be smaller or egal to the population size)
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoFitDivBoundedArchive(moeoComparator < MOEOT > & _indiComparator, moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, moeoFitnessAssignment < MOEOT > & _fitness, moeoDiversityAssignment < MOEOT > & _diversity, unsigned int _maxSize=100, bool _replace=true) : moeoBoundedArchive < MOEOT >(_comparator, _maxSize, _replace), indiComparator(_indiComparator), fitness(_fitness), diversity(_diversity)
{}
/**
* Ctor with moeoParetoObjectiveVectorComparator where you can choose your own moeoComparator, moeoFitnessAssignment, moeoDiversityAssignment and archive size.
* @param _indiComparator the functor used to compare MOEOT
* @param _fitness the assignment fitness method
* @param _diversity the diversity assignment method
* @param _maxSize the size of archive (must be smaller or egal to the population size)
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoFitDivBoundedArchive(moeoComparator < MOEOT > & _indiComparator, moeoFitnessAssignment < MOEOT > & _fitness, moeoDiversityAssignment < MOEOT > & _diversity, unsigned int _maxSize=100, bool _replace=true) : moeoBoundedArchive < MOEOT >(_maxSize, _replace), indiComparator(_indiComparator), fitness(_fitness), diversity(_diversity)
{}
/**
* Updates the archive with a given individual _moeo
* @param _moeo the given individual
* @return true if _moeo is non-dominated (and not if it is added to the archive)
*/
bool operator()(const MOEOT & _moeo)
{
bool res;
res = this->update(_moeo);
if(size() > maxSize){
fitness(*this);
diversity(*this);
std::sort(begin(), end(), indiComparator);
resize(maxSize);
}
return res;
}
/**
* Updates the archive with a given population _pop
* @param _pop the given population
* @return true if a _pop[i] is non-dominated (and not if it is added to the archive)
*/
bool operator()(const eoPop < MOEOT > & _pop)
{
bool res;
res = this->update(_pop);
if(size() > maxSize){
fitness(*this);
diversity(*this);
std::sort(begin(), end(), indiComparator);
resize(maxSize);
}
return res;
}
private:
/**
* Wrapper which allow to used an moeoComparator in std::sort
* @param _comp the comparator to used
*/
class Wrapper
{
public:
/**
* Ctor.
* @param _comp the comparator
*/
Wrapper(moeoComparator < MOEOT > & _comp) : comp(_comp) {}
/**
* Returns true if _moeo1 is greater than _moeo2 according to the comparator
* _moeo1 the first individual
* _moeo2 the first individual
*/
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return comp(_moeo1,_moeo2);
}
private:
/** the comparator */
moeoComparator < MOEOT > & comp;
}
indiComparator;
/** fitness assignment */
moeoFitnessAssignment < MOEOT > & fitness;
/** diversity assignment */
moeoDiversityAssignment < MOEOT > & diversity;
};
#endif /*MOEOFITDIVBOUNDEDARCHIVE_H_*/

View file

@ -0,0 +1,80 @@
/*
* <moeoFixedSizeArchive.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
*
*/
//-----------------------------------------------------------------------------
// moeoFixedSizeArchive.h
//-----------------------------------------------------------------------------
#ifndef MOEOFIXEDSIZEARCHIVE_H_
#define MOEOFIXEDSIZEARCHIVE_H_
#include <eoPop.h>
#include <archive/moeoArchive.h>
#include <comparator/moeoObjectiveVectorComparator.h>
/**
* Abstract class for representing a fixed size archive ;
* a fixed size archive is an archive containing a given number of solutions.
*/
template < class MOEOT >
class moeoFixedSizeArchive : public moeoArchive < MOEOT >
{
public:
/**
* The type of an objective vector for a solution
*/
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Default ctor.
* The moeoObjectiveVectorComparator used to compare solutions is based on Pareto dominance
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoFixedSizeArchive(bool _replace=true) : moeoArchive < MOEOT >(_replace) {}
/**
* Ctor
* @param _comparator the moeoObjectiveVectorComparator used to compare solutions
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoFixedSizeArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, bool _replace=true) : moeoArchive < MOEOT >( _comparator, _replace) {}
};
#endif /*MOEOFIXEDSIZEARCHIVE_H_*/

View file

@ -0,0 +1,170 @@
/*
* <moeoImprOnlyBoundedArchive.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
*
*/
//-----------------------------------------------------------------------------
// moeoIMPRONLYBOUNDEDARCHIVE.h
//-----------------------------------------------------------------------------
#ifndef MOEOImprOnlyBoundedArchive_H_
#define MOEOImprOnlyBoundedArchive_H_
#include <archive/moeoBoundedArchive.h>
#include <archive/moeoArchive.h>
/**
* This class represents a bounded archive which different parameters to specify.
*/
template < class MOEOT >
class moeoImprOnlyBoundedArchive : public moeoBoundedArchive < MOEOT >
{
public:
using moeoArchive < MOEOT > :: size;
using moeoArchive < MOEOT > :: resize;
using moeoArchive < MOEOT > :: operator[];
using moeoArchive < MOEOT > :: back;
using moeoArchive < MOEOT > :: pop_back;
using moeoArchive < MOEOT > :: push_back;
using moeoArchive < MOEOT > :: begin;
using moeoArchive < MOEOT > :: end;
using moeoArchive < MOEOT > :: replace;
using moeoBoundedArchive < MOEOT > :: maxSize;
/**
* The type of an objective vector for a solution
*/
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Ctor where you can choose your own moeoComparator and archive size.
* @param _comparator the functor used to compare objective vectors
* @param _maxSize the size of archive (must be smaller or egal to the population size)
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoImprOnlyBoundedArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, unsigned int _maxSize=100, bool _replace=true) : moeoBoundedArchive < MOEOT >(_comparator, _maxSize, _replace){}
/**
* Ctor with moeoParetoObjectiveVectorComparator where you can choose your own archive size.
* @param _maxSize the size of archive (must be smaller or egal to the population size)
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoImprOnlyBoundedArchive(unsigned int _maxSize=100, bool _replace=true) : moeoBoundedArchive < MOEOT >(_maxSize, _replace){}
/**
* Updates the archive with a given individual _moeo
* @param _moeo the given individual
* @return true if _moeo is non-dominated (and not if it is added to the archive)
*/
bool operator()(const MOEOT & _moeo)
{
return update(_moeo);
}
/**
* Updates the archive with a given population _pop
* @param _pop the given population
* @return true if a _pop[i] is non-dominated (and not if it is added to the archive)
*/
bool operator()(const eoPop < MOEOT > & _pop)
{
bool res = false;
bool tmp = false;
for (unsigned int i=0; i<_pop.size(); i++)
{
tmp = (*this).update(_pop[i]);
res = tmp || res;
}
return res;
}
private:
/**
* Updates the archive with a given individual _moeo *** NEW ***
* @param _moeo the given individual
*/
bool update(const MOEOT & _moeo)
{
// first step: removing the dominated solutions from the archive
for (unsigned int j=0; j<size();)
{
// if the jth solution contained in the archive is dominated by _moeo
if ( this->comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
{
operator[](j) = back();
pop_back();
}
else if (replace && (_moeo.objectiveVector() == operator[](j).objectiveVector()))
{
operator[](j) = back();
pop_back();
}
else
{
j++;
}
}
// second step: is _moeo dominated?
bool dom = false;
for (unsigned int j=0; j<size(); j++)
{
// if _moeo is dominated by the jth solution contained in the archive
if ( this->comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
{
dom = true;
break;
}
else if (!replace && (_moeo.objectiveVector() == operator[](j).objectiveVector()) )
{
dom = true;
break;
}
}
if (!dom)
{
if(size()<maxSize)
push_back(_moeo);
else
dom=!dom;
}
return !dom;
}
};
#endif /*MOEOIMPRONLYBOUNDEDARCHIVE_H_*/

View file

@ -0,0 +1,386 @@
/*
* <moeoSPEA2Archive.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
*
*/
//-----------------------------------------------------------------------------
// moeoSPEA2Archive.h
//-----------------------------------------------------------------------------
#ifndef MOEOSPEA2ARCHIVE_H_
#define MOEOSPEA2ARCHIVE_H_
#include <limits>
#include <list>
#include <eoPop.h>
#include <archive/moeoFixedSizeArchive.h>
#include <comparator/moeoComparator.h>
#include <comparator/moeoFitnessThenDiversityComparator.h>
#include <comparator/moeoObjectiveVectorComparator.h>
#include <distance/moeoDistance.h>
#include <distance/moeoEuclideanDistance.h>
/**
* This class represents a bounded archive as defined in the SPEA2 algorithm.
* E. Zitzler, M. Laumanns, and L. Thiele. SPEA2: Improving the Strength Pareto Evolutionary Algorithm. Technical Report 103,
* Computer Engineering and Networks Laboratory (TIK), ETH Zurich, Zurich, Switzerland, 2001.
*/
template < class MOEOT >
class moeoSPEA2Archive : public moeoFixedSizeArchive < MOEOT >
{
public:
using moeoFixedSizeArchive < MOEOT > :: size;
using moeoFixedSizeArchive < MOEOT > :: resize;
using moeoFixedSizeArchive < MOEOT > :: operator[];
using moeoFixedSizeArchive < MOEOT > :: back;
using moeoFixedSizeArchive < MOEOT > :: pop_back;
using moeoFixedSizeArchive < MOEOT > :: push_back;
using moeoFixedSizeArchive < MOEOT > :: begin;
using moeoFixedSizeArchive < MOEOT > :: end;
/**
* The type of an objective vector for a solution
*/
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Default ctor.
* @param _maxSize the size of archive (must be smaller or equal to the population size)
*/
moeoSPEA2Archive(unsigned int _maxSize=100): moeoFixedSizeArchive < MOEOT >(true), maxSize(_maxSize), borne(0), indiComparator(defaultComparator), distance(defaultDistance)
{}
/**l
* Ctor where you can choose your own moeoDistance
* @param _dist the distance used
* @param _maxSize the size of archive (must be smaller or egal to the population size)
*/
moeoSPEA2Archive(moeoDistance <MOEOT, double>& _dist, unsigned int _maxSize=100): moeoFixedSizeArchive < MOEOT >(true), maxSize(_maxSize), borne(0), indiComparator(defaultComparator), distance(_dist)
{}
/**
* Ctor where you can choose your own moeoObjectiveVectorComparator
* @param _comparator the functor used to compare objective vectors
* @param _maxSize the size of archive (must be smaller or egal to the population size)
*/
moeoSPEA2Archive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, unsigned int _maxSize=100): moeoFixedSizeArchive < MOEOT >(_comparator, true), maxSize(_maxSize), borne(0), indiComparator(defaultComparator), distance(defaultDistance)
{}
/**
* Ctor where you can choose your own moeoComparator
* @param _indiComparator the functor used to compare MOEOT
* @param _maxSize the size of archive (must be smaller or egal to the population size)
*/
moeoSPEA2Archive(moeoComparator <MOEOT>& _indiComparator, unsigned int _maxSize=100): moeoFixedSizeArchive < MOEOT >(true), maxSize(_maxSize), borne(0), indiComparator(_indiComparator), distance(defaultDistance)
{}
/**
* Ctor where you can choose your own moeoComparator, moeoDistance and moeoObjectiveVectorComparator
* @param _indiComparator the functor used to compare MOEOT
* @param _dist the distance used
* @param _comparator the functor used to compare objective vectors
* @param _maxSize the size of archive (must be smaller or egal to the population size)
*/
moeoSPEA2Archive(moeoComparator <MOEOT>& _indiComparator, moeoDistance <MOEOT, double>& _dist, moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, unsigned int _maxSize=100) : moeoFixedSizeArchive < MOEOT >(_comparator, true), maxSize(_maxSize), borne(0), indiComparator(_indiComparator), distance(_dist)
{}
/**
* Updates the archive with a given individual _moeo
* @param _moeo the given individual
* @return true (TODO)
*/
bool operator()(const MOEOT & _moeo)
{
eoPop < MOEOT > pop_tmp;
pop_tmp.push_back(_moeo);
operator()(pop_tmp);
return true;
}
/**
* Updates the archive with a given population _pop
* @param _pop the given population
* @return true (TODO)
*/
bool operator()(const eoPop < MOEOT > & _pop)
{
unsigned int i;
unsigned int foo=0;
//Creation of the vector that contains minimal pop's informations
std::vector<struct refpop> copy_pop(_pop.size());
for (i=0;i<_pop.size(); i++)
{
copy_pop[i].index=i;
copy_pop[i].fitness=_pop[i].fitness();
copy_pop[i].diversity=_pop[i].diversity();
}
//Sort this vector in decrease order of fitness+diversity
std::sort(copy_pop.begin(), copy_pop.end(), Cmp());
//If the archive is empty, put in the best elements of the pop
if (borne < maxSize)
{
foo= std::min((unsigned int)_pop.size(), maxSize-borne);
for (i=0; i< foo ; i++)
{
push_back(_pop[copy_pop[i].index]);
borne++;
}
}
else
{
unsigned int j=0;
//Sort the archive
std::sort(begin(), end(), indiComparator);
i=0;
//While we have a better element in pop than the worst <= -1 in the archive, replace the worst(of archive) by the best(of pop)
while ( (i<borne) && ( (operator[](i).fitness()+operator[](i).diversity()) < (copy_pop[j].fitness + copy_pop[j].diversity) ) && (operator[](i).fitness()<=-1) && ( j < copy_pop.size() ) )
{
operator[](i)= back();
pop_back();
push_back(_pop[copy_pop[j].index]);
i++;
j++;
}
//If their are others goods elements in pop (fitness=0) , keep only archive's size elements between the archive's elements and the good element in the pop (k ieme smallest distance is used)
if (copy_pop[j].fitness > -1)
{
unsigned int inf=j;
unsigned int p;
unsigned int k=0;
unsigned int l=0;
double tmp=0;
unsigned int tmp2=0;
//search bounds of copy_pop where are the goods elements
while ((j < copy_pop.size()) && (copy_pop[j].fitness > -1.0))
j++;
p=j-inf;
std::vector< std::vector< std::pair<int,double> > > matrice(borne+p);
//Build the distance matrice(vector of vector) between each keeped elements
if (borne+p>0)
{
for (k=0; k<borne+p-1; k++)
{
for (l=k+1; l<borne+p; l++)
{
if ( (k<borne) && (l<borne) )
tmp=distance(operator[](k), operator[](l));
else if ( (k<borne) && (l>=borne) )
tmp=distance(operator[](k), _pop[copy_pop[l-borne+inf].index]);
else
tmp=distance(_pop[copy_pop[k-borne+inf].index], _pop[copy_pop[l-borne+inf].index]);
matrice[k].push_back(std::pair<int,double>(l,tmp));
matrice[l].push_back(std::pair<int,double>(k,tmp));
}
}
}
for (k=0; k<borne+p; k++)
{
//sort each line of the matrice
std::sort(matrice[k].begin(),matrice[k].end(), CmpPair());
//insert an indice at the end of each line after they were be sorted
matrice[k].push_back(std::pair<int,double>(-1,k));
}
//sort the lines of the matrice between us (by shortest distance)
std::sort(matrice.begin(),matrice.end(), CmpVector());
//vectors and iterators used to replace some archive element by some pop element
std::vector<unsigned int> notkeeped;
std::vector<unsigned int> keeped;
std::vector< std::vector< std::pair<int,double> > >::iterator matrice_it=matrice.begin();
std::vector< std::pair<int,double> >::iterator it;
//search elements of the archive to delete
for (k=0; k<p; k++)
{
tmp2=(unsigned int)matrice[0].back().second;
if (tmp2<borne)
notkeeped.push_back(tmp2);
matrice.erase(matrice_it);
for (l=0; l<matrice.size(); l++)
{
it=matrice[l].begin();
while ((unsigned int)(*it).first != tmp2)
it++;
matrice[l].erase(it);
}
if (k != (p-1))
std::sort(matrice.begin(),matrice.end(), CmpVector());
}
//search elements of pop to put in archive
for (k=0; k<borne; k++)
{
tmp2=(unsigned int)matrice[k].back().second;
if (tmp2 >= borne)
keeped.push_back(tmp2);
}
//replace some archive element by some pop element
for (k=0; k<keeped.size(); k++)
{
push_back( _pop[ copy_pop[keeped[k]-borne+inf].index ] );
operator[](notkeeped[k]) = back();
pop_back();
}
}
}
return true;
}//endoperator()
private:
/** archive max size */
unsigned int maxSize;
/** archive size */
unsigned int borne;
/**
* Wrapper which allow to used an moeoComparator in std::sort
* @param _comp the comparator to used
*/
class Wrapper
{
public:
/**
* Ctor.
* @param _comp the comparator
*/
Wrapper(moeoComparator < MOEOT > & _comp) : comp(_comp) {}
/**
* Returns true if _moeo1 is greater than _moeo2 according to the comparator
* _moeo1 the first individual
* _moeo2 the first individual
*/
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return comp(_moeo1,_moeo2);
}
private:
/** the comparator */
moeoComparator < MOEOT > & comp;
}
indiComparator;
/** default moeoComparator*/
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
/** distance */
moeoDistance <MOEOT, double>& distance;
/** default distance */
moeoEuclideanDistance < MOEOT > defaultDistance;
/**
* Structure needs to copy informations of the pop in order to sort it
*/
struct refpop
{
unsigned int index;
double fitness;
double diversity;
};
/**
* Comparator of struct refpop : compare fitness+divesity
*/
struct Cmp
{
bool operator()(const struct refpop& _a, const struct refpop& _b)
{
return ( (_a.diversity + _a.fitness) > (_b.diversity + _b.fitness) );
}
};
/**
* Comparator of two vector of pair
* Compare the second pair's value of the first element vector, if equals compare the next element vector...
*/
struct CmpVector
{
bool operator()( const std::vector< std::pair<int,double> >& _a, const std::vector< std::pair<int,double> >& _b)
{
std::vector< std::pair<int,double> >::const_iterator it1= _a.begin();
std::vector< std::pair<int,double> >::const_iterator it2= _b.begin();
while ( (it1 != _a.end()) && (it2 != _b.end()))
{
if ((*it1).second < (*it2).second)
return true;
else if ((*it1).second > (*it2).second)
return false;
it1++;
it2++;
}
return true;
}
};
/**
* Comparator of two pair : compare the second pair's value
*/
struct CmpPair
{
bool operator()(const std::pair<int,double>& _a, const std::pair<int,double>& _b)
{
return _a.second < _b.second;
}
};
};
#endif /*MOEOSPEA2ARCHIVE_H_*/

View file

@ -0,0 +1,100 @@
/*
* <moeoUnboundedArchive.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
*
*/
//-----------------------------------------------------------------------------
// moeoUnboundedArchive.h
//-----------------------------------------------------------------------------
#ifndef MOEOUNBOUNDEDARCHIVE_H_
#define MOEOUNBOUNDEDARCHIVE_H_
#include <eoPop.h>
#include <archive/moeoArchive.h>
#include <comparator/moeoObjectiveVectorComparator.h>
/**
* An unbounded archive is an archive storing an unbounded number of non-dominated solutions.
*/
template < class MOEOT >
class moeoUnboundedArchive : public moeoArchive < MOEOT >
{
public:
/**
* The type of an objective vector for a solution
*/
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Default ctor.
* The moeoObjectiveVectorComparator used to compare solutions is based on Pareto dominance
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoUnboundedArchive(bool _replace=true) : moeoArchive < MOEOT >(_replace) {}
/**
* Ctor
* @param _comparator the moeoObjectiveVectorComparator used to compare solutions
* @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not
*/
moeoUnboundedArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, bool _replace=true) : moeoArchive < MOEOT >(_comparator, _replace) {}
/**
* Updates the archive with a given individual _moeo
* @param _moeo the given individual
* @return true if _moeo is added to the archive
*/
bool operator()(const MOEOT & _moeo)
{
return this->update(_moeo);
}
/**
* Updates the archive with a given population _pop
* @param _pop the given population
* @return true if a _pop[i] is added to the archive
*/
bool operator()(const eoPop < MOEOT > & _pop)
{
return this->update(_pop);
}
};
#endif /*MOEOUNBOUNDEDARCHIVE_H_*/