moeoComparator.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // moeoComparator.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 MOEOCOMPARATOR_H_
00014 #define MOEOCOMPARATOR_H_
00015 
00016 #include <eoFunctor.h>
00017 
00021 template < class MOEOT >
00022 class moeoComparator : public eoBF < const MOEOT &, const MOEOT &, const bool >
00023     {};
00024 
00025 
00029 template < class MOEOT >
00030 class moeoObjectiveComparator : public moeoComparator < MOEOT >
00031 {
00032 public:
00038     const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
00039     {
00040         return _moeo1.objectiveVector() > _moeo2.objectiveVector();
00041     }
00042 };
00043 
00047 template < class MOEOT >
00048 class moeoOneObjectiveComparator : public moeoComparator < MOEOT >
00049 {
00050 public:
00051 
00056     moeoOneObjectiveComparator(unsigned _obj) : obj(_obj)
00057     {
00058         if (obj > MOEOT::ObjectiveVector::nObjectives())
00059         {
00060             throw std::runtime_error("Problem with the index of objective in moeoOneObjectiveComparator");
00061         }
00062     }
00063 
00069     const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
00070     {
00071         return _moeo1.objectiveVector()[obj] > _moeo2.objectiveVector()[obj];
00072     }
00073 
00074 private:
00076     unsigned obj;
00077 
00078 };
00079 
00080 
00084 template < class MOEOT >
00085 class moeoFitnessThenDiversityComparator : public moeoComparator < MOEOT >
00086 {
00087 public:
00093     const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
00094     {
00095         if (_moeo1.fitness() == _moeo2.fitness())
00096         {
00097             return _moeo1.diversity() > _moeo2.diversity();
00098         }
00099         else
00100         {
00101             return _moeo1.fitness() > _moeo2.fitness();
00102         }
00103     }
00104 };
00105 
00106 
00110 template < class MOEOT >
00111 class moeoDiversityThenFitnessComparator : public moeoComparator < MOEOT >
00112 {
00113 public:
00119     const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
00120     {
00121         if (_moeo1.diversity() == _moeo2.diversity())
00122         {
00123             return _moeo1.fitness() > _moeo2.fitness();
00124         }
00125         else
00126         {
00127             return _moeo1.diversity() > _moeo2.diversity();
00128         }
00129     }
00130 };
00131 
00132 
00133 #endif /*MOEOCOMPARATOR_H_*/

Generated on Tue Apr 17 16:53:20 2007 for ParadisEO-MOEO by  doxygen 1.5.1