The constructor for the eoGpDepthInitializer has been extended with a

sort of the initializor vector containing all possible nodes. This sort
assures that the terminals are in the front of vector. Untill now this
was assumed but not checked or enforced.
This commit is contained in:
jeggermo 2001-07-02 11:38:27 +00:00
commit 402e34c238

View file

@ -72,6 +72,11 @@ std::istream& operator>>(std::istream& is, eoParseTree<FType, Node>& eot)
return is;
}
template <class Node>
bool lt_arity(const Node &node1, const Node &node2)
{
return (node1.arity() < node2.arity());
}
template <class FType, class Node>
class eoGpDepthInitializer : public eoInit< eoParseTree<FType, Node> >
@ -94,6 +99,9 @@ class eoGpDepthInitializer : public eoInit< eoParseTree<FType, Node> >
{
throw logic_error("eoGpDepthInitializer: uhm, wouldn't you rather give a non-empty set of Nodes?");
}
// lets sort the initializor vector according to arity (so we can be sure the terminals are in front)
// we use stable_sort so that if element i was in front of element j and they have the same arity i remains in front of j
stable_sort(initializor.begin(), initializor.end(), lt_arity<Node>);
}
virtual string className() const { return "eoDepthInitializer"; };
@ -150,7 +158,7 @@ class eoGpDepthInitializer : public eoInit< eoParseTree<FType, Node> >
private :
unsigned max_depth;
std::vector<Node> initializor;
bool grow;