Index: trunk/sources/HeuristicLab.Functions/ProgrammableFunction.cs
===================================================================
--- trunk/sources/HeuristicLab.Functions/ProgrammableFunction.cs	(revision 165)
+++ trunk/sources/HeuristicLab.Functions/ProgrammableFunction.cs	(revision 189)
@@ -119,83 +119,98 @@
     }
 
-    public double Evaluate(Dataset dataset, int sampleIndex, IFunctionTree tree) {
-      // evaluate sub-trees
-      double[] evaluationResults = new double[tree.SubTrees.Count];
-      for(int subTree=0; subTree < tree.SubTrees.Count; subTree++) {
-        evaluationResults[subTree] = tree.SubTrees[subTree].Evaluate(dataset, sampleIndex);
-      }
+    public IFunctionTree GetTreeNode() {
+      return new ProgrammableFunctionTree(this);
+    }
+
+    // application of programmable-function is not possible
+    public double Apply(Dataset dataset, int sampleIndex, double[] args) {
+      throw new NotSupportedException();
+    }
+
+    internal double Call(object[] parameters) {
       // lazy activation of the user-programmed code
       if(applyMethod == null) {
         Compile();
       }
+      return (double)applyMethod.Invoke(null, parameters);
+    }
+
+    #endregion
+
+    #region disabled operator functionality
+    // operator-tree style evaluation is not supported for functions.
+    public override IOperation Apply(IScope scope) {
+      throw new NotSupportedException();
+    }
+
+    private static readonly List<IOperator> emptySubOperatorList = new List<IOperator>();
+    public override IList<IOperator> SubOperators {
+      get { return emptySubOperatorList; }
+    }
+
+    public override void AddSubOperator(IOperator subOperator) {
+      throw new NotSupportedException();
+    }
+
+    public override bool TryAddSubOperator(IOperator subOperator) {
+      throw new NotSupportedException();
+    }
+
+    public override bool TryAddSubOperator(IOperator subOperator, int index) {
+      throw new NotSupportedException();
+    }
+
+    public override bool TryAddSubOperator(IOperator subOperator, int index, out ICollection<IConstraint> violatedConstraints) {
+      throw new NotSupportedException();
+    }
+
+    public override bool TryAddSubOperator(IOperator subOperator, out ICollection<IConstraint> violatedConstraints) {
+      throw new NotSupportedException();
+    }
+
+    public override void AddSubOperator(IOperator subOperator, int index) {
+      throw new NotSupportedException();
+    }
+
+    public override void RemoveSubOperator(int index) {
+      throw new NotSupportedException();
+    }
+
+    public override bool TryRemoveSubOperator(int index) {
+      throw new NotSupportedException();
+    }
+
+    public override bool TryRemoveSubOperator(int index, out ICollection<IConstraint> violatedConstraints) {
+      throw new NotSupportedException();
+    }
+    #endregion
+  }
+
+  class ProgrammableFunctionTree : FunctionTree {
+    private ProgrammableFunction progFun;
+    public ProgrammableFunctionTree() : base() { }
+    public ProgrammableFunctionTree(ProgrammableFunction progFun) : base(progFun) {
+      this.progFun = progFun;
+    }
+    public override double Evaluate(Dataset dataset, int sampleIndex) {
+      // evaluate sub-trees
+      double[] evaluationResults = new double[SubTrees.Count];
+      for(int subTree = 0; subTree < SubTrees.Count; subTree++) {
+        evaluationResults[subTree] = SubTrees[subTree].Evaluate(dataset, sampleIndex);
+      }
 
       // collect parameters
-      object[] parameters = new object[VariableInfos.Count + 3];
+      object[] parameters = new object[LocalVariables.Count + 3];
       parameters[0] = dataset;
       parameters[1] = sampleIndex;
       int i = 2;
       // all local variables are available in the custom function
-      foreach(IVariable variable in tree.LocalVariables) {
+      foreach(IVariable variable in LocalVariables) {
         parameters[i] = variable;
         i++;
       }
       parameters[i] = evaluationResults;
-      return (double)applyMethod.Invoke(null, parameters);
-    }
-
-    // application of programmable-function is not possible
-    public double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      throw new NotSupportedException();
-    }
-
-    #endregion
-
-    #region disabled operator functionality
-    // operator-tree style evaluation is not supported for functions.
-    public override IOperation Apply(IScope scope) {
-      throw new NotSupportedException();
-    }
-
-    private static readonly List<IOperator> emptySubOperatorList = new List<IOperator>();
-    public override IList<IOperator> SubOperators {
-      get { return emptySubOperatorList; }
-    }
-
-    public override void AddSubOperator(IOperator subOperator) {
-      throw new NotSupportedException();
-    }
-
-    public override bool TryAddSubOperator(IOperator subOperator) {
-      throw new NotSupportedException();
-    }
-
-    public override bool TryAddSubOperator(IOperator subOperator, int index) {
-      throw new NotSupportedException();
-    }
-
-    public override bool TryAddSubOperator(IOperator subOperator, int index, out ICollection<IConstraint> violatedConstraints) {
-      throw new NotSupportedException();
-    }
-
-    public override bool TryAddSubOperator(IOperator subOperator, out ICollection<IConstraint> violatedConstraints) {
-      throw new NotSupportedException();
-    }
-
-    public override void AddSubOperator(IOperator subOperator, int index) {
-      throw new NotSupportedException();
-    }
-
-    public override void RemoveSubOperator(int index) {
-      throw new NotSupportedException();
-    }
-
-    public override bool TryRemoveSubOperator(int index) {
-      throw new NotSupportedException();
-    }
-
-    public override bool TryRemoveSubOperator(int index, out ICollection<IConstraint> violatedConstraints) {
-      throw new NotSupportedException();
-    }
-    #endregion
+      return progFun.Call(parameters);
+    }
   }
 }
