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>
|
||||
|
||||
|
|
@ -91,11 +93,13 @@
|
|||
#include <eoSelectPerc.h>
|
||||
#include <eoSelectNumber.h>
|
||||
#include <eoSelectMany.h>
|
||||
// other batch selections
|
||||
// DetSelect probably shoudl be turned into an eoSelectOne
|
||||
// other batch selections
|
||||
// DetSelect probably shoudl be turned into an eoSelectOne
|
||||
// (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>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
eoBreed.h
|
||||
eoBreed.h
|
||||
(c) Maarten Keijzer, GeNeura Team, 2000
|
||||
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -29,9 +29,11 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
#include <eoPop.h>
|
||||
#include <eoFunctor.h>
|
||||
#include <eoSelect.h>
|
||||
#include <eoTransform.h>
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
/**
|
||||
eoBreed: breeding is thought of a combination of selecting and transforming
|
||||
a population. For efficiency reasons you might want to build your own
|
||||
eoBreed derived class rather than relying on a seperate select and transform
|
||||
|
|
@ -44,7 +46,7 @@ class eoBreed : public eoBF<const eoPop<EOT>&, eoPop<EOT>&, void>
|
|||
{};
|
||||
|
||||
/**
|
||||
eoSelectTransform: special breeder that is just an application of an embedded select,
|
||||
eoSelectTransform: special breeder that is just an application of an embedded select,
|
||||
followed by an embedded transform
|
||||
*/
|
||||
template <class EOT>
|
||||
|
|
|
|||
|
|
@ -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,12 +33,16 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#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.
|
||||
*/
|
||||
template<class EOT>
|
||||
template<class EOT>
|
||||
class eoGeneralBreeder: public eoBreed<EOT>
|
||||
{
|
||||
public:
|
||||
|
|
@ -49,10 +53,13 @@ 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!
|
||||
*
|
||||
* @param _parents the initial population
|
||||
|
|
@ -69,15 +76,16 @@ class eoGeneralBreeder: public eoBreed<EOT>
|
|||
while (it.size() < target)
|
||||
{
|
||||
op(it);
|
||||
++it;
|
||||
}
|
||||
|
||||
|
||||
swap(_offspring, it);
|
||||
_offspring.resize(target); // you might have generated a few more
|
||||
}
|
||||
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoGeneralBreeder"; }
|
||||
|
||||
|
||||
private:
|
||||
eoSelectOne<EOT>& select;
|
||||
eoGenOp<EOT>& op;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public :
|
|||
struct OutOfIndividuals {};
|
||||
|
||||
/** a populator behaves like an iterator. Hence the operator*
|
||||
* it returns the current individual -- eventually getting
|
||||
* it returns the current individual -- eventually getting
|
||||
* a new one through the operator++ if at the end
|
||||
*/
|
||||
EOT& operator*(void)
|
||||
|
|
@ -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
|
||||
/** 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;
|
||||
};
|
||||
|
|
@ -133,7 +125,7 @@ class eoSeqPopulator : public eoPopulator<EOT>
|
|||
{
|
||||
public :
|
||||
|
||||
eoSeqPopulator(const eoPop<EOT>& _pop) :
|
||||
eoSeqPopulator(const eoPop<EOT>& _pop) :
|
||||
eoPopulator<EOT>(_pop), src_it(_pop.begin()) {}
|
||||
|
||||
const EOT& select(void)
|
||||
|
|
@ -149,7 +141,7 @@ public :
|
|||
|
||||
private :
|
||||
vector<EOT>::const_iterator src_it;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/** SelectivePopulator an eoPoplator that uses an eoSelectOne to select guys.
|
||||
|
|
@ -169,7 +161,7 @@ public :
|
|||
|
||||
private :
|
||||
eoSelectOne<EOT>& sel;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// eoRandomSelect.h
|
||||
// (c) GeNeura Team, 1998 - EEAAX 1999, Maarten Keijzer 2000
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -41,23 +41,23 @@
|
|||
/** eoRandomSelect: a selection method that selects ONE individual randomly */
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <class EOT> class eoRandomSelect: public eoSelectOne<EOT>
|
||||
template <class EOT> class eoRandomSelect: 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[eo::rng.random(pop.size())] ;
|
||||
return _pop[eo::rng.random(_pop.size())] ;
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** eoBestSelect: a selection method that always return the best
|
||||
/** eoBestSelect: a selection method that always return the best
|
||||
* (mainly for testing purposes) */
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <class EOT> class eoBestSelect: public eoSelectOne<EOT>
|
||||
template <class EOT> class eoBestSelect: public eoSelectOne<EOT>
|
||||
{
|
||||
public:
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
and 'genetic' operators
|
||||
|
||||
(c) Maarten Keijzer (mkeijzer@mad.scientist.com) and GeNeura Team, 1999, 2000
|
||||
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -52,7 +52,7 @@ public :
|
|||
|
||||
void operator()(ExternalEO& _eo)
|
||||
{
|
||||
_eo = (*init)();
|
||||
_eo.External::operator=( (*init)() );
|
||||
_eo.invalidate();
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue