I have turned into comments the Pop constructor that used Type as the type of the gene, given that an EO can have NO genes

This commit is contained in:
victor 1999-12-15 13:57:09 +00:00
commit 29ea368191

View file

@ -49,76 +49,87 @@ to the population.
template<class EOT>
class eoPop: public vector<EOT>, public eoObject, public eoPersistent {
/// Type is the type of each gene in the chromosome
#ifdef _MSC_VER
typedef EOT::Type Type;
#else
typedef typename EOT::Type Type;
#endif
public:
/** Protected ctor. This is intended to avoid creation of void populations, except
from sibling classes
*/
eoPop() :vector<EOT>() {};
/** Ctor for fixed-size chromosomes, with variable content
@param _popSize total population size
@param _eoSize chromosome size. EOT should accept a fixed-size ctor
@param _geneRdn random number generator for each of the genes
*/
eoPop( unsigned _popSize, unsigned _eoSize, eoRnd<Type> & _geneRnd )
:vector<EOT>() {
for ( unsigned i = 0; i < _popSize; i ++ ){
EOT tmpEOT( _eoSize, _geneRnd);
push_back( tmpEOT );
}
};
/** Ctor for variable-size chromosomes, with variable content
@param _popSize total population size
@param _sizeRnd RNG for the chromosome size. This will be added 1, just in case.
@param _geneRdn random number generator for each of the genes
*/
eoPop( unsigned _popSize, eoRnd<unsigned> & _sizeRnd, eoRnd<Type> & _geneRnd )
:vector<EOT>() {
for ( unsigned i = 0; i < _popSize; i ++ ){
unsigned size = 1 + _sizeRnd();
EOT tmpEOT( size, _geneRnd);
push_back( tmpEOT );
}
};
/** Ctor from an istream; reads the population from a stream,
each element should be in different lines
@param _is the stream
*/
eoPop( istream& _is ):vector<EOT>() {
readFrom( _is );
}
///
~eoPop() {};
/** @name Methods from eoObject */
//@{
/**
* Read object. The EOT class must have a ctor from a stream;
in this case, a strstream is used.
* @param _is A istream.
*/
/*
Victor Rivas (vrivas@ujaen.es): 15-Dec-1999
An EO can have NO genes.
/// Type is the type of each gene in the chromosome
#ifdef _MSC_VER
typedef EOT::Type Type;
#else
typedef typename EOT::Type Type;
#endif
*/
public:
/** Protected ctor. This is intended to avoid creation of void populations, except
from sibling classes
*/
eoPop():vector<EOT>() {};
/** Ctor for fixed-size chromosomes, with variable content
@param _popSize total population size
@param _eoSize chromosome size. EOT should accept a fixed-size ctor
@param _geneRdn random number generator for each of the genes
*/
/*
Victor Rivas (vrivas@ujaen.es): 15-Dec-1999
This constructor must be substitued by one using factories.
eoPop( unsigned _popSize, unsigned _eoSize, eoRnd<Type> & _geneRnd )
:vector<EOT>() {
for ( unsigned i = 0; i < _popSize; i ++ ){
EOT tmpEOT( _eoSize, _geneRnd);
push_back( tmpEOT );
}
};
*/
/** Ctor for variable-size chromosomes, with variable content
@param _popSize total population size
@param _sizeRnd RNG for the chromosome size. This will be added 1, just in case.
@param _geneRdn random number generator for each of the genes
*/
/*
Victor Rivas (vrivas@ujaen.es): 15-Dec-1999
This constructor must be substitued by one using factories.
eoPop( unsigned _popSize, eoRnd<unsigned> & _sizeRnd, eoRnd<Type> & _geneRnd )
:vector<EOT>() {
for ( unsigned i = 0; i < _popSize; i ++ ){
unsigned size = 1 + _sizeRnd();
EOT tmpEOT( size, _geneRnd);
push_back( tmpEOT );
}
};
*/
/** Ctor from an istream; reads the population from a stream,
each element should be in different lines
@param _is the stream
*/
eoPop( istream& _is ):vector<EOT>() {
readFrom( _is );
}
///
~eoPop() {};
/** @name Methods from eoObject */
//@{
/**
* Read object. The EOT class must have a ctor from a stream;
in this case, a strstream is used.
* @param _is A istream.
*/
virtual void readFrom(istream& _is) {
while( _is ) { // reads line by line, and creates an object per
// line
char line[MAXLINELENGTH];
_is.getline( line, MAXLINELENGTH-1 );
if (strlen( line ) ) {
istrstream s( line );
EOT thisEOT( s );
push_back( thisEOT );
}
if (strlen( line ) ) {
istrstream s( line );
EOT thisEOT( s );
push_back( thisEOT );
}
}
}
@ -127,18 +138,18 @@ class eoPop: public vector<EOT>, public eoObject, public eoPersistent {
* @param _os A ostream. In this case, prints the population to
standard output. The EOT class must hav standard output with cout,
but since it should be an eoObject anyways, it's no big deal.
*/
*/
virtual void printOn(ostream& _os) const {
copy( begin(), end(), ostream_iterator<EOT>( _os, "\n") );
};
/** Inherited from eoObject. Returns the class name.
@see eoObject
*/
virtual string className() const {return "eoPop";};
//@}
protected:
//@}
protected:
};
#endif