Index: /branches/FunctionsAndStructIdRefactoring/HeuristicLab.Constraints/SubOperatorsConstraintAnalyser.cs
===================================================================
--- /branches/FunctionsAndStructIdRefactoring/HeuristicLab.Constraints/SubOperatorsConstraintAnalyser.cs	(revision 144)
+++ /branches/FunctionsAndStructIdRefactoring/HeuristicLab.Constraints/SubOperatorsConstraintAnalyser.cs	(revision 145)
@@ -91,5 +91,6 @@
     private static bool InSet(IOperator op, ICollection<IOperator> set) {
       foreach(IOperator element in set) {
-        if(((StringData)element.GetVariable("TypeId").Value).Data ==
+        if(element==op ||
+          ((StringData)element.GetVariable("TypeId").Value).Data ==
           ((StringData)op.GetVariable("TypeId").Value).Data) {
           return true;
Index: /branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionBase.cs
===================================================================
--- /branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionBase.cs	(revision 144)
+++ /branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionBase.cs	(revision 145)
@@ -58,5 +58,5 @@
 
     public override IList<IOperator> SubOperators {
-      get { throw new NotSupportedException(); }
+      get { return new List<IOperator>(); }
     }
 
Index: /branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionTree.cs
===================================================================
--- /branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionTree.cs	(revision 144)
+++ /branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionTree.cs	(revision 145)
@@ -77,4 +77,5 @@
     public override XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
+      node.AppendChild(PersistenceManager.Persist("Function", function, document, persistedObjects));
       XmlNode subTreesNode = document.CreateNode(XmlNodeType.Element, "SubTrees", null);
       for(int i = 0; i < subTrees.Count; i++)
@@ -90,4 +91,5 @@
     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
       base.Populate(node, restoredObjects);
+      function = (IFunction)PersistenceManager.Restore(node.SelectSingleNode("Function"), restoredObjects);
       XmlNode subTreesNode = node.SelectSingleNode("SubTrees");
       for(int i = 0; i < subTreesNode.ChildNodes.Count; i++)
@@ -106,4 +108,5 @@
         clone.AddVariable((IVariable)variable.Clone(clonedObjects));
       }
+      clone.function = function;
       return clone;
     }
Index: /branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/RandomTreeCreator.cs
===================================================================
--- /branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/RandomTreeCreator.cs	(revision 144)
+++ /branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/RandomTreeCreator.cs	(revision 145)
@@ -41,7 +41,7 @@
       AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
       AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In));
-      AddVariableInfo(new VariableInfo("OperatorTree", "The tree to mutate", typeof(IFunctionTree), VariableKind.In));
-      AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
-      AddVariableInfo(new VariableInfo("TreeHeight", "The height of the tree", typeof(IntData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("FunctionTree", "The created tree", typeof(IFunctionTree), VariableKind.New | VariableKind.Out));
+      AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.New | VariableKind.Out));
+      AddVariableInfo(new VariableInfo("TreeHeight", "The height of the tree", typeof(IntData), VariableKind.New | VariableKind.Out));
     }
 
@@ -67,7 +67,7 @@
       int actualTreeHeight = gardener.GetTreeHeight(root);
 
-      scope.AddVariable(new HeuristicLab.Core.Variable("OperatorTree", root));
-      scope.AddVariable(new HeuristicLab.Core.Variable("TreeSize", new IntData(actualTreeSize)));
-      scope.AddVariable(new HeuristicLab.Core.Variable("TreeHeight", new IntData(actualTreeHeight)));
+      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("FunctionTree"), root));
+      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeSize"), new IntData(actualTreeSize)));
+      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeHeight"), new IntData(actualTreeHeight)));
 
       if(!gardener.IsValidTree(root)) { throw new InvalidProgramException(); }
Index: /branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/TreeGardener.cs
===================================================================
--- /branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/TreeGardener.cs	(revision 144)
+++ /branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/TreeGardener.cs	(revision 145)
@@ -325,11 +325,14 @@
 
     internal bool IsValidTree(IFunctionTree tree) {
-      if (!tree.Function.IsValid())
-        return false;
-      foreach (IFunctionTree subTree in tree.SubTrees) {
-        if (!subTree.Function.IsValid())
-          return false;
-      }
-
+      foreach(IConstraint constraint in tree.Function.Constraints) {
+        if(constraint is NumberOfSubOperatorsConstraint) {
+          int max = ((NumberOfSubOperatorsConstraint)constraint).MaxOperators.Data;
+          int min = ((NumberOfSubOperatorsConstraint)constraint).MinOperators.Data;
+          if(tree.SubTrees.Count < min || tree.SubTrees.Count > max) return false;
+        }
+      }
+      foreach(IFunctionTree subTree in tree.SubTrees) {
+        if(!IsValidTree(subTree)) return false;
+      }
       return true;
     }
