From 32b4f077c4ee70d64dd616518e98710967950891 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Thu, 13 Jun 2013 10:36:33 +0200 Subject: [PATCH] Move the dual hypervolume continuator in a separated file --- moeo/src/continue/moeoDualHypContinue.h | 121 ++++++++++++++++++++++++ moeo/src/continue/moeoHypContinue.h | 111 ++++------------------ 2 files changed, 139 insertions(+), 93 deletions(-) create mode 100644 moeo/src/continue/moeoDualHypContinue.h diff --git a/moeo/src/continue/moeoDualHypContinue.h b/moeo/src/continue/moeoDualHypContinue.h new file mode 100644 index 000000000..99c33d45f --- /dev/null +++ b/moeo/src/continue/moeoDualHypContinue.h @@ -0,0 +1,121 @@ +/* + +(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 _moeoDualHypContinue_h +#define _moeoDualHypContinue_h + +#include + +/** + Continues until the (feasible or unfeasible) given Pareto set is reached. + + + @ingroup Continuators + */ +template< class MOEOT, class MetricT = moeoDualHyperVolumeDifferenceMetric > +class moeoDualHypContinue: public moeoHypContinue +{ +protected: + bool is_feasible; + + using moeoHypContinue::arch; + using moeoHypContinue::OptimSet; + + using moeoHypContinue::pareto; + using moeoHypContinue::is_null_hypervolume; + +public: + typedef typename MOEOT::ObjectiveVector ObjectiveVector; + typedef typename ObjectiveVector::Type AtomType; + + /** A continuator that stops once a given Pareto front has been reached + * + * You should specify the feasibility of the targeted front. + * NOTE: the MOEOT::ObjectiveVector is supposed to implement the moeoDualRealObjectiveVector interface. + * + */ + moeoDualHypContinue( const std::vector & _OptimVec, bool _is_feasible, moeoArchive < MOEOT > & _archive, bool _normalize=true, double _rho=1.1 ) + : moeoHypContinue( _OptimVec, _archive, _normalize, _rho ), + is_feasible(_is_feasible) + { + assert( _OptimVec.size() > 0); + vectorToParetoSet(_OptimVec); + } + + /** A continuator that stops once a given Pareto front has been reached + * + * You should specify the feasibility of the targeted front. + * NOTE: the MOEOT::ObjectiveVector is supposed to implement the moeoDualRealObjectiveVector interface. + * + */ + moeoDualHypContinue( const std::vector & _OptimVec, bool _is_feasible, moeoArchive < MOEOT > & _archive, bool _normalize=true, ObjectiveVector& _ref_point=NULL ) + : moeoHypContinue( _OptimVec, _archive, _normalize, _ref_point ), + is_feasible(_is_feasible) + { + assert( _OptimVec.size() > 0); + vectorToParetoSet(_OptimVec); + } + + + /** Returns false when a ParetoSet is reached. */ + virtual bool operator() ( const eoPop& /*_pop*/ ) + { + std::vector bestCurrentParetoSet = pareto( arch ); + +#ifndef NDEBUG + assert( bestCurrentParetoSet.size() > 0 ); + for( unsigned int i=1; i & _OptimVec) + { + unsigned dim = (unsigned)(_OptimVec.size()/ObjectiveVector::Traits::nObjectives()); + OptimSet.resize(dim); + + unsigned k=0; + for(size_t i=0; i < dim; i++) { + for (size_t j=0; j < ObjectiveVector::Traits::nObjectives(); j++) { + // Use the feasibility declaration of an eoDualFitness + OptimSet[i][j] = AtomType(_OptimVec[k++], is_feasible); + } + } + } +}; + +#endif diff --git a/moeo/src/continue/moeoHypContinue.h b/moeo/src/continue/moeoHypContinue.h index 228006d3a..bbc1a799b 100644 --- a/moeo/src/continue/moeoHypContinue.h +++ b/moeo/src/continue/moeoHypContinue.h @@ -36,7 +36,6 @@ //----------------------------------------------------------------------------- - #ifndef _moeoHypContinue_h #define _moeoHypContinue_h @@ -60,17 +59,29 @@ public: /// Ctor moeoHypContinue( const std::vector & _OptimVec, moeoArchive < MOEOT > & _archive, bool _normalize=true, double _rho=1.1) - : eoContinue(), arch(_archive), metric(_normalize,_rho) + : eoContinue(), arch(_archive), default_metric(new MetricT(_normalize,_rho)), metric(*default_metric) { vectorToParetoSet(_OptimVec); } moeoHypContinue( const std::vector & _OptimVec, moeoArchive < MOEOT > & _archive, bool _normalize=true, ObjectiveVector& _ref_point=NULL) - : eoContinue (), arch(_archive), metric(_normalize,_ref_point) + : eoContinue(), arch(_archive), default_metric(new MetricT(_normalize,_ref_point)), metric(*default_metric) { vectorToParetoSet(_OptimVec); } + moeoHypContinue( MetricT& _metric, const std::vector & _OptimVec, moeoArchive < MOEOT > & _archive ) + : eoContinue(), arch(_archive), default_metric(NULL), metric(_metric) + { + vectorToParetoSet(_OptimVec); + } + + ~moeoHypContinue() + { + if( default_metric != NULL ) { + delete default_metric; + } + } /** Returns false when a ParetoSet is reached. */ virtual bool operator() ( const eoPop& /*_pop*/ ) @@ -88,8 +99,8 @@ protected: { std::vector < ObjectiveVector > bestCurrentParetoSet; - for (size_t i=0; i & arch; - MetricT metric; + MetricT* default_metric; + MetricT& metric; std::vector OptimSet; }; -/** - Continues until the (feasible or unfeasible) given Pareto set is reached. - - - @ingroup Continuators - */ -template< class MOEOT, class MetricT = moeoDualHyperVolumeDifferenceMetric > -class moeoDualHypContinue: public moeoHypContinue -{ -protected: - bool is_feasible; - - using moeoHypContinue::arch; - using moeoHypContinue::OptimSet; - - using moeoHypContinue::pareto; - using moeoHypContinue::is_null_hypervolume; - -public: - typedef typename MOEOT::ObjectiveVector ObjectiveVector; - typedef typename ObjectiveVector::Type AtomType; - - /** A continuator that stops once a given Pareto front has been reached - * - * You should specify the feasibility of the targeted front. - * NOTE: the MOEOT::ObjectiveVector is supposed to implement the moeoDualRealObjectiveVector interface. - * - */ - moeoDualHypContinue( const std::vector & _OptimVec, bool _is_feasible, moeoArchive < MOEOT > & _archive, bool _normalize=true, double _rho=1.1 ) - : moeoHypContinue( _OptimVec, _archive, _normalize, _rho ), is_feasible(_is_feasible) - { - assert( _OptimVec.size() > 0); - vectorToParetoSet(_OptimVec); - } - - /** A continuator that stops once a given Pareto front has been reached - * - * You should specify the feasibility of the targeted front. - * NOTE: the MOEOT::ObjectiveVector is supposed to implement the moeoDualRealObjectiveVector interface. - * - */ - moeoDualHypContinue( const std::vector & _OptimVec, bool _is_feasible, moeoArchive < MOEOT > & _archive, bool _normalize=true, ObjectiveVector& _ref_point=NULL ) - : moeoHypContinue( _OptimVec, _archive, _normalize, _ref_point ), is_feasible(_is_feasible) - { - assert( _OptimVec.size() > 0); - vectorToParetoSet(_OptimVec); - } - - /** Returns false when a ParetoSet is reached. */ - virtual bool operator() ( const eoPop& /*_pop*/ ) - { - std::vector bestCurrentParetoSet = pareto( arch ); - -#ifndef NDEBUG - assert( bestCurrentParetoSet.size() > 0 ); - for( unsigned int i=1; i & _OptimVec) - { - unsigned dim = (unsigned)(_OptimVec.size()/ObjectiveVector::Traits::nObjectives()); - OptimSet.resize(dim); - - unsigned k=0; - for(size_t i=0; i < dim; i++) { - for (size_t j=0; j < ObjectiveVector::Traits::nObjectives(); j++) { - // Use the feasibility declaration of an eoDualFitness - OptimSet[i][j] = AtomType(_OptimVec[k++], is_feasible); - } - } - } -}; - #endif