00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef MOEOCROWDINGDIVERSITYASSIGNMENT_H_
00039 #define MOEOCROWDINGDIVERSITYASSIGNMENT_H_
00040
00041 #include <eoPop.h>
00042 #include <comparator/moeoOneObjectiveComparator.h>
00043 #include <diversity/moeoDiversityAssignment.h>
00044
00049 template < class MOEOT >
00050 class moeoCrowdingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
00051 {
00052 public:
00053
00055 typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00056
00057
00061 double inf() const
00062 {
00063 return std::numeric_limits<double>::max();
00064 }
00065
00066
00070 double tiny() const
00071 {
00072 return 1e-6;
00073 }
00074
00075
00080 void operator()(eoPop < MOEOT > & _pop)
00081 {
00082 if (_pop.size() <= 2)
00083 {
00084 for (unsigned int i=0; i<_pop.size(); i++)
00085 {
00086 _pop[i].diversity(inf());
00087 }
00088 }
00089 else
00090 {
00091 setDistances(_pop);
00092 }
00093 }
00094
00095
00103 void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
00104 {
00105 std::cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << std::endl;
00106 }
00107
00108
00109 protected:
00110
00115 virtual void setDistances (eoPop < MOEOT > & _pop)
00116 {
00117 double min, max, distance;
00118 unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
00119
00120 for (unsigned int i=0; i<_pop.size(); i++)
00121 {
00122 _pop[i].diversity(0);
00123 }
00124
00125 for (unsigned int obj=0; obj<nObjectives; obj++)
00126 {
00127
00128 moeoOneObjectiveComparator < MOEOT > objComp(obj);
00129
00130 std::sort(_pop.begin(), _pop.end(), objComp);
00131
00132 min = _pop[0].objectiveVector()[obj];
00133 max = _pop[_pop.size()-1].objectiveVector()[obj];
00134
00135 _pop[0].diversity(inf());
00136 _pop[_pop.size()-1].diversity(inf());
00137 for (unsigned int i=1; i<_pop.size()-1; i++)
00138 {
00139 distance = (_pop[i+1].objectiveVector()[obj] - _pop[i-1].objectiveVector()[obj]) / (max-min);
00140 _pop[i].diversity(_pop[i].diversity() + distance);
00141 }
00142 }
00143 }
00144
00145 };
00146
00147 #endif