Index: branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs
===================================================================
--- branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs	(revision 143)
+++ branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs	(revision 144)
@@ -75,5 +75,5 @@
           // no parent means the new child is the initial operator
           // and we have to update the value in the variable
-          scope.GetVariable("FunctionTree").Value = newTerminal;
+          scope.GetVariable(scope.TranslateName("FunctionTree")).Value = newTerminal;
         } else {
           parent.RemoveSubTree(selectedChildIndex);
@@ -92,5 +92,5 @@
           // no parent means the new function is the initial operator
           // and we have to update the value in the variable
-          scope.GetVariable("FunctionTree").Value = newFunction;
+          scope.GetVariable(scope.TranslateName("FunctionTree")).Value = newFunction;
           root = newFunction;
         } else {
@@ -124,16 +124,16 @@
     private IFunctionTree ChangeTerminalType(IFunctionTree parent, IFunctionTree child, int childIndex, TreeGardener gardener, MersenneTwister random) {
 
-      IList<IOperator> allowedChildren;
+      IList<IFunction> allowedChildren;
       if (parent == null) {
         allowedChildren = gardener.Terminals;
       } else {
         SubOperatorsConstraintAnalyser analyser = new SubOperatorsConstraintAnalyser();
-        analyser.AllPossibleOperators = gardener.Terminals;
-        allowedChildren = analyser.GetAllowedOperators(parent, childIndex);
+        analyser.AllPossibleOperators = gardener.Terminals.Cast<IOperator>().ToArray();
+        allowedChildren = analyser.GetAllowedOperators(parent.Function, childIndex).Cast<IFunction>().ToList();
       }
 
       // selecting from the terminals should always work since the current child was also a terminal
       // so in the worst case we will just create a new terminal of the same type again.
-      return gardener.CreateRandomTree((IOperator)allowedChildren[random.Next(allowedChildren.Count)].Clone(), 1, 1, false);
+      return gardener.CreateRandomTree(allowedChildren[random.Next(allowedChildren.Count)], 1, 1, false);
     }
 
@@ -143,13 +143,13 @@
       // and how many of the existing subtrees we can reuse
 
-      // let's choose the operator we want to use instead of the old child. For this we have to determine the
-      // pool of allowed operators based on constraints of the parent if there is one.
-      IList<IOperator> allowedSubOperators;
+      // let's choose the function we want to use instead of the old child. For this we have to determine the
+      // pool of allowed functions based on constraints of the parent if there is one.
+      IList<IFunction> allowedFunctions;
       SubOperatorsConstraintAnalyser analyser = new SubOperatorsConstraintAnalyser();
-      analyser.AllPossibleOperators = gardener.AllFunctions;
+      analyser.AllPossibleOperators = gardener.AllFunctions.Cast<IOperator>().ToArray();
       if (parent == null) {
-        allowedSubOperators = gardener.AllFunctions;
-      } else {
-        allowedSubOperators = analyser.GetAllowedOperators(parent, childIndex);
+        allowedFunctions = gardener.AllFunctions;
+      } else {
+        allowedFunctions = analyser.GetAllowedOperators(parent.Function, childIndex).Cast<IFunction>().ToList();
       }
 
@@ -160,13 +160,13 @@
       int maxArity;
 
-      allowedSubOperators = allowedSubOperators.Where(f => {
+      allowedFunctions = allowedFunctions.Where(f => {
         gardener.GetMinMaxArity(f, out minArity, out maxArity);
         return minArity <= actualArity;
       }).ToList();
 
-      IFunctionTree newTree = new FunctionTree((IOperator)allowedSubOperators[random.Next(allowedSubOperators.Count)]);
-
-      gardener.GetMinMaxArity(newOperator, out minArity, out maxArity);
-      // if the old child had too many sub-operators then make the new child with the maximal arity
+      IFunctionTree newTree = new FunctionTree(allowedFunctions[random.Next(allowedFunctions.Count)]);
+
+      gardener.GetMinMaxArity(newTree.Function, out minArity, out maxArity);
+      // if the old child had too many sub-trees then make the new child with the maximal arity
       if (actualArity > maxArity)
         actualArity = maxArity;
@@ -180,18 +180,18 @@
       // create a list that holds old sub-trees that we can reuse in the new tree
       List<IFunctionTree> availableSubTrees = new List<IFunctionTree>(child.SubTrees);
-      List<IFunctionTree> freshSubTrees = new List<IFunctionTree>() { new FunctionTree(newOperator) };
-
-      // randomly select the suboperators that we keep
+      List<IFunctionTree> freshSubTrees = new List<IFunctionTree>() { newTree };
+
+      // randomly select the sub-trees that we keep
       for (int i = 0; i < actualArity; i++) {
-        // fill all sub-operator slots of the new operator
-        // if for a given slot i there are existing sub-operators that can be used in that slot
-        // then use a random existing sub-operator. When there are no existing sub-operators
+        // fill all sub-tree slots of the new tree
+        // if for a given slot i there are existing sub-trees that can be used in that slot
+        // then use a random existing sub-tree. When there are no existing sub-trees
         // that fit in the given slot then create a new random tree and use it for the slot
-        IList<IOperator> allowedOperators = analyser.GetAllowedOperators(newOperator, i);
+        IList<IFunction> allowedOperators = analyser.GetAllowedOperators(newTree.Function, i).Cast<IFunction>().ToList();
         var matchingSubTrees = availableSubTrees.Where(subTree => allowedOperators.Contains(subTree.Function));
 
         if (matchingSubTrees.Count() > 0) {
-          IFunctionTree selectedSubTree = matchingSubTrees.ElementAt(random.Next(matchingTrees.Count()));
-          // we can just add it as suboperator
+          IFunctionTree selectedSubTree = matchingSubTrees.ElementAt(random.Next(matchingSubTrees.Count()));
+          // we can just add it as subtree
           newTree.InsertSubTree(i, selectedSubTree);
           availableSubTrees.Remove(selectedSubTree); // the branch shouldn't be available for the following slots
Index: branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation/SubstituteSubTreeManipulation.cs
===================================================================
--- branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation/SubstituteSubTreeManipulation.cs	(revision 143)
+++ branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation/SubstituteSubTreeManipulation.cs	(revision 144)
@@ -27,4 +27,5 @@
 using HeuristicLab.Operators;
 using HeuristicLab.Random;
+using HeuristicLab.Functions;
 
 namespace HeuristicLab.StructureIdentification {
@@ -42,12 +43,11 @@
       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 manipulate", typeof(IOperator), 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 tree to manipulate", typeof(IFunctionTree), VariableKind.In | VariableKind.Out));
+      AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In | VariableKind.Out));
+      AddVariableInfo(new VariableInfo("TreeHeight", "The height of the tree", typeof(IntData), VariableKind.In | VariableKind.Out));
     }
 
     public override IOperation Apply(IScope scope) {
-      IOperator rootOperator = GetVariableValue<IOperator>("OperatorTree", scope, true);
-
+      IFunctionTree root = GetVariableValue<IFunctionTree>("FunctionTree", scope, true);
       MersenneTwister random = GetVariableValue<MersenneTwister>("Random", scope, true);
       GPOperatorLibrary library = GetVariableValue<GPOperatorLibrary>("OperatorLibrary", scope, true);
@@ -60,37 +60,34 @@
       TreeGardener gardener = new TreeGardener(random, library);
 
-      IOperator parent = gardener.GetRandomParentNode(rootOperator);
+      IFunctionTree parent = gardener.GetRandomParentNode(root);
       if(parent == null) {
         // parent == null means we should subsitute the whole tree
         // => create a new random tree
 
-        // create a new random operator tree
-
-        IOperator newOperatorTree;
+        // create a new random function tree
+        IFunctionTree newTree;
         if(random.NextDouble() <= balancedTreesRate) {
-          newOperatorTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight, true);
+          newTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight, true);
         } else {
-          newOperatorTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight, false);
+          newTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight, false);
         }
 
