cleanup, docs
This commit is contained in:
parent
3533d8addb
commit
14b3a61ba8
1 changed files with 82 additions and 69 deletions
|
|
@ -1,31 +1,24 @@
|
||||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
/* (C) GeNeura Team, 2000 - EEAAX 1999 - Maarten Keijzer 2000
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
This library is free software; you can redistribute it and/or
|
||||||
// eoVector.h
|
modify it under the terms of the GNU Lesser General Public
|
||||||
// (c) GeNeura Team, 2000 - EEAAX 1999 - Maarten Keijzer 2000
|
License as published by the Free Software Foundation; either
|
||||||
/*
|
version 2 of the License, or (at your option) any later version.
|
||||||
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,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Lesser General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
Contact: eodev-main@lists.sourceforge.net
|
||||||
|
Old contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
Marc.Schoenauer@polytechnique.fr
|
Marc.Schoenauer@polytechnique.fr
|
||||||
mak@dhi.dk
|
mak@dhi.dk
|
||||||
|
*/
|
||||||
CVS Info: $Date: 2006-12-02 11:36:29 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/eoVector.h,v 1.18 2006-12-02 11:36:29 kuepper Exp $ $Author: kuepper $
|
|
||||||
|
|
||||||
*/
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef _eoVector_h
|
#ifndef _eoVector_h
|
||||||
#define _eoVector_h
|
#define _eoVector_h
|
||||||
|
|
@ -34,13 +27,13 @@
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <EO.h>
|
#include <EO.h>
|
||||||
|
|
||||||
/**
|
/** Base class for fixed length chromosomes
|
||||||
|
|
||||||
Base class for fixed length chromosomes, 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,
|
|
||||||
|
|
||||||
|
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 FitT, class GeneType>
|
template <class FitT, class GeneType>
|
||||||
class eoVector : public EO<FitT>, public std::vector<GeneType>
|
class eoVector : public EO<FitT>, public std::vector<GeneType>
|
||||||
|
|
@ -69,71 +62,91 @@ public:
|
||||||
/// copy ctor abstracting from the FitT
|
/// copy ctor abstracting from the FitT
|
||||||
template <class OtherFitnessType>
|
template <class OtherFitnessType>
|
||||||
eoVector(const eoVector<OtherFitnessType, GeneType>& _vec) : std::vector<GeneType>(_vec)
|
eoVector(const eoVector<OtherFitnessType, GeneType>& _vec) : std::vector<GeneType>(_vec)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// we can't have a Ctor from a std::vector, it would create ambiguity
|
// we can't have a Ctor from a std::vector, it would create ambiguity
|
||||||
// with the copy Ctor
|
// with the copy Ctor
|
||||||
void value(const std::vector<GeneType>& _v)
|
void value(const std::vector<GeneType>& _v)
|
||||||
{
|
{
|
||||||
if (_v.size() != size()) // safety check
|
if (_v.size() != size()) // safety check
|
||||||
{
|
{
|
||||||
if (size()) // NOT an initial empty std::vector
|
if (size()) // NOT an initial empty std::vector
|
||||||
std::cout << "Warning: Changing size in eoVector assignation"<<std::endl;
|
std::cout << "Warning: Changing size in eoVector assignation"<<std::endl;
|
||||||
resize(_v.size());
|
resize(_v.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::copy(_v.begin(), _v.end(), begin());
|
std::copy(_v.begin(), _v.end(), begin());
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// to avoid conflicts between EO::operator< and std::vector<GeneType>::operator<
|
/// to avoid conflicts between EO::operator< and std::vector<GeneType>::operator<
|
||||||
bool operator<(const eoVector<FitT, GeneType>& _eo) const
|
bool operator<(const eoVector<FitT, GeneType>& _eo) const
|
||||||
{
|
{
|
||||||
return EO<FitT>::operator<(_eo);
|
return EO<FitT>::operator<(_eo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// printing...
|
/// printing...
|
||||||
virtual void printOn(std::ostream& os) const
|
virtual void printOn(std::ostream& os) const
|
||||||
{
|
{
|
||||||
EO<FitT>::printOn(os);
|
EO<FitT>::printOn(os);
|
||||||
os << ' ';
|
os << ' ';
|
||||||
|
|
||||||
os << size() << ' ';
|
os << size() << ' ';
|
||||||
|
|
||||||
std::copy(begin(), end(), std::ostream_iterator<AtomType>(os, " "));
|
std::copy(begin(), end(), std::ostream_iterator<AtomType>(os, " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// reading...
|
/// reading...
|
||||||
virtual void readFrom(std::istream& is)
|
virtual void readFrom(std::istream& is)
|
||||||
{
|
|
||||||
EO<FitT>::readFrom(is);
|
|
||||||
|
|
||||||
unsigned sz;
|
|
||||||
is >> sz;
|
|
||||||
|
|
||||||
resize(sz);
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
for (i = 0; i < sz; ++i)
|
|
||||||
{
|
{
|
||||||
AtomType atom;
|
EO<FitT>::readFrom(is);
|
||||||
is >> atom;
|
|
||||||
operator[](i) = atom;
|
unsigned sz;
|
||||||
|
is >> sz;
|
||||||
|
|
||||||
|
resize(sz);
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
for (i = 0; i < sz; ++i)
|
||||||
|
{
|
||||||
|
AtomType atom;
|
||||||
|
is >> atom;
|
||||||
|
operator[](i) = atom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// to avoid conflicts between EO::operator< and std::vector<double>::operator<
|
/** Less than
|
||||||
|
|
||||||
|
This is impemented to avoid conflicts between EO::operator< and
|
||||||
|
std::vector<GeneType>::operator<
|
||||||
|
*/
|
||||||
template <class FitT, class GeneType>
|
template <class FitT, class GeneType>
|
||||||
bool operator<(const eoVector<FitT, GeneType>& _eo1, const eoVector<FitT, GeneType>& _eo2)
|
bool operator<(const eoVector<FitT, GeneType>& _eo1, const eoVector<FitT, GeneType>& _eo2)
|
||||||
{
|
{
|
||||||
return _eo1.operator<(_eo2);
|
return _eo1.operator<(_eo2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Greater than
|
||||||
|
|
||||||
|
This is impemented to avoid conflicts between EO::operator> and
|
||||||
|
std::vector<GeneType>::operator>
|
||||||
|
*/
|
||||||
template <class FitT, class GeneType>
|
template <class FitT, class GeneType>
|
||||||
bool operator>(const eoVector<FitT, GeneType>& _eo1, const eoVector<FitT, GeneType>& _eo2)
|
bool operator>(const eoVector<FitT, GeneType>& _eo1, const eoVector<FitT, GeneType>& _eo2)
|
||||||
{
|
{
|
||||||
return _eo1.operator>(_eo2);
|
return _eo1.operator>(_eo2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// coding: iso-8859-1
|
||||||
|
// mode: C++
|
||||||
|
// c-file-offsets: ((c . 0))
|
||||||
|
// c-file-style: "Stroustrup"
|
||||||
|
// fill-column: 80
|
||||||
|
// End:
|
||||||
|
|
|
||||||
Reference in a new issue