Various bugs found and resolved.
This commit is contained in:
parent
4f1802c4e9
commit
4388faec2e
7 changed files with 56 additions and 42 deletions
|
|
@ -66,6 +66,8 @@
|
|||
#include <eoInit.h>
|
||||
|
||||
#include <eoOp.h>
|
||||
#include <eoGenOp.h>
|
||||
#include <eoOpContainer.h>
|
||||
|
||||
#include <eoPop.h>
|
||||
|
||||
|
|
@ -96,6 +98,8 @@
|
|||
// (using setup and an index)
|
||||
#include <eoDetSelect.h>
|
||||
|
||||
// Breeders
|
||||
#include <eoGeneralBreeder.h>
|
||||
|
||||
// Replacement
|
||||
// #include <eoReplacement.h>
|
||||
|
|
@ -118,6 +122,7 @@
|
|||
#include <utils/checkpointing>
|
||||
|
||||
// aliens
|
||||
#include <other/external_eo>
|
||||
#include <eoCounter.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
#include <eoPop.h>
|
||||
#include <eoFunctor.h>
|
||||
#include <eoSelect.h>
|
||||
#include <eoTransform.h>
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -58,7 +58,11 @@ class eoGenOp : public eoOp<EOT>, public eoUF<eoPopulator<EOT> &, void>
|
|||
/// Ctor that honors its superclass
|
||||
eoGenOp(): eoOp<EOT>( eoOp<EOT>::general ) {}
|
||||
|
||||
/** Max production is used to reserve space for all elements that are used by the operator,
|
||||
not setting it properly can result in a crash
|
||||
*/
|
||||
virtual unsigned max_production(void) = 0;
|
||||
|
||||
virtual string className() = 0;
|
||||
void operator()(eoPopulator<EOT>& _pop)
|
||||
{
|
||||
|
|
@ -103,18 +107,18 @@ class eoBinGenOp : public eoGenOp<EOT>
|
|||
public:
|
||||
eoBinGenOp(eoBinOp<EOT>& _op) : op(_op) {}
|
||||
|
||||
unsigned max_production(void) { return 1; }
|
||||
unsigned max_production(void) { return 2; } //2 as it will request two individuals
|
||||
|
||||
/** do the work: get 2 individuals from the population, modifies
|
||||
only one (it's a eoBinOp) and erases the non-midified one
|
||||
only one (it's a eoBinOp)
|
||||
*/
|
||||
void apply(eoPopulator<EOT>& _pop)
|
||||
{
|
||||
EOT& a = *_pop;
|
||||
EOT& b = *++_pop;
|
||||
const EOT& b = _pop.select();
|
||||
|
||||
if (op(a, b))
|
||||
a.invalidate();
|
||||
_pop.erase(); // erase the b from the next population
|
||||
}
|
||||
string className() {return op.className();}
|
||||
|
||||
|
|
@ -206,6 +210,9 @@ class eoQuadGenOp : public eoGenOp<EOT>
|
|||
case eoOp<EOT>::quadratic : return _store.storeFunctor(new eoQuadGenOp<EOT>(static_cast<eoQuadOp<EOT>&>(_op)));
|
||||
case eoOp<EOT>::general : return static_cast<eoGenOp<EOT>&>(_op);
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return static_cast<eoGenOp<EOT>&>(_op);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -33,7 +33,11 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <eoOp.h>
|
||||
#include <eoGenOp.h>
|
||||
#include <eoPopulator.h>
|
||||
#include <eoSelectOne.h>
|
||||
#include <eoBreed.h>
|
||||
#include <utils/eoHowMany.h>
|
||||
|
||||
/**
|
||||
Base class for breeders using generalized operators.
|
||||
|
|
@ -49,9 +53,12 @@ class eoGeneralBreeder: public eoBreed<EOT>
|
|||
* @param _rate pour howMany, le nbre d'enfants a generer
|
||||
* @param _interpret_as_rate <a href="../../tutorial/html/eoEngine.html#howmany">explanation</a>
|
||||
*/
|
||||
eoGeneralBreeder( eoSelectOne<EOT>& _select, eoGenOp<EOT>& _op,
|
||||
double _rate=1.0, bool _interpret_as_rate = true) :
|
||||
select( _select ), op(_op), howMany(_rate, _interpret_as_rate) {}
|
||||
eoGeneralBreeder(
|
||||
eoSelectOne<EOT>& _select,
|
||||
eoGenOp<EOT>& _op,
|
||||
double _rate=1.0,
|
||||
bool _interpret_as_rate = true) :
|
||||
select( _select ), op(_op), howMany(_rate, _interpret_as_rate) {}
|
||||
|
||||
/** The breeder: simply calls the genOp on a selective populator!
|
||||
*
|
||||
|
|
@ -69,6 +76,7 @@ class eoGeneralBreeder: public eoBreed<EOT>
|
|||
while (it.size() < target)
|
||||
{
|
||||
op(it);
|
||||
++it;
|
||||
}
|
||||
|
||||
swap(_offspring, it);
|
||||
|
|
|
|||
|
|
@ -83,15 +83,6 @@ public :
|
|||
current = eoPop<EOT>::insert(current, _eo);
|
||||
}
|
||||
|
||||
/** useful for operators that generate less offspring than parents
|
||||
* though there is another way - using a selector *within*
|
||||
* the operator to get the extra parents from outside
|
||||
*/
|
||||
void erase()
|
||||
{
|
||||
current = eoPop<EOT>::erase(current);
|
||||
}
|
||||
|
||||
/** just to make memory mangement more efficient
|
||||
*/
|
||||
void reserve(int how_many)
|
||||
|
|
@ -115,11 +106,12 @@ public :
|
|||
/** no more individuals */
|
||||
bool exhausted(void) { return current == end(); }
|
||||
|
||||
virtual const EOT& select() = 0;
|
||||
|
||||
protected :
|
||||
/** the pure virtual selection method - will be instanciated in
|
||||
* eoSeqPopulator and eoPropPopulator
|
||||
*/
|
||||
virtual const EOT& select() = 0;
|
||||
eoPop<EOT>::iterator current;
|
||||
const eoPop<EOT>& src;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ template <class EOT> class eoRandomSelect: public eoSelectOne<EOT>
|
|||
/// not a big deal!!!
|
||||
virtual const EOT& operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
return _pop[eo::rng.random(pop.size())] ;
|
||||
return _pop[eo::rng.random(_pop.size())] ;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public :
|
|||
|
||||
void operator()(ExternalEO& _eo)
|
||||
{
|
||||
_eo = (*init)();
|
||||
_eo.External::operator=( (*init)() );
|
||||
_eo.invalidate();
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue