00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef MOEOOBJECTIVEVECTORDOUBLE_H_
00014 #define MOEOOBJECTIVEVECTORDOUBLE_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 moeoObjectiveVectorDouble : public moeoObjectiveVector < ObjectiveVectorTraits, double >
00028 {
00029 public:
00030
00031 using moeoObjectiveVector < ObjectiveVectorTraits, double >::size;
00032 using moeoObjectiveVector < ObjectiveVectorTraits, double >::operator[];
00033
00037 moeoObjectiveVectorDouble(double _value = 0.0) : moeoObjectiveVector < ObjectiveVectorTraits, double > (_value)
00038 {}
00039
00040
00045 moeoObjectiveVectorDouble(std::vector < double > & _v) : moeoObjectiveVector < ObjectiveVectorTraits, double > (_v)
00046 {}
00047
00048
00054 bool dominates(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
00055 {
00056 moeoParetoObjectiveVectorComparator < moeoObjectiveVectorDouble<ObjectiveVectorTraits> > comparator;
00057 return comparator(_other, *this);
00058 }
00059
00060
00065 bool operator==(const moeoObjectiveVectorDouble < 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 moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
00083 {
00084 return ! operator==(_other);
00085 }
00086
00087
00093 bool operator<(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
00094 {
00095 moeoObjectiveObjectiveVectorComparator < moeoObjectiveVectorDouble < ObjectiveVectorTraits > > cmp;
00096 return cmp(*this, _other);
00097 }
00098
00099
00105 bool operator>(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
00106 {
00107 return _other < *this;
00108 }
00109
00110
00116 bool operator<=(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
00117 {
00118 return operator==(_other) || operator<(_other);
00119 }
00120
00121
00127 bool operator>=(const moeoObjectiveVectorDouble < 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 moeoObjectiveVectorDouble < 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, moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _objectiveVector)
00157 {
00158 _objectiveVector = moeoObjectiveVectorDouble < ObjectiveVectorTraits > ();
00159 for (unsigned int i=0; i<_objectiveVector.size(); i++)
00160 {
00161 _is >> _objectiveVector[i];
00162 }
00163 return _is;
00164 }
00165
00166 #endif