Modifications 22/02/2007

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@183 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
legrand 2007-02-22 15:38:01 +00:00
commit 8312d91a84
19 changed files with 930 additions and 805 deletions

View file

@ -24,52 +24,54 @@
* but it can be replaced at will by any other class that implements the static functions defined therein.
* Some static funtions to access to the traits characteristics are re-defined in order not to write a lot of typedef's.
*/
template < class ObjectiveVectorTraits >
class moeoObjectiveVector
template < class ObjectiveVectorTraits > class moeoObjectiveVector
{
public:
/** The traits of objective vectors */
typedef ObjectiveVectorTraits Traits;
typedef ObjectiveVectorTraits Traits;
/**
* Parameters setting (for the objective vector of any solution)
* @param _nObjectives the number of objectives
* @param _bObjectives the min/max vector (true = min / false = max)
*/
static void setup(unsigned _nObjectives, std::vector < bool > & _bObjectives)
{
ObjectiveVectorTraits::setup(_nObjectives, _bObjectives);
}
static void setup (unsigned _nObjectives,
std::vector < bool > &_bObjectives)
{
ObjectiveVectorTraits::setup (_nObjectives, _bObjectives);
}
/**
* Returns the number of objectives
*/
static unsigned nObjectives()
{
return ObjectiveVectorTraits::nObjectives();
}
static unsigned nObjectives ()
{
return ObjectiveVectorTraits::nObjectives ();
}
/**
* Returns true if the _ith objective have to be minimized
* @param _i the index
*/
static bool minimizing(unsigned _i) {
return ObjectiveVectorTraits::minimizing(_i);
}
static bool minimizing (unsigned _i)
{
return ObjectiveVectorTraits::minimizing (_i);
}
/**
* Returns true if the _ith objective have to be maximized
* @param _i the index
*/
static bool maximizing(unsigned _i) {
return ObjectiveVectorTraits::maximizing(_i);
}
static bool maximizing (unsigned _i)
{
return ObjectiveVectorTraits::maximizing (_i);
}
};
@ -77,122 +79,159 @@ public:
* This class allows to represent a solution in the objective space (phenotypic representation) by a std::vector of doubles,
* i.e. that an objective value is represented using a double, and this for any objective.
*/
template < class ObjectiveVectorTraits >
class moeoObjectiveVectorDouble : public moeoObjectiveVector < ObjectiveVectorTraits >, public std::vector < double >
template < class ObjectiveVectorTraits > class moeoObjectiveVectorDouble:public moeoObjectiveVector < ObjectiveVectorTraits >,
public std::vector <
double >
{
public:
using std::vector< double >::size;
using std::vector< double >::operator[];
public:
using
std::vector < double >::size;
using
std::vector < double >::operator[];
/**
* Ctor
*/
moeoObjectiveVectorDouble() : std::vector < double > (ObjectiveVectorTraits::nObjectives(), 0.0) {}
moeoObjectiveVectorDouble ():
std::vector < double >(ObjectiveVectorTraits::nObjectives (), 0.0)
{
}
/**
* Ctor from a vector of doubles
* @param _v the std::vector < double >
*/
moeoObjectiveVectorDouble(std::vector <double> & _v) : std::vector < double > (_v) {}
moeoObjectiveVectorDouble (std::vector < double >&_v):
std::vector < double >(_v)
{
}
/**
* Returns true if the current objective vector dominates _other according to the Pareto dominance relation
* (but it's better to use a moeoObjectiveVectorComparator object to compare solutions)
* @param _other the other moeoObjectiveVectorDouble object to compare with
*/
bool dominates(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
moeoParetoObjectiveVectorComparator < moeoObjectiveVectorDouble<ObjectiveVectorTraits> > comparator;
return comparator(*this, _other)==1;
}
bool
dominates (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
&_other) const
{
moeoParetoObjectiveVectorComparator <
moeoObjectiveVectorDouble <
ObjectiveVectorTraits > >
comparator;
return
comparator (*this, _other) == 1;
}
/**
* Returns true if the current objective vector is equal to _other (according to a tolerance value)
* @param _other the other moeoObjectiveVectorDouble object to compare with
*/
bool operator==(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
for (unsigned i=0; i < size(); i++)
{
if ( fabs(operator[](i) - _other[i]) > ObjectiveVectorTraits::tolerance() )
{
return false;
}
}
return true;
}
bool
operator== (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
&_other) const
{
for (unsigned i = 0; i < size (); i++)
{
if (fabs (operator[](i) - _other[i]) >
ObjectiveVectorTraits::tolerance ())
{
return false;
}
}
return
true;
}
/**
* Returns true if the current objective vector is different than _other (according to a tolerance value)
* @param _other the other moeoObjectiveVectorDouble object to compare with
*/
bool operator!=(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
return ! operator==(_other);
}
bool
operator!= (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
&_other) const
{
return !
operator== (_other);
}
/**
* Returns true if the current objective vector is smaller than _other on the first objective, then on the second, and so on
* (can be usefull for sorting/printing)
* @param _other the other moeoObjectiveVectorDouble object to compare with
*/
bool operator<(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
for (unsigned i=0; i < size(); i++)
{
if ( fabs(operator[](i) - _other[i]) > ObjectiveVectorTraits::tolerance() )
{
if (operator[](i) < _other[i])
{
return true;
}
else
{
return false;
}
}
}
*/
bool
operator< (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
&_other) const
{
for (unsigned i = 0; i < size (); i++)
{
if (fabs (operator[](i) - _other[i]) >
ObjectiveVectorTraits::tolerance ())
{
if (operator[](i) < _other[i])
{
return true;
}
else
{
return false;
}
}
}
}
return false;
}
/**
* Returns true if the current objective vector is greater than _other on the first objective, then on the second, and so on
* (can be usefull for sorting/printing)
* @param _other the other moeoObjectiveVectorDouble object to compare with
*/
bool operator>(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
return _other < *this;
}
bool
operator> (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
&_other) const
{
return
_other < *
this;
}
/**
* Returns true if the current objective vector is smaller than or equal to _other on the first objective, then on the second, and so on
* (can be usefull for sorting/printing)
* @param _other the other moeoObjectiveVectorDouble object to compare with
*/
bool operator<=(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
return operator==(_other) || operator<(_other);
}
bool
operator<= (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
&_other) const
{
return
operator== (_other) ||
operator< (_other);
}
/**
* Returns true if the current objective vector is greater than or equal to _other on the first objective, then on the second, and so on
* (can be usefull for sorting/printing)
* @param _other the other moeoObjectiveVectorDouble object to compare with
*/
bool operator>=(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
return operator==(_other) || operator>(_other);
}
bool
operator>= (const moeoObjectiveVectorDouble < ObjectiveVectorTraits >
&_other) const
{
return
operator== (_other) ||
operator> (_other);
}
};
@ -203,13 +242,15 @@ public:
* @param _objectiveVector the objective vector to write
*/
template < class ObjectiveVectorTraits >
std::ostream & operator<<(std::ostream & _os, const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _objectiveVector)
std::ostream & operator<< (std::ostream & _os,
const moeoObjectiveVectorDouble <
ObjectiveVectorTraits > &_objectiveVector)
{
for (unsigned i=0; i<_objectiveVector.size(); i++)
{
_os << _objectiveVector[i] << ' ';
}
return _os;
for (unsigned i = 0; i < _objectiveVector.size (); i++)
{
_os << _objectiveVector[i] << ' ';
}
return _os;
}
/**
@ -218,14 +259,16 @@ std::ostream & operator<<(std::ostream & _os, const moeoObjectiveVectorDouble <
* @param _objectiveVector the objective vector to read
*/
template < class ObjectiveVectorTraits >
std::istream & operator>>(std::istream & _is, moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _objectiveVector)
std::istream & operator>> (std::istream & _is,
moeoObjectiveVectorDouble <
ObjectiveVectorTraits > &_objectiveVector)
{
_objectiveVector = moeoObjectiveVectorDouble < ObjectiveVectorTraits > ();
for (unsigned i=0; i<_objectiveVector.size(); i++)
{
_is >> _objectiveVector[i];
}
return _is;
_objectiveVector = moeoObjectiveVectorDouble < ObjectiveVectorTraits > ();
for (unsigned i = 0; i < _objectiveVector.size (); i++)
{
_is >> _objectiveVector[i];
}
return _is;
}
#endif /*MOEOOBJECTIVEVECTOR_H_*/
#endif /*MOEOOBJECTIVEVECTOR_H_ */