Updating the selectors: they inherited from eoSelect and noew the inherite from eoBinPopOp
This commit is contained in:
parent
050df933c8
commit
a92af188c8
2 changed files with 12 additions and 11 deletions
|
|
@ -40,20 +40,21 @@
|
||||||
* eoRandomSelect: an selection operator, which selects randomly a percentage
|
* eoRandomSelect: an selection operator, which selects randomly a percentage
|
||||||
of the initial population.
|
of the initial population.
|
||||||
*/
|
*/
|
||||||
template<class EOT> class eoRandomSelect: public eoSelect<EOT>
|
template<class EOT> class eoRandomSelect: public eoBinPopOp<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
eoRandomSelect(const float& _percent = 0.4): eoSelect<EOT>(), rate(_percent) {};
|
eoRandomSelect(const float& _percent = 0.4):
|
||||||
|
eoBinPopOp<EOT>(), repRate(_percent) {};
|
||||||
|
|
||||||
///
|
///
|
||||||
virtual ~eoRandomSelect() {};
|
virtual ~eoRandomSelect() {};
|
||||||
|
|
||||||
/// Takes a percentage of the population randomly, and transfers it to siblings
|
/// Takes a percentage of the population randomly, and transfers it to siblings
|
||||||
virtual void operator() ( const eoPop<EOT>& _parents, eoPop<EOT>& _siblings ) const {
|
virtual void operator() ( eoPop<EOT>& _parents, eoPop<EOT>& _siblings ) {
|
||||||
// generates random numbers
|
// generates random numbers
|
||||||
eoUniform<unsigned> uniform(0, _parents.size()-1);
|
eoUniform<unsigned> uniform(0, _parents.size()-1);
|
||||||
unsigned num_chroms = (unsigned)(rate * _parents.size());
|
unsigned num_chroms = (unsigned)(repRate * _parents.size());
|
||||||
|
|
||||||
// selection of chromosomes
|
// selection of chromosomes
|
||||||
do {
|
do {
|
||||||
|
|
@ -69,7 +70,7 @@ template<class EOT> class eoRandomSelect: public eoSelect<EOT>
|
||||||
* @param _s A istream.
|
* @param _s A istream.
|
||||||
*/
|
*/
|
||||||
virtual void readFrom(istream& _s) {
|
virtual void readFrom(istream& _s) {
|
||||||
_s >> rate;
|
_s >> repRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Print itself: inherited from eoObject implementation. Declared virtual so that
|
/** Print itself: inherited from eoObject implementation. Declared virtual so that
|
||||||
|
|
@ -77,7 +78,7 @@ template<class EOT> class eoRandomSelect: public eoSelect<EOT>
|
||||||
base classes, so you don´t have to worry about, for instance, fitness.
|
base classes, so you don´t have to worry about, for instance, fitness.
|
||||||
@param _s the ostream in which things are written*/
|
@param _s the ostream in which things are written*/
|
||||||
virtual void printOn( ostream& _s ) const{
|
virtual void printOn( ostream& _s ) const{
|
||||||
_s << rate;
|
_s << repRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Inherited from eoObject
|
/** Inherited from eoObject
|
||||||
|
|
@ -89,7 +90,7 @@ template<class EOT> class eoRandomSelect: public eoSelect<EOT>
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float rate;
|
float repRate;
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,12 @@
|
||||||
@author JJ Merelo, 1998
|
@author JJ Merelo, 1998
|
||||||
*/
|
*/
|
||||||
template<class EOT>
|
template<class EOT>
|
||||||
class eoTournament:public eoSelect<EOT>{
|
class eoTournament:public eoBinPopOp<EOT>{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Proportion of guys that are going to be eliminated
|
/// Proportion of guys that are going to be eliminated
|
||||||
eoTournament( float _perc, unsigned _tSize): eoSelect<EOT>(),
|
eoTournament( float _perc, unsigned _tSize):
|
||||||
perc( _perc), repTournamentSize(_tSize){};
|
eoBinPopOp<EOT>(), perc( _perc), repTournamentSize(_tSize){};
|
||||||
|
|
||||||
/// Virtual dtor
|
/// Virtual dtor
|
||||||
~eoTournament(){};
|
~eoTournament(){};
|
||||||
|
|
@ -55,7 +55,7 @@ public:
|
||||||
* Selects from the initial pop using tournament selection, and copies it
|
* Selects from the initial pop using tournament selection, and copies it
|
||||||
* to the other population.
|
* to the other population.
|
||||||
*/
|
*/
|
||||||
virtual void operator() ( const eoPop<EOT>& _vEO, eoPop<EOT>& _aVEO) const {
|
virtual void operator() ( eoPop<EOT>& _vEO, eoPop<EOT>& _aVEO) {
|
||||||
|
|
||||||
unsigned thisSize = _vEO.size();
|
unsigned thisSize = _vEO.size();
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue