From c44264e703e5daafe4243217185c21b01adaff15 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Thu, 13 Jun 2013 10:00:15 +0200 Subject: [PATCH] Move the hyper volume dual difference metric in a separated file --- .../moeoDualHyperVolumeDifferenceMetric.h | 117 ++++++++++++++++++ .../metric/moeoHyperVolumeDifferenceMetric.h | 86 ------------- 2 files changed, 117 insertions(+), 86 deletions(-) create mode 100644 moeo/src/metric/moeoDualHyperVolumeDifferenceMetric.h diff --git a/moeo/src/metric/moeoDualHyperVolumeDifferenceMetric.h b/moeo/src/metric/moeoDualHyperVolumeDifferenceMetric.h new file mode 100644 index 000000000..b7774bb51 --- /dev/null +++ b/moeo/src/metric/moeoDualHyperVolumeDifferenceMetric.h @@ -0,0 +1,117 @@ +/* + +(c) 2013 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 MOEODUALHYPERVOLUMEDIFFERENCEMETRIC_H_ +#define MOEODUALHYPERVOLUMEDIFFERENCEMETRIC_H_ + +#include + + +template +class moeoDualHyperVolumeDifferenceMetric : public moeoHyperVolumeDifferenceMetric +{ +protected: + using moeoHyperVolumeDifferenceMetric::rho; + using moeoHyperVolumeDifferenceMetric::normalize; + using moeoHyperVolumeDifferenceMetric::ref_point; + using moeoHyperVolumeDifferenceMetric::bounds; + +public: + + typedef typename ObjectiveVector::Type Type; + + moeoDualHyperVolumeDifferenceMetric( bool _normalize=true, double _rho=1.1) + : moeoHyperVolumeDifferenceMetric(_normalize, _rho) + { + + } + + moeoDualHyperVolumeDifferenceMetric( bool _normalize/*=true*/, ObjectiveVector& _ref_point/*=NULL*/ ) + : moeoHyperVolumeDifferenceMetric( _normalize, _ref_point ) + { + + } + + /** + * calculates and returns the HyperVolume value of a pareto front + * @param _set1 the vector contains all objective Vector of the first pareto front + * @param _set2 the vector contains all objective Vector of the second pareto front + */ + virtual double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) + { +#ifndef NDEBUG + // the two sets must be homogeneous in feasibility + assert( _set1.size() > 0 ); + for( unsigned int i=1; i<_set1.size(); ++i ) { + assert( _set1[i].is_feasible() == _set1[0].is_feasible() ); + } + assert( _set2.size() > 0 ); + for( unsigned int i=1; i<_set2.size(); ++i ) { + assert( _set2[i].is_feasible() == _set2[0].is_feasible() ); + } + // and they must have the same feasibility + assert( _set1[0].is_feasible() == _set2[0].is_feasible() ); +#endif + bool feasible = _set1[0].is_feasible(); + + double hypervolume_set1; + double hypervolume_set2; + + if(rho >= 1.0){ + //determine bounds + setup(_set1, _set2); + //determine reference point + for (unsigned int i=0; i unaryMetric(ref_point, bounds); + hypervolume_set1 = unaryMetric(_set1); + hypervolume_set2 = unaryMetric(_set2); + + return hypervolume_set1 - hypervolume_set2; + } +}; + +#endif /*MOEODUALHYPERVOLUMEDIFFERENCEMETRIC_H_*/ diff --git a/moeo/src/metric/moeoHyperVolumeDifferenceMetric.h b/moeo/src/metric/moeoHyperVolumeDifferenceMetric.h index 64a001281..ad3336cd7 100644 --- a/moeo/src/metric/moeoHyperVolumeDifferenceMetric.h +++ b/moeo/src/metric/moeoHyperVolumeDifferenceMetric.h @@ -197,90 +197,4 @@ class moeoHyperVolumeDifferenceMetric : public moeoVectorVsVectorBinaryMetric < }; - -template -class moeoDualHyperVolumeDifferenceMetric : public moeoHyperVolumeDifferenceMetric -{ -protected: - using moeoHyperVolumeDifferenceMetric::rho; - using moeoHyperVolumeDifferenceMetric::normalize; - using moeoHyperVolumeDifferenceMetric::ref_point; - using moeoHyperVolumeDifferenceMetric::bounds; - -public: - - typedef typename ObjectiveVector::Type Type; - - moeoDualHyperVolumeDifferenceMetric( bool _normalize=true, double _rho=1.1) - : moeoHyperVolumeDifferenceMetric(_normalize, _rho) - { - - } - - moeoDualHyperVolumeDifferenceMetric( bool _normalize/*=true*/, ObjectiveVector& _ref_point/*=NULL*/ ) - : moeoHyperVolumeDifferenceMetric( _normalize, _ref_point ) - { - - } - - /** - * calculates and returns the HyperVolume value of a pareto front - * @param _set1 the vector contains all objective Vector of the first pareto front - * @param _set2 the vector contains all objective Vector of the second pareto front - */ - virtual double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) - { -#ifndef NDEBUG - // the two sets must be homogeneous in feasibility - assert( _set1.size() > 0 ); - for( unsigned int i=1; i<_set1.size(); ++i ) { - assert( _set1[i].is_feasible() == _set1[0].is_feasible() ); - } - assert( _set2.size() > 0 ); - for( unsigned int i=1; i<_set2.size(); ++i ) { - assert( _set2[i].is_feasible() == _set2[0].is_feasible() ); - } - // and they must have the same feasibility - assert( _set1[0].is_feasible() == _set2[0].is_feasible() ); -#endif - bool feasible = _set1[0].is_feasible(); - - double hypervolume_set1; - double hypervolume_set2; - - if(rho >= 1.0){ - //determine bounds - setup(_set1, _set2); - //determine reference point - for (unsigned int i=0; i unaryMetric(ref_point, bounds); - hypervolume_set1 = unaryMetric(_set1); - hypervolume_set2 = unaryMetric(_set2); - - return hypervolume_set1 - hypervolume_set2; - } -}; - #endif /*MOEOHYPERVOLUMEMETRIC_H_*/