diff --git a/moeo/src/core/moeoDualRealObjectiveVector.h b/moeo/src/core/moeoDualRealObjectiveVector.h new file mode 100644 index 000000000..9be12d8f7 --- /dev/null +++ b/moeo/src/core/moeoDualRealObjectiveVector.h @@ -0,0 +1,114 @@ +/* + +(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 + +*/ + +#ifndef _DUALREALOBJECTIVEVECTOR_H_ +#define _DUALREALOBJECTIVEVECTOR_H_ + +#include +#include + +#include + +#include +#include +#include + +template < class ObjectiveVectorTraits > +class moeoDualRealObjectiveVector : public moeoScalarObjectiveVector +{ + protected: + bool _is_feasible; + + public: + + moeoDualRealObjectiveVector(double value=0.0) : moeoScalarObjectiveVector(value, false) {} + + bool is_feasible() const + { +#ifndef NDEBUG + // if the feasibility is correctly assigned, + // every scalar's feasibility should be equal to the objective vector + for( typename moeoDualRealObjectiveVector::const_iterator it = this->begin(), end = this->end(); it != end; ++it ) { + assert( it->is_feasible() == _is_feasible ); + } +#endif + return _is_feasible; + } + + //! One should ensure that feasabilities of scalars are all the same + void is_feasible( bool value ) + { +#ifndef NDEBUG + for( typename moeoDualRealObjectiveVector::const_iterator it = this->begin(), end = this->end(); it != end; ++it ) { + assert( it->is_feasible() == value ); + } +#endif + _is_feasible = value; + } + + bool dominates(const moeoRealObjectiveVector < ObjectiveVectorTraits > & 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); + } + } + + //! Use when maximizing an + bool operator<(const moeoDualRealObjectiveVector < ObjectiveVectorTraits > & 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 { + moeoObjectiveObjectiveVectorComparator < moeoDualRealObjectiveVector < ObjectiveVectorTraits > > cmp; + return cmp(*this, other); + } + } +}; + + +#endif /*_DUALREALOBJECTIVEVECTOR_H_*/ diff --git a/moeo/src/moeo b/moeo/src/moeo index 9ac18c050..b2e7b4db1 100644 --- a/moeo/src/moeo +++ b/moeo/src/moeo @@ -88,7 +88,9 @@ #include #include #include +#include #include +#include #include #include