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:
parent
91f5ddbdaa
commit
29ea368191
1 changed files with 82 additions and 71 deletions
133
eo/src/eoPop.h
133
eo/src/eoPop.h
|
|
@ -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
|
||||||
|
typedef typename EOT::Type Type;
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Protected ctor. This is intended to avoid creation of void populations, except
|
/** Protected ctor. This is intended to avoid creation of void populations, except
|
||||||
from sibling classes
|
from sibling classes
|
||||||
*/
|
*/
|
||||||
eoPop() :vector<EOT>() {};
|
eoPop():vector<EOT>() {};
|
||||||
|
|
||||||
|
|
||||||
/** Ctor for fixed-size chromosomes, with variable content
|
/** Ctor for fixed-size chromosomes, with variable content
|
||||||
@param _popSize total population size
|
@param _popSize total population size
|
||||||
@param _eoSize chromosome size. EOT should accept a fixed-size ctor
|
@param _eoSize chromosome size. EOT should accept a fixed-size ctor
|
||||||
@param _geneRdn random number generator for each of the genes
|
@param _geneRdn random number generator for each of the genes
|
||||||
*/
|
*/
|
||||||
eoPop( unsigned _popSize, unsigned _eoSize, eoRnd<Type> & _geneRnd )
|
/*
|
||||||
:vector<EOT>() {
|
Victor Rivas (vrivas@ujaen.es): 15-Dec-1999
|
||||||
for ( unsigned i = 0; i < _popSize; i ++ ){
|
This constructor must be substitued by one using factories.
|
||||||
EOT tmpEOT( _eoSize, _geneRnd);
|
eoPop( unsigned _popSize, unsigned _eoSize, eoRnd<Type> & _geneRnd )
|
||||||
push_back( tmpEOT );
|
:vector<EOT>() {
|
||||||
}
|
for ( unsigned i = 0; i < _popSize; i ++ ){
|
||||||
};
|
EOT tmpEOT( _eoSize, _geneRnd);
|
||||||
|
push_back( tmpEOT );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
/** Ctor for variable-size chromosomes, with variable content
|
/** Ctor for variable-size chromosomes, with variable content
|
||||||
@param _popSize total population size
|
@param _popSize total population size
|
||||||
@param _sizeRnd RNG for the chromosome size. This will be added 1, just in case.
|
@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
|
@param _geneRdn random number generator for each of the genes
|
||||||
*/
|
*/
|
||||||
eoPop( unsigned _popSize, eoRnd<unsigned> & _sizeRnd, eoRnd<Type> & _geneRnd )
|
/*
|
||||||
:vector<EOT>() {
|
Victor Rivas (vrivas@ujaen.es): 15-Dec-1999
|
||||||
for ( unsigned i = 0; i < _popSize; i ++ ){
|
This constructor must be substitued by one using factories.
|
||||||
unsigned size = 1 + _sizeRnd();
|
eoPop( unsigned _popSize, eoRnd<unsigned> & _sizeRnd, eoRnd<Type> & _geneRnd )
|
||||||
EOT tmpEOT( size, _geneRnd);
|
:vector<EOT>() {
|
||||||
push_back( tmpEOT );
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
/** Ctor from an istream; reads the population from a stream,
|
///
|
||||||
each element should be in different lines
|
~eoPop() {};
|
||||||
@param _is the stream
|
|
||||||
*/
|
|
||||||
eoPop( istream& _is ):vector<EOT>() {
|
|
||||||
readFrom( _is );
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
/** @name Methods from eoObject */
|
||||||
~eoPop() {};
|
//@{
|
||||||
|
/**
|
||||||
|
* Read object. The EOT class must have a ctor from a stream;
|
||||||
|
in this case, a strstream is used.
|
||||||
|
* @param _is A istream.
|
||||||
|
|
||||||
/** @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,7 +138,7 @@ 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") );
|
||||||
};
|
};
|
||||||
|
|
@ -136,9 +147,9 @@ class eoPop: public vector<EOT>, public eoObject, public eoPersistent {
|
||||||
@see eoObject
|
@see eoObject
|
||||||
*/
|
*/
|
||||||
virtual string className() const {return "eoPop";};
|
virtual string className() const {return "eoPop";};
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Reference in a new issue