-        if(!gardener.IsValidTree(newOperatorTree)) {
+        if(!gardener.IsValidTree(newTree)) {
           throw new InvalidProgramException();
         }
 
         // update the variables in the scope with the new values
-        GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(newOperatorTree);
-        GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(newOperatorTree);
-        scope.GetVariable("OperatorTree").Value = newOperatorTree;
+        GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(newTree);
+        GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(newTree);
+        scope.GetVariable(scope.TranslateName("FunctionTree")).Value = newTree;
         
-        // return a CompositeOperation that randomly initializes the new operator
-        return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newOperatorTree), scope);
+        // return a CompositeOperation that randomly initializes the new tree
+        return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newTree), scope);
       } else {
         // determine a random child of the parent to be replaced
-        int childIndex = random.Next(parent.SubOperators.Count);
-
-        // get the list of allowed suboperators as the new child
-        IList<IOperator> allowedOperators = gardener.GetAllowedSubFunctions(parent, childIndex);
-
-        if(allowedOperators.Count == 0) {
+        int childIndex = random.Next(parent.SubTrees.Count);
+        // get the list of allowed functions for the new sub-tree
+        IList<IFunction> allowedFunctions = gardener.GetAllowedSubFunctions(parent.Function, childIndex);
+        if(allowedFunctions.Count == 0) {
           // don't change anything
           // this shouldn't happen
@@ -100,32 +97,31 @@
         // calculate the maximum size and height of the new sub-tree based on the location where
         // it will be inserted
-        int parentLevel = gardener.GetBranchLevel(rootOperator, parent);
+        int parentLevel = gardener.GetBranchLevel(root, parent);
 
         int maxSubTreeHeight = maxTreeHeight - parentLevel;
-        int maxSubTreeSize = maxTreeSize - (treeSize - gardener.GetTreeSize(parent.SubOperators[childIndex]));
+        int maxSubTreeSize = maxTreeSize - (treeSize - gardener.GetTreeSize(parent.SubTrees[childIndex]));
 
-        // get a random operatorTree
-        IOperator newOperatorTree;
+        // create a random function tree
+        IFunctionTree newTree;
         if(random.NextDouble() <= balancedTreesRate) {
-          newOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, true);
+          newTree = gardener.CreateRandomTree(allowedFunctions, maxSubTreeSize, maxSubTreeHeight, true);
         } else {
-          newOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, false);
+          newTree = gardener.CreateRandomTree(allowedFunctions, maxSubTreeSize, maxSubTreeHeight, false);
         }
 
-        IOperator oldChild = parent.SubOperators[childIndex];
-        parent.RemoveSubOperator(childIndex);
-        parent.AddSubOperator(newOperatorTree, childIndex);
+        IFunctionTree oldChild = parent.SubTrees[childIndex];
+        parent.RemoveSubTree(childIndex);
+        parent.InsertSubTree(childIndex, newTree);
 
-        if(!gardener.IsValidTree(rootOperator)) {
+        if(!gardener.IsValidTree(root)) {
           throw new InvalidProgramException();
         }
 
         // update the values of treeSize and treeHeight
-        GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(rootOperator);
-        GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(rootOperator);
-        // the root operator hasn't changed so we don't need to update 
-
+        GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root);
+        GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root);
+        // the root hasn't changed so we don't need to update 
         // return a CompositeOperation that randomly initializes all nodes of the new subtree
-        return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newOperatorTree), scope);
+        return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newTree), scope);
       }
     }
