file cleaned
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1883 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
942686cede
commit
8ff21724ed
1 changed files with 142 additions and 104 deletions
|
|
@ -43,7 +43,6 @@
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template < class MOEOT >
|
template < class MOEOT >
|
||||||
struct comp
|
struct comp
|
||||||
{
|
{
|
||||||
|
|
@ -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];
|
||||||
|
|
@ -296,10 +299,45 @@ protected:
|
||||||
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_ */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue