diff --git a/moeo/src/comparator/moeoParetoDualObjectiveVectorComparator.h b/moeo/src/comparator/moeoParetoDualObjectiveVectorComparator.h new file mode 100644 index 000000000..e7e1ffd06 --- /dev/null +++ b/moeo/src/comparator/moeoParetoDualObjectiveVectorComparator.h @@ -0,0 +1,58 @@ +/* + +(c) 2010 Thales group + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; version 2 + of the License. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Contact: http://eodev.sourceforge.net + +Authors: + Johann Dréo + Pierre Savéant + +*/ + +#ifndef MOEOPARETODUALOBJECTIVEVECTORCOMPARATOR_H_ +#define MOEOPARETODUALOBJECTIVEVECTORCOMPARATOR_H_ + +#include + +/** + * This functor class allows to compare 2 objective vectors according to Pareto dominance. + */ +template < class ObjectiveVector > +class moeoParetoDualObjectiveVectorComparator : public moeoParetoObjectiveVectorComparator< ObjectiveVector > + { + public: + + /** + * Returns true if ov1 is dominated by ov2 + * @param _ov1 the first objective vector + * @param _ov2 the second objective vector + */ + bool operator()(const ObjectiveVector & ov1, const ObjectiveVector & ov2) + { + if( ov1.is_feasible() && !ov2.is_feasible() ) { + return false; + } else if( !ov1.is_feasible() && ov2.is_feasible() ) { + return true; + } else { + return moeoParetoObjectiveVectorComparator::operator()(ov1, ov2); + } + } + + }; + +#endif /*MOEOPARETODUALOBJECTIVEVECTORCOMPARATOR_H_*/ diff --git a/moeo/src/core/moeoDualRealObjectiveVector.h b/moeo/src/core/moeoDualRealObjectiveVector.h index 1ed62a8ff..64bf65f57 100644 --- a/moeo/src/core/moeoDualRealObjectiveVector.h +++ b/moeo/src/core/moeoDualRealObjectiveVector.h @@ -42,6 +42,8 @@ class moeoDualRealObjectiveVector : public moeoScalarObjectiveVector::size; using moeoScalarObjectiveVector < ObjectiveVectorTraits, T >::operator[]; @@ -73,28 +75,16 @@ class moeoDualRealObjectiveVector : public moeoScalarObjectiveVector & other) const { - // am I better than the other ? - - // if I'm feasible and the other is not - if( this->is_feasible() && !other.is_feasible() ) { - // no, the other has a better objective - return true; - - } else if( !this->is_feasible() && other.is_feasible() ) { - // yes, a feasible objective is always better than an unfeasible one - return false; - - } else { - // the two objective are of the same type - // lets rely on the comparator - moeoParetoObjectiveVectorComparator< moeoDualRealObjectiveVector > comparator; - return comparator(other, *this); - } + moeoParetoDualObjectiveVectorComparator cmp; + return cmp( other, *this ); } - //! Use when maximizing an + //! True if this is smaller than other bool operator<(const moeoDualRealObjectiveVector < ObjectiveVectorTraits > & other) const { // am I better than the other ? @@ -102,14 +92,15 @@ class moeoDualRealObjectiveVector : public moeoScalarObjectiveVectoris_feasible() && !other.is_feasible() ) { // no, the other has a better objective - return true; + return false; } else if( !this->is_feasible() && other.is_feasible() ) { // yes, a feasible objective is always better than an unfeasible one - return false; + return true; } else { moeoObjectiveObjectiveVectorComparator < moeoDualRealObjectiveVector < ObjectiveVectorTraits > > cmp; + // Returns true if this is smaller than other return cmp(*this, other); } } diff --git a/moeo/src/moeo b/moeo/src/moeo index bc7282ffa..3b310d64f 100644 --- a/moeo/src/moeo +++ b/moeo/src/moeo @@ -78,6 +78,7 @@ #include #include #include +#include #include #include #include