small bug fixes
This commit is contained in:
parent
73f37176e8
commit
9d1fdcd126
2 changed files with 34 additions and 24 deletions
|
|
@ -7,36 +7,40 @@
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <iostream> // ostream, istream
|
||||
#include <functional> // bind2nd
|
||||
#include <iostream> // ostream, istream
|
||||
#include <functional> // bind2nd
|
||||
#include <string> // string
|
||||
#include <eoVector.h> // EO
|
||||
|
||||
#include <string> // string
|
||||
#include <eoVector.h> // EO
|
||||
/*****************************************************************************
|
||||
* eoBin: implementation of binary chromosome. *
|
||||
* based on STL's bit_vector (vector<bool>). *
|
||||
*****************************************************************************/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** eoBin: implementation of binary chromosome.
|
||||
based on STL's bit_vector (vector<bool>)*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <class F> class eoBin: public eoVector<bool,F>
|
||||
template <class F> class eoBin: public eoVector<bool, F>
|
||||
{
|
||||
public:
|
||||
typedef bool Type;
|
||||
|
||||
/// (Default) Constructor.
|
||||
/// @param size Size of the binary string.
|
||||
/**
|
||||
* (Default) Constructor.
|
||||
* @param size Size of the binary string.
|
||||
*/
|
||||
eoBin(const unsigned& size = 0, const bool& value = false):
|
||||
eoVector<bool,F>(size, value) {}
|
||||
|
||||
/// (Default) Constructor.
|
||||
/// @param size Size of the binary string.
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param size Size of the binary string.
|
||||
*/
|
||||
eoBin(const unsigned& size, const eoRnd<Type>& rnd): eoVector<bool,F>(size)
|
||||
{
|
||||
generate(begin(), end(), rnd);
|
||||
}
|
||||
|
||||
/// Constructor from istream.
|
||||
/// @param is The istream to read from.
|
||||
/**
|
||||
* Constructor from istream.
|
||||
* @param is The istream to read from.
|
||||
*/
|
||||
eoBin(istrstream& is)
|
||||
{
|
||||
readFrom(is);
|
||||
|
|
@ -48,15 +52,19 @@ template <class F> class eoBin: public eoVector<bool,F>
|
|||
return "eoBin";
|
||||
}
|
||||
|
||||
/// To print me on a stream.
|
||||
/// @param os The ostream.
|
||||
/**
|
||||
* To print me on a stream.
|
||||
* @param os The ostream.
|
||||
*/
|
||||
void printOn(ostream& os) const
|
||||
{
|
||||
copy(begin(), end(), ostream_iterator<bool>(os));
|
||||
}
|
||||
|
||||
/// To read me from a stream.
|
||||
/// @param is The istream.
|
||||
/**
|
||||
* To read me from a stream.
|
||||
* @param is The istream.
|
||||
*/
|
||||
void readFrom(istream& is)
|
||||
{
|
||||
string bits;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@
|
|||
template <class T, class fitnessT>
|
||||
class eoVector: public eo1d<T, fitnessT>, public vector<T> {
|
||||
public:
|
||||
typedef Type T;
|
||||
|
||||
/// Canonical part of the objects: several ctors, copy ctor, dtor and assignment operator
|
||||
//@{
|
||||
|
||||
|
|
@ -31,7 +33,7 @@ public:
|
|||
@param _size Lineal length of the object
|
||||
@param _val Common initial value
|
||||
*/
|
||||
eoVector( unsigned _size, T _val = 0)
|
||||
eoVector( unsigned _size = 0, T _val = 0)
|
||||
: eo1d<T, fitnessT>(), vector<T>( _size, _val ){ };
|
||||
|
||||
/** Ctor using a random number generator
|
||||
|
|
@ -80,7 +82,7 @@ which is supposed to be dynamic and dependent on environment.
|
|||
virtual T& gene( unsigned _i ) {
|
||||
if ( _i >= size() )
|
||||
throw out_of_range( "out_of_range when writing a gene");
|
||||
return (*this)[_i];
|
||||
return operator[](_i);
|
||||
};
|
||||
|
||||
/** methods that implement the eo1d <em>protocol</em>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue