00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef MOEOVECTOR_H_
00039 #define MOEOVECTOR_H_
00040
00041 #include <iterator>
00042 #include <vector>
00043 #include <core/MOEO.h>
00044
00049 template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType >
00050 class moeoVector : public MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >, public std::vector < GeneType >
00051 {
00052 public:
00053
00054 using MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity > :: invalidate;
00055 using std::vector < GeneType > :: operator[];
00056 using std::vector < GeneType > :: begin;
00057 using std::vector < GeneType > :: end;
00058 using std::vector < GeneType > :: resize;
00059 using std::vector < GeneType > :: size;
00060
00062 typedef GeneType AtomType;
00064 typedef std::vector < GeneType > ContainerType;
00065
00066
00072 moeoVector(unsigned int _size = 0, GeneType _value = GeneType()) :
00073 MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >(), std::vector<GeneType>(_size, _value)
00074 {}
00075
00076
00081 void value(const std::vector < GeneType > & _v)
00082 {
00083 if (_v.size() != size())
00084 {
00085 if (size())
00086 {
00087 std::cout << "Warning: Changing size in moeoVector assignation"<<std::endl;
00088 resize(_v.size());
00089 }
00090 else
00091 {
00092 throw std::runtime_error("Size not initialized in moeoVector");
00093 }
00094 }
00095 std::copy(_v.begin(), _v.end(), begin());
00096 invalidate();
00097 }
00098
00099
00104 bool operator<(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo) const
00105 {
00106 return MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::operator<(_moeo);
00107 }
00108
00109
00114 virtual void printOn(std::ostream & _os) const
00115 {
00116 MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os);
00117 _os << ' ';
00118 _os << size() << ' ';
00119 std::copy(begin(), end(), std::ostream_iterator<AtomType>(_os, " "));
00120 }
00121
00122
00127 virtual void readFrom(std::istream & _is)
00128 {
00129 MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is);
00130 unsigned int sz;
00131 _is >> sz;
00132 resize(sz);
00133 unsigned int i;
00134 for (i = 0; i < sz; ++i)
00135 {
00136 AtomType atom;
00137 _is >> atom;
00138 operator[](i) = atom;
00139 }
00140 }
00141
00142 };
00143
00144
00150 template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType >
00151 bool operator<(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo1, const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo2)
00152 {
00153 return _moeo1.operator<(_moeo2);
00154 }
00155
00156
00162 template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType >
00163 bool operator>(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo1, const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo2)
00164 {
00165 return _moeo1.operator>(_moeo2);
00166 }
00167
00168 #endif