/* (C) GeNeura Team, 2000 - EEAAX 1999 - Maarten Keijzer 2000 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: eodev-main@lists.sourceforge.net Old contact: todos@geneura.ugr.es, http://geneura.ugr.es Marc.Schoenauer@polytechnique.fr mak@dhi.dk */ #ifndef _eoVector_h #define _eoVector_h #include #include #include /** Base class for fixed length chromosomes It just derives from EO and std::vector and redirects the smaller than operator to EO (fitness based comparison). GeneType must have the following methods: void ctor (needed for the std::vector<>), copy ctor, */ template class eoVector : public EO, public std::vector { public: using EO::invalidate; using std::vector::operator[]; using std::vector::begin; using std::vector::end; using std::vector::resize; using std::vector::size; typedef GeneType AtomType; typedef std::vector ContainerType; /** default constructor @param size Length of vector (default is 0) @param value Initial value of all elements (default is default value of type GeneType) */ eoVector(unsigned size = 0, GeneType value = GeneType()) : EO(), std::vector(size, value) {} /// copy ctor abstracting from the FitT template eoVector(const eoVector& _vec) : std::vector(_vec) {} // we can't have a Ctor from a std::vector, it would create ambiguity // with the copy Ctor void value(const std::vector& _v) { if (_v.size() != size()) // safety check { if (size()) // NOT an initial empty std::vector std::cout << "Warning: Changing size in eoVector assignation"<::operator< bool operator<(const eoVector& _eo) const { return EO::operator<(_eo); } /// printing... virtual void printOn(std::ostream& os) const { EO::printOn(os); os << ' '; os << size() << ' '; std::copy(begin(), end(), std::ostream_iterator(os, " ")); } /// reading... virtual void readFrom(std::istream& is) { EO::readFrom(is); unsigned sz; is >> sz; resize(sz); unsigned i; for (i = 0; i < sz; ++i) { AtomType atom; is >> atom; operator[](i) = atom; } } }; /** Less than This is impemented to avoid conflicts between EO::operator< and std::vector::operator< */ template bool operator<(const eoVector& _eo1, const eoVector& _eo2) { return _eo1.operator<(_eo2); } /** Greater than This is impemented to avoid conflicts between EO::operator> and std::vector::operator> */ template bool operator>(const eoVector& _eo1, const eoVector& _eo2) { return _eo1.operator>(_eo2); } #endif // Local Variables: // coding: iso-8859-1 // mode: C++ // c-file-offsets: ((c . 0)) // c-file-style: "Stroustrup" // fill-column: 80 // End: