new version
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@267 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
6a6dab8eff
commit
5df71ee73a
42 changed files with 3554 additions and 824 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoArchive.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||
/*
|
||||
This library...
|
||||
|
||||
|
|
@ -14,92 +14,165 @@
|
|||
#define MOEOARCHIVE_H_
|
||||
|
||||
#include <eoPop.h>
|
||||
#include <moeoObjectiveVectorComparator.h>
|
||||
|
||||
/**
|
||||
* An archive is a secondary population that stores non-dominated solutions
|
||||
* An archive is a secondary population that stores non-dominated solutions.
|
||||
*/
|
||||
template < class EOT > class moeoArchive:public eoPop < EOT >
|
||||
template < class MOEOT >
|
||||
class moeoArchive : public eoPop < MOEOT >
|
||||
{
|
||||
public:
|
||||
|
||||
using std::vector < EOT >::size;
|
||||
using std::vector < EOT >::operator[];
|
||||
using std::vector < EOT >::back;
|
||||
using std::vector < EOT >::pop_back;
|
||||
using std::vector < MOEOT > :: size;
|
||||
using std::vector < MOEOT > :: operator[];
|
||||
using std::vector < MOEOT > :: back;
|
||||
using std::vector < MOEOT > :: pop_back;
|
||||
|
||||
/**
|
||||
* The fitness type of a solution
|
||||
*/
|
||||
typedef typename EOT::Fitness EOFitness;
|
||||
|
||||
/**
|
||||
* Returns true if the current archive dominates _fit
|
||||
* @param _fit the (Pareto) fitness to compare with the current archive
|
||||
*/
|
||||
bool dominates (const EOFitness & _fit) const
|
||||
{
|
||||
for (unsigned i = 0; i < size; i++)
|
||||
if (operator[](i).fitness ().dominates (_fit))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* The type of an objective vector for a solution
|
||||
*/
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
||||
/**
|
||||
* Returns true if the current archive contains _fit
|
||||
* @param _fit the (Pareto) fitness to search within the current archive
|
||||
*/
|
||||
bool contains (const EOFitness & _fit) const
|
||||
{
|
||||
for (unsigned i = 0; i < size; i++)
|
||||
if (operator[](i).fitness () == _fit)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the archive with a given individual _eo
|
||||
* @param _eo the given individual
|
||||
*/
|
||||
void update (const EOT & _eo)
|
||||
{
|
||||
// Removing the dominated solutions from the archive
|
||||
for (unsigned j = 0; j < size ();)
|
||||
{
|
||||
if (_eo.fitness ().dominates (operator[](j).fitness ()))
|
||||
{
|
||||
operator[](j) = back ();
|
||||
pop_back ();
|
||||
}
|
||||
else if (_eo.fitness () == operator[](j).fitness ())
|
||||
{
|
||||
operator[](j) = back ();
|
||||
pop_back ();
|
||||
}
|
||||
else
|
||||
j++;
|
||||
}
|
||||
/**
|
||||
* Default ctor.
|
||||
* The moeoObjectiveVectorComparator used to compare solutions is based on Pareto dominance
|
||||
*/
|
||||
moeoArchive() : eoPop < MOEOT >(), comparator(paretoComparator)
|
||||
{}
|
||||
|
||||
// Dominated ?
|
||||
bool dom = false;
|
||||
for (unsigned j = 0; j < size (); j++)
|
||||
if (operator [](j).fitness ().dominates (_eo.fitness ()))
|
||||
{
|
||||
dom = true;
|
||||
break;
|
||||
}
|
||||
if (!dom)
|
||||
push_back (_eo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the archive with a given population _pop
|
||||
* @param _pop the given population
|
||||
*/
|
||||
void update (const eoPop < EOT > &_pop)
|
||||
{
|
||||
for (unsigned i = 0; i < _pop.size (); i++)
|
||||
update (_pop[i]);
|
||||
}
|
||||
/**
|
||||
* Ctor
|
||||
* @param _comparator the moeoObjectiveVectorComparator used to compare solutions
|
||||
*/
|
||||
moeoArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator) : eoPop < MOEOT >(), comparator(_comparator)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* 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 i = 0; i<size(); i++)
|
||||
{
|
||||
if ( comparator(operator[](i).fitness(), _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 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
|
||||
*/
|
||||
void update (const MOEOT & _moeo)
|
||||
{
|
||||
// first step: removing the dominated solutions from the archive
|
||||
for (unsigned j=0; j<size();)
|
||||
{
|
||||
// if _moeo dominates the jth solution contained in the archive
|
||||
if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
|
||||
{
|
||||
operator[](j) = back();
|
||||
pop_back();
|
||||
}
|
||||
else if (_moeo.objectiveVector() == operator[](j).objectiveVector())
|
||||
{
|
||||
operator[](j) = back();
|
||||
pop_back();
|
||||
}
|
||||
else
|
||||
{
|
||||
j++;
|
||||
}
|
||||
}
|
||||
// second step: is _moeo dominated?
|
||||
bool dom = false;
|
||||
for (unsigned j=0; j<size(); j++)
|
||||
{
|
||||
// if the jth solution contained in the archive dominates _moeo
|
||||
if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
|
||||
{
|
||||
dom = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!dom)
|
||||
{
|
||||
push_back(_moeo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the archive with a given population _pop
|
||||
* @param _pop the given population
|
||||
*/
|
||||
void update (const eoPop < MOEOT > & _pop)
|
||||
{
|
||||
for (unsigned i=0; i<_pop.size(); i++)
|
||||
{
|
||||
update(_pop[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 i=0; i<size(); i++)
|
||||
{
|
||||
if (! _arch.contains(operator[](i).objectiveVector()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (unsigned i=0; i<_arch.size() ; i++)
|
||||
{
|
||||
if (! contains(_arch[i].objectiveVector()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** The moeoObjectiveVectorComparator used to compare solutions */
|
||||
moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
|
||||
/** A moeoObjectiveVectorComparator based on Pareto dominance (used as default) */
|
||||
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue