Use a specific comparator for the dual objective vector

Because we want to have a separated comparator to use in the archive or…
This commit is contained in:
Johann Dreo 2013-06-25 15:41:29 +02:00
commit 0567d7be6c
3 changed files with 70 additions and 20 deletions

View file

@ -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 <johann.dreo@thalesgroup.com>
Pierre Savéant <pierre.saveant@thalesgroup.com>
*/
#ifndef MOEOPARETODUALOBJECTIVEVECTORCOMPARATOR_H_
#define MOEOPARETODUALOBJECTIVEVECTORCOMPARATOR_H_
#include <comparator/moeoParetoObjectiveVectorComparator.h>
/**
* 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<ObjectiveVector>::operator()(ov1, ov2);
}
}
};
#endif /*MOEOPARETODUALOBJECTIVEVECTORCOMPARATOR_H_*/

View file

@ -42,6 +42,8 @@ class moeoDualRealObjectiveVector : public moeoScalarObjectiveVector<ObjectiveVe
bool _is_feasible;
public:
typedef ObjectiveVectorTraits Traits;
typedef T Base;
using moeoScalarObjectiveVector < ObjectiveVectorTraits, T >::size;
using moeoScalarObjectiveVector < ObjectiveVectorTraits, T >::operator[];
@ -73,28 +75,16 @@ class moeoDualRealObjectiveVector : public moeoScalarObjectiveVector<ObjectiveVe
_is_feasible = value;
}
/**
* Returns true if the current objective vector dominates _other according to the Pareto dominance relation
*/
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<ObjectiveVectorTraits> > comparator;
return comparator(other, *this);
}
moeoParetoDualObjectiveVectorComparator<moeoDualRealObjectiveVector> 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 moeoScalarObjectiveVector<ObjectiveVe
// 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;
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);
}
}

View file

@ -78,6 +78,7 @@
#include <comparator/moeoObjectiveVectorComparator.h>
#include <comparator/moeoOneObjectiveComparator.h>
#include <comparator/moeoParetoObjectiveVectorComparator.h>
#include <comparator/moeoParetoDualObjectiveVectorComparator.h>
#include <comparator/moeoPtrComparator.h>
#include <comparator/moeoStrictObjectiveVectorComparator.h>
#include <comparator/moeoWeakObjectiveVectorComparator.h>