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
|
||||
of the initial population.
|
||||
*/
|
||||
template<class EOT> class eoRandomSelect: public eoSelect<EOT>
|
||||
template<class EOT> class eoRandomSelect: public eoBinPopOp<EOT>
|
||||
{
|
||||
public:
|
||||
///
|
||||
eoRandomSelect(const float& _percent = 0.4): eoSelect<EOT>(), rate(_percent) {};
|
||||
eoRandomSelect(const float& _percent = 0.4):
|
||||
eoBinPopOp<EOT>(), repRate(_percent) {};
|
||||
|
||||
///
|
||||
virtual ~eoRandomSelect() {};
|
||||
|
||||
/// 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
|
||||
eoUniform<unsigned> uniform(0, _parents.size()-1);
|
||||
unsigned num_chroms = (unsigned)(rate * _parents.size());
|
||||
unsigned num_chroms = (unsigned)(repRate * _parents.size());
|
||||
|
||||
// selection of chromosomes
|
||||
do {
|
||||
|
|
@ -69,7 +70,7 @@ template<class EOT> class eoRandomSelect: public eoSelect<EOT>
|
|||
* @param _s A istream.
|
||||
*/
|
||||
virtual void readFrom(istream& _s) {
|
||||
_s >> rate;
|
||||
_s >> repRate;
|
||||
}
|
||||
|
||||
/** 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.
|
||||
@param _s the ostream in which things are written*/
|
||||
virtual void printOn( ostream& _s ) const{
|
||||
_s << rate;
|
||||
_s << repRate;
|
||||
}
|
||||
|
||||
/** Inherited from eoObject
|
||||
|
|
@ -89,7 +90,7 @@ template<class EOT> class eoRandomSelect: public eoSelect<EOT>
|
|||
|
||||
|
||||
private:
|
||||
float rate;
|
||||
float repRate;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -38,12 +38,12 @@
|
|||
@author JJ Merelo, 1998
|
||||
*/
|
||||
template<class EOT>
|
||||
class eoTournament:public eoSelect<EOT>{
|
||||
class eoTournament:public eoBinPopOp<EOT>{
|
||||
public:
|
||||
|
||||
/// Proportion of guys that are going to be eliminated
|
||||
eoTournament( float _perc, unsigned _tSize): eoSelect<EOT>(),
|
||||
perc( _perc), repTournamentSize(_tSize){};
|
||||
eoTournament( float _perc, unsigned _tSize):
|
||||
eoBinPopOp<EOT>(), perc( _perc), repTournamentSize(_tSize){};
|
||||
|
||||
/// Virtual dtor
|
||||
~eoTournament(){};
|
||||
|
|
@ -55,7 +55,7 @@ public:
|
|||
* Selects from the initial pop using tournament selection, and copies it
|
||||
* 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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue