- Main Page
- Classes
- Files

- Search for |

# moeoCrowdingDistanceDiversityAssignment.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // moeoCrowdingDistanceDiversityAssignment.h
    00005 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
    00006 /*
    00007     This library...
    00008
    00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
    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         // set diversity to 0
    00095         for (unsigned int i=0; i<_pop.size(); i++)
    00096         {
    00097             _pop[i].diversity(0);
    00098         }
    00099         // for each objective
    00100         for (unsigned int obj=0; obj<nObjectives; obj++)
    00101         {
    00102             // comparator
    00103             moeoOneObjectiveComparator < MOEOT > objComp(obj);
    00104             // sort
    00105             std::sort(_pop.begin(), _pop.end(), objComp);
    00106             // min & max
    00107             min = _pop[0].objectiveVector()[obj];
    00108             max = _pop[_pop.size()-1].objectiveVector()[obj];
    00109             // set the diversity value to infiny for min and max
    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 /*MOEOCROWDINGDISTANCEDIVERSITYASSIGNMENT_H_*/