file cleaned

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1883 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-07-08 14:56:04 +00:00
commit 8ff21724ed

View file

@ -1,39 +1,39 @@
/* /*
* <moeo2DMinHypervolumeArchive.h> * <moeo2DMinHypervolumeArchive.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Arnaud Liefooghe * Arnaud Liefooghe
* Jérémie Humeau * Jérémie Humeau
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL * modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL * license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info". * "http://www.cecill.info".
* *
* As a counterpart to the access to the source code and rights to copy, * 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 * modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the * with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability. * economic rights, and the successive licensors have only limited liability.
* *
* In this respect, the user's attention is drawn to the risks associated * In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the * with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software, * 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 * that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced * therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore * professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their * encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or * 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 * data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security. * same conditions as regards security.
* The fact that you are presently reading this means that you have had * The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms. * knowledge of the CeCILL license and that you accept its terms.
* *
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr * Contact: paradiseo-help@lists.gforge.inria.fr
* *
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef MOEO2DMINHYPERVOLUMEARCHIVE_H_ #ifndef MOEO2DMINHYPERVOLUMEARCHIVE_H_
@ -43,7 +43,6 @@
#include <climits> #include <climits>
template < class MOEOT > template < class MOEOT >
struct comp struct comp
{ {
@ -58,7 +57,7 @@ struct comp
/** 2D (minimization) bounded archive by hypervolume , base on a set */ /** 2D (minimization) bounded archive by hypervolume , base on a set */
template < class MOEOT > template < class MOEOT >
class moeo2DMinHypervolumeArchive : public std::set<MOEOT, comp < MOEOT > > class moeo2DMinHypervolumeArchive : public std::set<MOEOT , comp < MOEOT > >
{ {
public: public:
@ -76,18 +75,17 @@ public:
/** /**
* Ctr. * Ctr.
* @param _maxSize size of the archive (must be >1) * @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) * @param _maxValue fitness assigned to the first and the last solution in the archive (default LONG_MAX)
*/ */
moeo2DMinHypervolumeArchive(unsigned int _maxSize, double _maxValue=LONG_MAX) : std::set < MOEOT, comp<MOEOT> > (), maxSize(_maxSize), maxValue(_maxValue) moeo2DMinHypervolumeArchive(unsigned int _maxSize=100, double _maxValue=LONG_MAX) : std::set < MOEOT, comp<MOEOT> > (), maxSize(_maxSize), maxValue(_maxValue)
{ {
if(maxSize<2) maxSize = std::max((unsigned int) 2, maxSize);
maxSize=2;
} }
/** /**
* update the archive with a solution * Update the archive with a solution
* @param _moeo a solution * @param _moeo a solution
* @return true if _moeo has been added to the archive * @return true if _moeo has been added to the archive
*/ */
@ -95,58 +93,41 @@ public:
{ {
//store result //store result
bool result; bool result;
Iterator it;
//used to affect the fitness value
MOEOT* tmp;
//used to find sol with minimum fitness value
double minFit=maxValue;
Iterator itMinFit;
//If archive is empty -> add the sol and affect its fitness value //If archive is empty -> add the sol and affect its fitness value
if (size()==0){ if (size()==0)
{
result = true; result = true;
insert(_moeo); insert(_moeo);
tmp = (MOEOT*)&(*begin()); it=begin();
tmp->fitness(maxValue); fitness(it, maxValue);
} }
else{ else // test if sol can be added to the archive
//else test if sol can be added to the archive {
result = insert(_moeo.objectiveVector()); result = insert(_moeo.objectiveVector());
if (result){ if (result)
//if yes, insert it and recompute fitness value of MOEOT and its neighbors {
// if yes, insert it and recompute fitness value of MOEOT and its neighbors
insert(hint,_moeo); insert(hint,_moeo);
if(size()>2){ if(size() > 2)
{
//general case //general case
hint--; hint--;
computeFitness(hint); computeFitness(hint);
} }
else{ else
//archive size < 3, fitness=maxValue for each sol {
Iterator it=begin(); //archive size <= 2, fitness=maxValue for each sol
while(it!=end()){ it=begin();
tmp = (MOEOT*)&(*it); while(it!=end())
tmp->fitness(maxValue); {
fitness(it, maxValue);
it++; it++;
} }
} }
//remove MOEOT with the lowest fitness value if archive size > maxSize // remove MOEOT with the lowest fitness value (if archive size > maxSize)
if(size()>maxSize){ filter();
//find sol with minimum fitness
for(Iterator i=begin(); i!=end(); i++){
if(i->fitness() < minFit){
minFit=i->fitness();
itMinFit=i;
}
}
//remove it and recompute fitness of its neighbors
Iterator ittmp=itMinFit;
ittmp--;
erase(itMinFit);
compute(ittmp);
ittmp++;
compute(ittmp);
}
} }
} }
return result; return result;
@ -170,8 +151,9 @@ public:
return result; return result;
} }
/** /**
* Test if insertion is possible and fix hint if yes * Test if insertion wrt Pareto-dominance is possible, and fix 'hint' if possible
* @param _objVec the objective vector of the sol to insert * @param _objVec the objective vector of the sol to insert
* @return true if objVec can be added to the archive wrt Pareto-dominance * @return true if objVec can be added to the archive wrt Pareto-dominance
*/ */
@ -205,29 +187,43 @@ public:
return result; return result;
} }
/** /**
* print objective vector and fitness value of the archive * print objective vector and fitness value of the archive
*/ */
void print(){ void print(){
Iterator it = begin(); Iterator it = begin();
while(it!=end()){ while(it!=end())
{
std::cout << (*it).objectiveVector()[0] << " " << (*it).objectiveVector()[1] << ", fit: " << (*it).fitness() << std::endl; std::cout << (*it).objectiveVector()[0] << " " << (*it).objectiveVector()[1] << ", fit: " << (*it).fitness() << std::endl;
it++; it++;
} }
} }
protected:
/** an empty MOEOT used for checking insertion */ protected:
MOEOT empty;
/** hint for the insertion */
Iterator hint;
/** Size max of the archive*/ /** Size max of the archive*/
unsigned int maxSize; unsigned int maxSize;
/** fitness assigned to the first and the last solution in the archive */ /** fitness assigned to the first and the last solution in the archive */
double maxValue; 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 * remove solutions from the archive that are dominated by _objVec
@ -245,47 +241,54 @@ protected:
} }
} }
/** /**
* compute fitness value of a solution and its two neighbors * compute fitness value of a solution and its two neighbors
* @param _it refer to the solution * @param _it refer to the solution
*/ */
void computeFitness(Iterator& _it){ void computeFitness(Iterator & _it)
{
Iterator tmp; Iterator tmp;
if(_it!=begin()){ if(_it!=begin())
{
tmp=_it; tmp=_it;
tmp--; tmp--;
compute(tmp); compute(tmp);
} }
_it++; _it++;
if(_it!=end()){ if(_it!=end())
{
_it--; _it--;
tmp=_it; tmp=_it;
tmp++; tmp++;
compute(tmp); compute(tmp);
} }
else{ else
{
_it--; _it--;
} }
compute(_it); compute(_it);
} }
/** /**
* compute fitness value of a solution * compute fitness value of a solution
* @param _it refer to the solution * @param _it refer to the solution
*/ */
void compute(Iterator& _it){ void compute(Iterator & _it)
{
double x0, x1, y0, y1, fit; double x0, x1, y0, y1, fit;
MOEOT* tmp; if (_it==begin())
if(_it==begin()){ {
tmp = (MOEOT*)&(*_it); fitness(_it, maxValue);
tmp->fitness(maxValue);
} }
else if((++_it)==end()){ else if ((++_it)==end())
{
_it--; _it--;
tmp = (MOEOT*)&(*_it); fitness(_it, maxValue);
tmp->fitness(maxValue);
} }
else{ else
{
_it--; _it--;
x0 = (*_it).objectiveVector()[0]; x0 = (*_it).objectiveVector()[0];
y0 = (*_it).objectiveVector()[1]; y0 = (*_it).objectiveVector()[1];
@ -295,11 +298,46 @@ protected:
_it++; _it++;
y1 = (*_it).objectiveVector()[1]; y1 = (*_it).objectiveVector()[1];
_it--; _it--;
fit= (x1 - x0) * (y1 - y0); fit = (x1 - x0) * (y1 - y0);
tmp = (MOEOT*)&(*_it); fitness(_it, fit);
tmp->fitness(fit); //tmp = (MOEOT*)&(*_it);
//tmp->fitness(fit);
} }
} }
/**
* iteratively removes the less-contributing solution from the acrhive
*/
void filter()
{
// ierators
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);
}
}
}; };
#endif /*MOEO2DMINHYPERVOLUMEARCHIVE_H_ */ #endif /*MOEO2DMINHYPERVOLUMEARCHIVE_H_ */