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