Well, what do you know, major commit.

Changed the signature of eoMon, eoBin and eoQuadOp to return a bool,
without invalidating fitness. Added a set of invalidators to take over
that job (see for instance eoSGA and eoSGATransform how this can transparantly used)

Derived eoState from eoFunctorStore (for convenience, from a design perspective this may sound wrong)

Added a wrap_op function that does the wrapping for you (see eoOpContainer how this made this functor
exceedingly less hairy). Checked all the tests removed the eoGeneric*Op family (not needed anymore)
and of course changed all the operators to reflect the change (and found a few that didn't
invalidate the fitness, thus really pointing out the advantage of the current approach)
This commit is contained in:
maartenkeijzer 2001-02-14 10:35:26 +00:00
commit 3a9b5a0e7e
30 changed files with 651 additions and 564 deletions

View file

@ -148,7 +148,7 @@ private :
unsigned max_depth;
std::vector<Node> initializor;
bool grow;
bool grow;
};
template<class FType, class Node>
@ -165,7 +165,7 @@ public:
/// Dtor
virtual ~eoSubtreeXOver () {};
void operator()(EoType & _eo1, EoType & _eo2 )
bool operator()(EoType & _eo1, EoType & _eo2 )
{
int i = rng.random(_eo1.size());
int j = rng.random(_eo2.size());
@ -173,26 +173,25 @@ public:
parse_tree<Node>::subtree tmp = _eo2[j];
_eo1[i] = _eo2[j]; // insert subtree
_eo2[j]=tmp;
_eo1.pruneTree(max_length);
_eo2.pruneTree(max_length);
_eo1.invalidate();
_eo2.invalidate();
return true;
}
unsigned max_length;
};
template<class FType, class Node>
class eoBranchMutation: public eoMonOp< eoParseTree<FType, Node> >
class eoBranchMutation: public eoMonOp< eoParseTree<FType, Node> >
{
public:
typedef eoParseTree<FType, Node> EoType;
eoBranchMutation(eoInit<EoType>& _init, unsigned _max_length)
: eoMonOp<EoType>(), max_length(_max_length), initializer(_init)
: eoMonOp<EoType>(), max_length(_max_length), initializer(_init)
{};
virtual string className() const { return "eoBranchMutation"; };
@ -200,26 +199,26 @@ public:
/// Dtor
virtual ~eoBranchMutation() {};
void operator()(EoType& _eo1 )
bool operator()(EoType& _eo1 )
{
int i = rng.random(_eo1.size());
EoType eo2;
initializer(eo2);
int j = rng.random(eo2.size());
_eo1[i] = eo2[j]; // insert subtree
_eo1.pruneTree(max_length);
_eo1.invalidate();
return true;
}
private :
unsigned max_length;
eoInit<EoType>& initializer;
eoInit<EoType>& initializer;
};