moeoParetoObjectiveVectorComparator.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // moeoParetoObjectiveVectorComparator.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 MOEOPARETOOBJECTIVEVECTORCOMPARATOR_H_
00014 #define MOEOPARETOOBJECTIVEVECTORCOMPARATOR_H_
00015 
00016 #include <comparator/moeoObjectiveVectorComparator.h>
00017 
00021 template < class ObjectiveVector >
00022 class moeoParetoObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
00023 {
00024 public:
00025 
00031     const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
00032     {
00033         bool dom = false;
00034         for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
00035         {
00036             // first, we have to check if the 2 objective values are not equal for the ith objective
00037             if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() )
00038             {
00039                 // if the ith objective have to be minimized...
00040                 if (ObjectiveVector::minimizing(i))
00041                 {
00042                     if (_objectiveVector1[i] > _objectiveVector2[i])
00043                     {
00044                         dom = true;             //_objectiveVector1[i] is not better than _objectiveVector2[i]
00045                     }
00046                     else
00047                     {
00048                         return false;   //_objectiveVector2 cannot dominate _objectiveVector1
00049                     }
00050                 }
00051                 // if the ith objective have to be maximized...
00052                 else if (ObjectiveVector::maximizing(i))
00053                 {
00054                     if (_objectiveVector1[i] > _objectiveVector2[i])
00055                     {
00056                         dom = true;             //_objectiveVector1[i] is not better than _objectiveVector2[i]
00057                     }
00058                     else
00059                     {
00060                         return false;   //_objectiveVector2 cannot dominate _objectiveVector1
00061                     }
00062                 }
00063             }
00064         }
00065         return dom;
00066     }
00067 
00068 };
00069 
00070 #endif /*MOEOPARETOOBJECTIVEVECTORCOMPARATOR_H_*/

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