moeoGDominanceObjectiveVectorComparator.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // moeoGDominanceObjectiveVectorComparator.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 MOEOGDOMINANCEOBJECTIVEVECTORCOMPARATOR_H_
00014 #define MOEOGDOMINANCEOBJECTIVEVECTORCOMPARATOR_H_
00015 
00016 #include <comparator/moeoObjectiveVectorComparator.h>
00017 
00024 template < class ObjectiveVector >
00025 class moeoGDominanceObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
00026 {
00027 public:
00028 
00033     moeoGDominanceObjectiveVectorComparator(ObjectiveVector & _ref) : ref(_ref)
00034     {}
00035 
00036 
00042     const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
00043     {
00044         unsigned int flag1 = flag(_objectiveVector1);
00045         unsigned int flag2 = flag(_objectiveVector2);
00046         if (flag2==0)
00047         {
00048             // cannot dominate
00049             return false;
00050         }
00051         else if ( (flag2==1) && (flag1==0) )
00052         {
00053             // is dominated
00054             return true;
00055         }
00056         else // (flag1==1) && (flag2==1)
00057         {
00058             // both are on the good region, so let's use the classical Pareto dominance
00059             return paretoComparator(_objectiveVector1, _objectiveVector2);
00060         }
00061     }
00062 
00063 
00064 private:
00065 
00067     ObjectiveVector & ref;
00069     moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
00070 
00071 
00076     unsigned int flag(const ObjectiveVector & _objectiveVector)
00077     {
00078         unsigned int result=1;
00079         for (unsigned int i=0; i<ref.nObjectives(); i++)
00080         {
00081             if (_objectiveVector[i] > ref[i])
00082             {
00083                 result=0;
00084             }
00085         }
00086         if (result==0)
00087         {
00088             result=1;
00089             for (unsigned int i=0; i<ref.nObjectives(); i++)
00090             {
00091                 if (_objectiveVector[i] < ref[i])
00092                 {
00093                     result=0;
00094                 }
00095             }
00096         }
00097         return result;
00098     }
00099 
00100 };
00101 
00102 #endif /*MOEOGDOMINANCEOBJECTIVEVECTORCOMPARATOR_H_*/

Generated on Tue Jun 26 15:13:04 2007 for ParadisEO-MOEO by  doxygen 1.4.7