Changed the populator to be a) more efficient and b) more useable
It is no longer derived from eoPop, it now gets a destination population. This saves a lot of copying. The semantics has changed a little as well. It is now an _infinite_ iterator. operator++ will *not* dispense new individuals, but will merely stay at the end. To get a new indy, use operator*() as before. eoEasyEA now checks the checkpoint *after* making a generation and clears the offspring eoGeneralBreeder is changed to reflect the changes in eoPopulator eoSequentialSelect now uses setup() rather than init()
This commit is contained in:
parent
a27aa7112a
commit
ead2ac2c62
4 changed files with 88 additions and 57 deletions
|
|
@ -60,25 +60,25 @@ template <class EOT> class eoRandomSelect: public eoSelectOne<EOT>
|
|||
template <class EOT> class eoBestSelect: public eoSelectOne<EOT>
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
/// not a big deal!!!
|
||||
virtual const EOT& operator()(const eoPop<EOT>& _pop)
|
||||
virtual const EOT& operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
return _pop.best_element() ;
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** eoSequentialSelect: returns all individual in order
|
||||
/** eoSequentialSelect: returns all individual in order
|
||||
* looping back to the beginning when exhasuted
|
||||
* can be from best to worse, or in random order
|
||||
*
|
||||
* It is the eoSelectOne equivalent of eoDetSelect -
|
||||
* It is the eoSelectOne equivalent of eoDetSelect -
|
||||
* though eoDetSelect always returns individuals from best to worst
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <class EOT> class eoSequentialSelect: public eoSelectOne<EOT>
|
||||
template <class EOT> class eoSequentialSelect: public eoSelectOne<EOT>
|
||||
{
|
||||
public:
|
||||
/** Ctor: sets the current pter to MAXINT so init will take place first time
|
||||
|
|
@ -87,19 +87,21 @@ template <class EOT> class eoSequentialSelect: public eoSelectOne<EOT>
|
|||
eoSequentialSelect(bool _ordered = true):
|
||||
ordered(_ordered), current(MAXINT) {}
|
||||
|
||||
void init(const eoPop<EOT>& _pop)
|
||||
void setup(const eoPop<EOT>& _pop)
|
||||
{
|
||||
eoPters.resize(_pop.size());
|
||||
if (ordered) // probably we could have a marker to avoid re-sorting
|
||||
_pop.sort(eoPters);
|
||||
_pop.sort(eoPters);
|
||||
else
|
||||
_pop.shuffle(eoPters);
|
||||
current=0;
|
||||
}
|
||||
|
||||
virtual const EOT& operator()(const eoPop<EOT>& _pop)
|
||||
virtual const EOT& operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
if (current >= _pop.size())
|
||||
init(_pop);
|
||||
setup(_pop);
|
||||
|
||||
unsigned eoN = current;
|
||||
current++;
|
||||
return *eoPters[eoN] ;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue