00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef MOEOVECTOR_H_
00014 #define MOEOVECTOR_H_
00015
00016 #include <iterator>
00017 #include <vector>
00018 #include <core/MOEO.h>
00019
00024 template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType >
00025 class moeoVector : public MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >, public std::vector < GeneType >
00026 {
00027 public:
00028
00029 using MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity > :: invalidate;
00030 using std::vector < GeneType > :: operator[];
00031 using std::vector < GeneType > :: begin;
00032 using std::vector < GeneType > :: end;
00033 using std::vector < GeneType > :: resize;
00034 using std::vector < GeneType > :: size;
00035
00037 typedef GeneType AtomType;
00039 typedef std::vector < GeneType > ContainerType;
00040
00041
00047 moeoVector(unsigned int _size = 0, GeneType _value = GeneType()) :
00048 MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >(), std::vector<GeneType>(_size, _value)
00049 {}
00050
00051
00056 void value(const std::vector < GeneType > & _v)
00057 {
00058 if (_v.size() != size())
00059 {
00060 if (size())
00061 {
00062 std::cout << "Warning: Changing size in moeoVector assignation"<<std::endl;
00063 resize(_v.size());
00064 }
00065 else
00066 {
00067 throw std::runtime_error("Size not initialized in moeoVector");
00068 }
00069 }
00070 std::copy(_v.begin(), _v.end(), begin());
00071 invalidate();
00072 }
00073
00074
00079 bool operator<(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo) const
00080 {
00081 return MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::operator<(_moeo);
00082 }
00083
00084
00089 virtual void printOn(std::ostream & _os) const
00090 {
00091 MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os);
00092 _os << ' ';
00093 _os << size() << ' ';
00094 std::copy(begin(), end(), std::ostream_iterator<AtomType>(_os, " "));
00095 }
00096
00097
00102 virtual void readFrom(std::istream & _is)
00103 {
00104 MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is);
00105 unsigned int sz;
00106 _is >> sz;
00107 resize(sz);
00108 unsigned int i;
00109 for (i = 0; i < sz; ++i)
00110 {
00111 AtomType atom;
00112 _is >> atom;
00113 operator[](i) = atom;
00114 }
00115 }
00116
00117 };
00118
00119
00125 template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType >
00126 bool operator<(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo1, const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo2)
00127 {
00128 return _moeo1.operator<(_moeo2);
00129 }
00130
00131
00137 template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType >
00138 bool operator>(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo1, const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo2)
00139 {
00140 return _moeo1.operator>(_moeo2);
00141 }
00142
00143 #endif