diff --git a/eo/src/eoPop.h b/eo/src/eoPop.h index e6cf0aef..363ee005 100644 --- a/eo/src/eoPop.h +++ b/eo/src/eoPop.h @@ -49,76 +49,87 @@ to the population. template class eoPop: public vector, 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() {}; - - - /** 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 & _geneRnd ) - :vector() { - 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 & _sizeRnd, eoRnd & _geneRnd ) - :vector() { - 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() { - 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() {}; + + + /** 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 & _geneRnd ) + :vector() { + 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 & _sizeRnd, eoRnd & _geneRnd ) + :vector() { + 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() { + 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, 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( _os, "\n") ); }; - + /** Inherited from eoObject. Returns the class name. @see eoObject */ virtual string className() const {return "eoPop";}; - //@} - - protected: - + //@} + +protected: + }; #endif