diff --git a/eo/src/gp/eoParseTree.h b/eo/src/gp/eoParseTree.h index b55d015b..7b07c85e 100644 --- a/eo/src/gp/eoParseTree.h +++ b/eo/src/gp/eoParseTree.h @@ -72,6 +72,11 @@ std::istream& operator>>(std::istream& is, eoParseTree& eot) return is; } +template +bool lt_arity(const Node &node1, const Node &node2) +{ + return (node1.arity() < node2.arity()); +} template class eoGpDepthInitializer : public eoInit< eoParseTree > @@ -94,6 +99,9 @@ class eoGpDepthInitializer : public eoInit< eoParseTree > { 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); } virtual string className() const { return "eoDepthInitializer"; }; @@ -150,7 +158,7 @@ class eoGpDepthInitializer : public eoInit< eoParseTree > private : - + unsigned max_depth; std::vector initializor; bool grow;