00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef moeoNDSorting_h
00014 #define moeoNDSorting_h
00015
00016 #include <cfloat>
00017 #include <eoNDSorting.h>
00018
00019 # define INF 1.0e14 // DBL_MAX
00020
00026 template < class EOT > class moeoNDSorting_II:public eoNDSorting < EOT >
00027 {
00028 public:
00029
00033 moeoNDSorting_II (bool nasty_flag_ = false):eoNDSorting < EOT >
00034 (nasty_flag_)
00035 {
00036 }
00037
00041 typedef std::pair < double, unsigned >double_index_pair;
00042
00046 class compare_nodes
00047 {
00048 public:bool operator () (const double_index_pair & a,
00049 const double_index_pair & b) const
00050 {
00051 return a.first < b.first;
00052 }
00053 };
00054
00056 std::vector < double >niche_penalty (const std::vector < unsigned >&_cf,
00057 const eoPop < EOT > &_pop)
00058 {
00059 typedef typename EOT::Fitness::fitness_traits traits;
00060 unsigned i;
00061 std::vector < double >niche_count (_cf.size (), 0.);
00062
00063
00064 unsigned nObjectives = traits::nObjectives ();
00065
00066 for (unsigned o = 0; o < nObjectives; ++o)
00067 {
00068 std::vector < std::pair < double,
00069 unsigned > >performance (_cf.size ());
00070 for (i = 0; i < _cf.size (); ++i)
00071 {
00072 performance[i].first = _pop[_cf[i]].fitness ()[o];
00073 performance[i].second = i;
00074 }
00075
00076 std::sort (performance.begin (), performance.end (), compare_nodes ());
00077
00078
00079 niche_count[performance[0].second] = INF;
00080 niche_count[performance.back ().second] = INF;
00081
00082 if (performance[0].first != performance.back ().first)
00083 {
00084 for (i = 1; i < _cf.size () - 1; ++i)
00085 {
00086 if (niche_count[performance[i].second] != INF)
00087 {
00088 niche_count[performance[i].second] +=
00089 (performance[i + 1].first -
00090 performance[i -
00091 1].first) / (performance.back ().first -
00092 performance[0].first);
00093 }
00094 }
00095 }
00096 }
00097
00098
00099 for (i = 0; i < niche_count.size (); ++i)
00100 {
00101 niche_count[i] = INF - niche_count[i];
00102 }
00103
00104 return niche_count;
00105 }
00106 };
00107
00108 #endif