moeoRealObjectiveVector.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // moeoRealObjectiveVector.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 MOEOREALOBJECTIVEVECTOR_H_
00014 #define MOEOREALOBJECTIVEVECTOR_H_
00015 
00016 #include <iostream>
00017 #include <math.h>
00018 #include <comparator/moeoObjectiveObjectiveVectorComparator.h>
00019 #include <comparator/moeoParetoObjectiveVectorComparator.h>
00020 #include <core/moeoObjectiveVector.h>
00021 
00026 template < class ObjectiveVectorTraits >
00027 class moeoRealObjectiveVector : public moeoObjectiveVector < ObjectiveVectorTraits, double >
00028 {
00029 public:
00030 
00031     using moeoObjectiveVector < ObjectiveVectorTraits, double >::size;
00032     using moeoObjectiveVector < ObjectiveVectorTraits, double >::operator[];
00033 
00037     moeoRealObjectiveVector(double _value = 0.0) : moeoObjectiveVector < ObjectiveVectorTraits, double > (_value)
00038     {}
00039 
00040 
00045     moeoRealObjectiveVector(std::vector < double > & _v) : moeoObjectiveVector < ObjectiveVectorTraits, double > (_v)
00046     {}
00047 
00048 
00054     bool dominates(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
00055     {
00056         moeoParetoObjectiveVectorComparator < moeoRealObjectiveVector<ObjectiveVectorTraits> > comparator;
00057         return comparator(_other, *this);
00058     }
00059 
00060 
00065     bool operator==(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
00066     {
00067         for (unsigned int i=0; i < size(); i++)
00068         {
00069             if ( fabs(operator[](i) - _other[i]) > ObjectiveVectorTraits::tolerance() )
00070             {
00071                 return false;
00072             }
00073         }
00074         return true;
00075     }
00076 
00077 
00082     bool operator!=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
00083     {
00084         return ! operator==(_other);
00085     }
00086 
00087 
00093     bool operator<(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
00094     {
00095         moeoObjectiveObjectiveVectorComparator < moeoRealObjectiveVector < ObjectiveVectorTraits > > cmp;
00096         return cmp(*this, _other);
00097     }
00098 
00099 
00105     bool operator>(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
00106     {
00107         return _other < *this;
00108     }
00109 
00110 
00116     bool operator<=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
00117     {
00118         return operator==(_other) || operator<(_other);
00119     }
00120 
00121 
00127     bool operator>=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
00128     {
00129         return operator==(_other) || operator>(_other);
00130     }
00131 
00132 };
00133 
00134 
00140 template < class ObjectiveVectorTraits >
00141 std::ostream & operator<<(std::ostream & _os, const moeoRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector)
00142 {
00143     for (unsigned int i=0; i<_objectiveVector.size(); i++)
00144     {
00145         _os << _objectiveVector[i] << '\t';
00146     }
00147     return _os;
00148 }
00149 
00155 template < class ObjectiveVectorTraits >
00156 std::istream & operator>>(std::istream & _is, moeoRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector)
00157 {
00158     _objectiveVector = moeoRealObjectiveVector < ObjectiveVectorTraits > ();
00159     for (unsigned int i=0; i<_objectiveVector.size(); i++)
00160     {
00161         _is >> _objectiveVector[i];
00162     }
00163     return _is;
00164 }
00165 
00166 #endif /*MOEOREALOBJECTIVEVECTOR_H_*/

Generated on Mon Jul 2 16:05:01 2007 for ParadisEO-MOEO by  doxygen 1.4.7