From 937ac7483d2ff4407d22a4dcbad0bd83b4f4ca70 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Tue, 2 Apr 2013 17:15:47 +0200 Subject: [PATCH] Add a wrapper to save a moeoMetric in an eoStat Example: moeoHyperVolumeDifferenceMetric * m_hypervolume = new moeoHyperVolumeDifferenceMetric(true,1.1); moeoBinaryMetricStat* hypervolume = new moeoBinaryMetricStat( *m_hypervolume, "hyp-vol" ); checkpoint.add( *hypervolume ); --- moeo/src/moeo | 1 + moeo/src/utils/moeoBinaryMetricStat.h | 59 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 moeo/src/utils/moeoBinaryMetricStat.h diff --git a/moeo/src/moeo b/moeo/src/moeo index 87f0c68db..b8878585a 100644 --- a/moeo/src/moeo +++ b/moeo/src/moeo @@ -207,6 +207,7 @@ #include #include #include +#include #include #include #include diff --git a/moeo/src/utils/moeoBinaryMetricStat.h b/moeo/src/utils/moeoBinaryMetricStat.h new file mode 100644 index 000000000..f60d20c29 --- /dev/null +++ b/moeo/src/utils/moeoBinaryMetricStat.h @@ -0,0 +1,59 @@ + + +template +class moeoBinaryMetricStat : public eoStat +{ +public: + /** The objective vector type of a solution */ + typedef typename MOEOT::ObjectiveVector ObjectiveVector; + + moeoBinaryMetricStat( + moeoVectorVsVectorBinaryMetric & metric, + std::string description, + T default_value = 0 + ) : + eoStat( default_value, description), + _metric(metric), + _first_gen(true) + {} + + virtual std::string className(void) const + { return "moeoBinaryMetricStat"; } + + + virtual void operator()( const eoPop & pop ) + { + if( pop.size() ) { + if( _first_gen ) { + _first_gen = false; + } else { + // creation of the two Pareto sets + std::vector < ObjectiveVector > from; + std::vector < ObjectiveVector > to; + for (unsigned int i=0; ivalue() = _metric(from,to); + } // if first gen + + // copy the pop + _prev_pop = pop; + } // if pop size + } + +protected: + /** binary metric comparing two Pareto sets */ + moeoVectorVsVectorBinaryMetric & _metric; + + /** (n-1) population */ + eoPop _prev_pop; + + /** is it the first generation ? */ + bool _first_gen; + +};