moeoCrowdingDiversityAssignment.h

00001 /*
00002 * <moeoCrowdingDiversityAssignment.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * Arnaud Liefooghe
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * data to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
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       // set diversity to 0
00120       for (unsigned int i=0; i<_pop.size(); i++)
00121         {
00122           _pop[i].diversity(0);
00123         }
00124       // for each objective
00125       for (unsigned int obj=0; obj<nObjectives; obj++)
00126         {
00127           // comparator
00128           moeoOneObjectiveComparator < MOEOT > objComp(obj);
00129           // sort
00130           std::sort(_pop.begin(), _pop.end(), objComp);
00131           // min & max
00132           min = _pop[0].objectiveVector()[obj];
00133           max = _pop[_pop.size()-1].objectiveVector()[obj];
00134           // set the diversity value to infiny for min and max
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 /*MOEOCROWDINGDIVERSITYASSIGNMENT_H_*/

Generated on Thu Mar 13 15:54:07 2008 for ParadisEO-MOEO-MultiObjectiveEvolvingObjects by  doxygen 1.4.7