00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _eoVector_h
00024 #define _eoVector_h
00025
00026 #include <vector>
00027 #include <iterator>
00028 #include <EO.h>
00029
00038 template <class FitT, class GeneType>
00039 class eoVector : public EO<FitT>, public std::vector<GeneType>
00040 {
00041 public:
00042
00043 using EO<FitT>::invalidate;
00044 using std::vector<GeneType>::operator[];
00045 using std::vector<GeneType>::begin;
00046 using std::vector<GeneType>::end;
00047 using std::vector<GeneType>::resize;
00048 using std::vector<GeneType>::size;
00049
00050 typedef GeneType AtomType;
00051 typedef std::vector<GeneType> ContainerType;
00052
00058 eoVector(unsigned _size = 0, GeneType _value = GeneType())
00059 : EO<FitT>(), std::vector<GeneType>(_size, _value)
00060 {}
00061
00063 template <class OtherFitnessType>
00064 eoVector(const eoVector<OtherFitnessType, GeneType>& _vec) : std::vector<GeneType>(_vec)
00065 {}
00066
00067
00068
00069 void value(const std::vector<GeneType>& _v)
00070 {
00071 if (_v.size() != size())
00072 {
00073 if (size())
00074 std::cout << "Warning: Changing size in eoVector assignation"<<std::endl;
00075 resize(_v.size());
00076 }
00077
00078 std::copy(_v.begin(), _v.end(), begin());
00079 invalidate();
00080 }
00081
00083 bool operator<(const eoVector<FitT, GeneType>& _eo) const
00084 {
00085 return EO<FitT>::operator<(_eo);
00086 }
00087
00089 virtual void printOn(std::ostream& os) const
00090 {
00091 EO<FitT>::printOn(os);
00092 os << ' ';
00093
00094 os << size() << ' ';
00095
00096 std::copy(begin(), end(), std::ostream_iterator<AtomType>(os, " "));
00097 }
00098
00100 virtual void readFrom(std::istream& is)
00101 {
00102 EO<FitT>::readFrom(is);
00103
00104 unsigned sz;
00105 is >> sz;
00106
00107 resize(sz);
00108 unsigned i;
00109
00110 for (i = 0; i < sz; ++i)
00111 {
00112 AtomType atom;
00113 is >> atom;
00114 operator[](i) = atom;
00115 }
00116 }
00117 };
00118
00124 template <class FitT, class GeneType>
00125 bool operator<(const eoVector<FitT, GeneType>& _eo1, const eoVector<FitT, GeneType>& _eo2)
00126 {
00127 return _eo1.operator<(_eo2);
00128 }
00129
00130
00136 template <class FitT, class GeneType>
00137 bool operator>(const eoVector<FitT, GeneType>& _eo1, const eoVector<FitT, GeneType>& _eo2)
00138 {
00139 return _eo1.operator>(_eo2);
00140 }
00141
00142
00143 #endif
00144
00145
00146
00147
00148
00149
00150
00151
00152