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 #ifndef _eoVector_h
00031 #define _eoVector_h
00032
00033 #include <vector>
00034 #include <iterator>
00035 #include <EO.h>
00036
00045 template <class FitT, class GeneType>
00046 class eoVector : public EO<FitT>, public std::vector<GeneType>
00047 {
00048 public:
00049
00050 using EO<FitT>::invalidate;
00051 using std::vector<GeneType>::operator[];
00052 using std::vector<GeneType>::begin;
00053 using std::vector<GeneType>::end;
00054 using std::vector<GeneType>::resize;
00055 using std::vector<GeneType>::size;
00056
00057 typedef GeneType AtomType;
00058 typedef std::vector<GeneType> ContainerType;
00059
00065 eoVector(unsigned size = 0, GeneType value = GeneType())
00066 : EO<FitT>(), std::vector<GeneType>(size, value)
00067 {}
00068
00070 template <class OtherFitnessType>
00071 eoVector(const eoVector<OtherFitnessType, GeneType>& _vec) : std::vector<GeneType>(_vec)
00072 {}
00073
00074
00075
00076 void value(const std::vector<GeneType>& _v)
00077 {
00078 if (_v.size() != size())
00079 {
00080 if (size())
00081 std::cout << "Warning: Changing size in eoVector assignation"<<std::endl;
00082 resize(_v.size());
00083 }
00084
00085 std::copy(_v.begin(), _v.end(), begin());
00086 invalidate();
00087 }
00088
00090 bool operator<(const eoVector<FitT, GeneType>& _eo) const
00091 {
00092 return EO<FitT>::operator<(_eo);
00093 }
00094
00096 virtual void printOn(std::ostream& os) const
00097 {
00098 EO<FitT>::printOn(os);
00099 os << ' ';
00100
00101 os << size() << ' ';
00102
00103 std::copy(begin(), end(), std::ostream_iterator<AtomType>(os, " "));
00104 }
00105
00107 virtual void readFrom(std::istream& is)
00108 {
00109 EO<FitT>::readFrom(is);
00110
00111 unsigned sz;
00112 is >> sz;
00113
00114 resize(sz);
00115 unsigned i;
00116
00117 for (i = 0; i < sz; ++i)
00118 {
00119 AtomType atom;
00120 is >> atom;
00121 operator[](i) = atom;
00122 }
00123 }
00124 };
00125
00127 template <class FitT, class GeneType>
00128 bool operator<(const eoVector<FitT, GeneType>& _eo1, const eoVector<FitT, GeneType>& _eo2)
00129 {
00130 return _eo1.operator<(_eo2);
00131 }
00132 template <class FitT, class GeneType>
00133 bool operator>(const eoVector<FitT, GeneType>& _eo1, const eoVector<FitT, GeneType>& _eo2)
00134 {
00135 return _eo1.operator>(_eo2);
00136 }
00137
00138 #endif