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 MOEOFRONTBYFRONTCROWDINGDIVERSITYASSIGNMENT_H_
00039 #define MOEOFRONTBYFRONTCROWDINGDIVERSITYASSIGNMENT_H_
00040
00041 #include <diversity/moeoCrowdingDiversityAssignment.h>
00042 #include <comparator/moeoFitnessThenDiversityComparator.h>
00043
00049 template < class MOEOT >
00050 class moeoFrontByFrontCrowdingDiversityAssignment : public moeoCrowdingDiversityAssignment < MOEOT >
00051 {
00052 public:
00053
00055 typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00056
00057
00065 void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
00066 {
00067 std::cout << "WARNING : updateByDeleting not implemented in moeoFrontByFrontCrowdingDistanceDiversityAssignment" << std::endl;
00068 }
00069
00070
00071 private:
00072
00073 using moeoCrowdingDiversityAssignment < MOEOT >::inf;
00074 using moeoCrowdingDiversityAssignment < MOEOT >::tiny;
00075
00080 void setDistances (eoPop < MOEOT > & _pop)
00081 {
00082 unsigned int a,b;
00083 double min, max, distance;
00084 unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
00085
00086 for (unsigned int i=0; i<_pop.size(); i++)
00087 {
00088 _pop[i].diversity(0.0);
00089 }
00090
00091 moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator;
00092 std::sort(_pop.begin(), _pop.end(), fitnessComparator);
00093
00094 a = 0;
00095 while (a < _pop.size())
00096 {
00097 b = lastIndex(_pop,a);
00098
00099 if ((b-a) < 2)
00100 {
00101 for (unsigned int i=a; i<=b; i++)
00102 {
00103 _pop[i].diversity(inf());
00104 }
00105 }
00106
00107 else
00108 {
00109
00110 for (unsigned int obj=0; obj<nObjectives; obj++)
00111 {
00112
00113 moeoOneObjectiveComparator < MOEOT > objComp(obj);
00114 std::sort(_pop.begin()+a, _pop.begin()+b+1, objComp);
00115
00116 min = _pop[b].objectiveVector()[obj];
00117 max = _pop[a].objectiveVector()[obj];
00118
00119 if (min == max)
00120 {
00121 min -= tiny();
00122 max += tiny();
00123 }
00124
00125 _pop[a].diversity(inf());
00126 _pop[b].diversity(inf());
00127
00128 for (unsigned int i=a+1; i<b; i++)
00129 {
00130 distance = (_pop[i-1].objectiveVector()[obj] - _pop[i+1].objectiveVector()[obj]) / (max-min);
00131 _pop[i].diversity(_pop[i].diversity() + distance);
00132 }
00133 }
00134 }
00135
00136 a = b+1;
00137 }
00138 }
00139
00140
00146 unsigned int lastIndex (eoPop < MOEOT > & _pop, unsigned int _start)
00147 {
00148 unsigned int i=_start;
00149 while ( (i<_pop.size()-1) && (_pop[i].fitness()==_pop[i+1].fitness()) )
00150 {
00151 i++;
00152 }
00153 return i;
00154 }
00155
00156 };
00157
00158 #endif