From 9da980e853274220aa2c788980888c41431bc3c9 Mon Sep 17 00:00:00 2001 From: legrand Date: Thu, 21 Dec 2006 14:01:34 +0000 Subject: [PATCH] moeoNDSorting for NSGAII added git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@116 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-moeo/src/moeoNDSorting.h | 91 ++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 trunk/paradiseo-moeo/src/moeoNDSorting.h diff --git a/trunk/paradiseo-moeo/src/moeoNDSorting.h b/trunk/paradiseo-moeo/src/moeoNDSorting.h new file mode 100644 index 000000000..926c763f0 --- /dev/null +++ b/trunk/paradiseo-moeo/src/moeoNDSorting.h @@ -0,0 +1,91 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +/* ----------------------------------------------------------------------------- + moeoNDSorting.h + (c) Deneche Abdelhakim, 2006 + + Contact: paradiseo-help@lists.gforge.inria.fr +*/ +//------------------------------------------------------------------------------ + +#ifndef moeoNDSorting_h +#define moeoNDSorting_h + +#include +#include + +# define INF 1.0e14 // DBL_MAX + +/** @brief Fast Elitist Non-Dominant Sorting Genetic Algorithm + + Note : This is a corrected version of the original eoNDSorting_II class + . + @see eoNDSorting_II +*/ +template +class moeoNDSorting_II : public eoNDSorting +{ + public: + + moeoNDSorting_II(bool nasty_flag_ = false) : eoNDSorting(nasty_flag_) {} + + typedef std::pair double_index_pair; + + class compare_nodes + { + public : + bool operator()(const double_index_pair& a, const double_index_pair& b) const + { + return a.first < b.first; + } + }; + + /// _cf points into the elements that consist of the current front + std::vector niche_penalty(const std::vector& _cf, const eoPop& _pop) + { + typedef typename EOT::Fitness::fitness_traits traits; + unsigned i; + std::vector niche_count(_cf.size(), 0.); + + + unsigned nObjectives = traits::nObjectives(); //_pop[_cf[0]].fitness().size(); + + for (unsigned o = 0; o < nObjectives; ++o) + { + std::vector > performance(_cf.size()); + for (i =0; i < _cf.size(); ++i) + { + performance[i].first = _pop[_cf[i]].fitness()[o]; + performance[i].second = i; + } + + std::sort(performance.begin(), performance.end(), compare_nodes()); // a lambda operator would've been nice here + + // set boundary at INF (so it will get chosen over all the others + niche_count[performance[0].second] = INF; + niche_count[performance.back().second] = INF; + + if (performance[0].first != performance.back().first) + { + for (i = 1; i < _cf.size()-1; ++i) + { + if (niche_count[performance[i].second] != INF) + { + niche_count[performance[i].second] += (performance[i+1].first - performance[i-1].first)/ + (performance.back().first-performance[0].first); + } + } + } + } + + // transform niche_count into penality + for (i = 0; i < niche_count.size(); ++i) + { + niche_count[i] = INF - niche_count[i]; + } + + return niche_count; + } +}; + +#endif