00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef MOEOCROWDINGDISTANCEDIVERSITYASSIGNMENT_H_
00014 #define MOEOCROWDINGDISTANCEDIVERSITYASSIGNMENT_H_
00015
00016 #include <eoPop.h>
00017 #include <comparator/moeoOneObjectiveComparator.h>
00018 #include <diversity/moeoDiversityAssignment.h>
00019
00024 template < class MOEOT >
00025 class moeoCrowdingDistanceDiversityAssignment : public moeoDiversityAssignment < MOEOT >
00026 {
00027 public:
00028
00030 typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00031
00032
00036 double inf() const
00037 {
00038 return std::numeric_limits<double>::max();
00039 }
00040
00041
00045 double tiny() const
00046 {
00047 return 1e-6;
00048 }
00049
00050
00055 void operator()(eoPop < MOEOT > & _pop)
00056 {
00057 if (_pop.size() <= 2)
00058 {
00059 for (unsigned int i=0; i<_pop.size(); i++)
00060 {
00061 _pop[i].diversity(inf());
00062 }
00063 }
00064 else
00065 {
00066 setDistances(_pop);
00067 }
00068 }
00069
00070
00078 void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
00079 {
00080 std::cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << std::endl;
00081 }
00082
00083
00084 protected:
00085
00090 virtual void setDistances (eoPop < MOEOT > & _pop)
00091 {
00092 double min, max, distance;
00093 unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
00094
00095 for (unsigned int i=0; i<_pop.size(); i++)
00096 {
00097 _pop[i].diversity(0);
00098 }
00099
00100 for (unsigned int obj=0; obj<nObjectives; obj++)
00101 {
00102
00103 moeoOneObjectiveComparator < MOEOT > objComp(obj);
00104
00105 std::sort(_pop.begin(), _pop.end(), objComp);
00106
00107 min = _pop[0].objectiveVector()[obj];
00108 max = _pop[_pop.size()-1].objectiveVector()[obj];
00109
00110 _pop[0].diversity(inf());
00111 _pop[_pop.size()-1].diversity(inf());
00112 for (unsigned int i=1; i<_pop.size()-1; i++)
00113 {
00114 distance = (_pop[i+1].objectiveVector()[obj] - _pop[i-1].objectiveVector()[obj]) / (max-min);
00115 _pop[i].diversity(_pop[i].diversity() + distance);
00116 }
00117 }
00118 }
00119
00120 };
00121
00122 #endif