From 402e34c238445f4d9d5d2c15abfb95ae93daf9fb Mon Sep 17 00:00:00 2001 From: jeggermo Date: Mon, 2 Jul 2001 11:38:27 +0000 Subject: [PATCH] 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. --- eo/src/gp/eoParseTree.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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;