Index: trunk/sources/HeuristicLab.Functions/BakedFunctionTree.cs
===================================================================
--- trunk/sources/HeuristicLab.Functions/BakedFunctionTree.cs	(revision 395)
+++ trunk/sources/HeuristicLab.Functions/BakedFunctionTree.cs	(revision 396)
@@ -48,8 +48,16 @@
   class BakedFunctionTree : ItemBase, IFunctionTree {
     private List<LightWeightFunction> linearRepresentation;
+    internal List<LightWeightFunction> LinearRepresentation {
+      get {
+        FlattenVariables();
+        FlattenTrees(); 
+        return linearRepresentation;
+      }
+    }
     private bool treesExpanded = false;
     private List<IFunctionTree> subTrees;
     private bool variablesExpanded = false;
     private List<IVariable> variables;
+    private BakedTreeEvaluator evaluator;
 
     public BakedFunctionTree() {
@@ -262,14 +270,7 @@
     }
 
-    public void PrepareEvaluation(Dataset dataset) {
-      FlattenVariables();
-      FlattenTrees();
-      BakedTreeEvaluator.ResetEvaluator(dataset, linearRepresentation);
-    }
-
-    public double Evaluate(int sampleIndex) {
-      return BakedTreeEvaluator.Evaluate(sampleIndex);
-    }
-
+    public IEvaluator CreateEvaluator(Dataset dataset) {
+      return new BakedTreeEvaluator(dataset);
+    }
 
     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
Index: trunk/sources/HeuristicLab.Functions/BakedTreeEvaluator.cs
===================================================================
--- trunk/sources/HeuristicLab.Functions/BakedTreeEvaluator.cs	(revision 395)
+++ trunk/sources/HeuristicLab.Functions/BakedTreeEvaluator.cs	(revision 396)
@@ -29,5 +29,5 @@
 
 namespace HeuristicLab.Functions {
-  internal static class BakedTreeEvaluator {
+  internal class BakedTreeEvaluator : IEvaluator {
     private const int MAX_TREE_SIZE = 4096;
 
@@ -40,11 +40,12 @@
     }
 
-    private static Instr[] codeArr;
-    private static int PC;
-    private static Dataset dataset;
-    private static int sampleIndex;
-
-
-    static BakedTreeEvaluator() {
+    private Instr[] codeArr;
+    private int PC;
+    private Dataset dataset;
+    private int sampleIndex;
+
+
+    public BakedTreeEvaluator(Dataset dataset) {
+      this.dataset = dataset;
       codeArr = new Instr[MAX_TREE_SIZE];
       for(int i = 0; i < MAX_TREE_SIZE; i++) {
@@ -53,7 +54,7 @@
     }
 
-    public static void ResetEvaluator(Dataset dataset, List<LightWeightFunction> linearRepresentation) {
+    public void ResetEvaluator(IFunctionTree functionTree) {
+      List<LightWeightFunction> linearRepresentation = ((BakedFunctionTree)functionTree).LinearRepresentation;
       int i = 0;
-      BakedTreeEvaluator.dataset = dataset;
       foreach(LightWeightFunction f in linearRepresentation) {
         TranslateToInstr(f, codeArr[i++]);
@@ -61,5 +62,5 @@
     }
 
-    private static Instr TranslateToInstr(LightWeightFunction f, Instr instr) {
+    private Instr TranslateToInstr(LightWeightFunction f, Instr instr) {
       instr.arity = f.arity;
       instr.symbol = EvaluatorSymbolTable.MapFunction(f.functionType);
@@ -79,11 +80,11 @@
     }
 
-    internal static double Evaluate(int sampleIndex) {
+    public double Evaluate(int sampleIndex) {
       PC = 0;
-      BakedTreeEvaluator.sampleIndex = sampleIndex;
+      this.sampleIndex = sampleIndex;
       return EvaluateBakedCode();
     }
 
-    private static double EvaluateBakedCode() {
+    private double EvaluateBakedCode() {
       Instr currInstr = codeArr[PC++];
       switch(currInstr.symbol) {
Index: trunk/sources/HeuristicLab.Functions/HeuristicLab.Functions.csproj
===================================================================
--- trunk/sources/HeuristicLab.Functions/HeuristicLab.Functions.csproj	(revision 395)
+++ trunk/sources/HeuristicLab.Functions/HeuristicLab.Functions.csproj	(revision 396)
@@ -58,4 +58,5 @@
     <Compile Include="Differential.cs" />
     <Compile Include="GreaterThan.cs" />
+    <Compile Include="IEvaluator.cs" />
     <Compile Include="IfThenElse.cs">
       <SubType>Code</SubType>
Index: trunk/sources/HeuristicLab.Functions/IEvaluator.cs
===================================================================
--- trunk/sources/HeuristicLab.Functions/IEvaluator.cs	(revision 396)
+++ trunk/sources/HeuristicLab.Functions/IEvaluator.cs	(revision 396)
@@ -0,0 +1,11 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace HeuristicLab.Functions {
+  public interface IEvaluator {
+    void ResetEvaluator(IFunctionTree functionTree);
+    double Evaluate(int sampleIndex);
+  }
+}
Index: trunk/sources/HeuristicLab.Functions/IFunctionTree.cs
===================================================================
--- trunk/sources/HeuristicLab.Functions/IFunctionTree.cs	(revision 395)
+++ trunk/sources/HeuristicLab.Functions/IFunctionTree.cs	(revision 396)
@@ -40,6 +40,5 @@
     void RemoveSubTree(int index);
 
-    void PrepareEvaluation(Dataset dataset);
-    double Evaluate(int sampleIndex);
+    IEvaluator CreateEvaluator(Dataset dataset);
   }
 }
Index: trunk/sources/HeuristicLab.StructureIdentification/Evaluation/CoefficientOfDeterminationEvaluator.cs
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/Evaluation/CoefficientOfDeterminationEvaluator.cs	(revision 395)
+++ trunk/sources/HeuristicLab.StructureIdentification/Evaluation/CoefficientOfDeterminationEvaluator.cs	(revision 396)
@@ -49,7 +49,6 @@
       double originalDeviationTotalSumOfSquares = 0.0;
       double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd);
-      functionTree.PrepareEvaluation(dataset);
       for(int sample = trainingStart; sample < trainingEnd; sample++) {
-        double estimated = functionTree.Evaluate(sample);
+        double estimated = evaluator.Evaluate(sample);
         double original = dataset.GetValue(sample, targetVariable);
         if(!double.IsNaN(original) && !double.IsInfinity(original)) {
Index: trunk/sources/HeuristicLab.StructureIdentification/Evaluation/EarlyStoppingMeanSquaredErrorEvaluator.cs
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/Evaluation/EarlyStoppingMeanSquaredErrorEvaluator.cs	(revision 395)
+++ trunk/sources/HeuristicLab.StructureIdentification/Evaluation/EarlyStoppingMeanSquaredErrorEvaluator.cs	(revision 396)
@@ -60,7 +60,6 @@
       double errorsSquaredSum = 0;
       double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd);
-      functionTree.PrepareEvaluation(dataset);
       for(int sample = trainingStart; sample < trainingEnd; sample++) {
-        double estimated = functionTree.Evaluate(sample);
+        double estimated = evaluator.Evaluate(sample);
         double original = dataset.GetValue(sample, targetVariable);
         if(double.IsNaN(estimated) || double.IsInfinity(estimated)) {
Index: trunk/sources/HeuristicLab.StructureIdentification/Evaluation/GPEvaluatorBase.cs
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/Evaluation/GPEvaluatorBase.cs	(revision 395)
+++ trunk/sources/HeuristicLab.StructureIdentification/Evaluation/GPEvaluatorBase.cs	(revision 396)
@@ -35,4 +35,5 @@
     protected int treeSize;
     protected double totalEvaluatedNodes;
+    protected IEvaluator evaluator;
 
     public GPEvaluatorBase()
@@ -56,4 +57,6 @@
       this.treeSize = scope.GetVariableValue<IntData>("TreeSize", false).Data;
       this.totalEvaluatedNodes = scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data;
+      if(evaluator == null) evaluator = functionTree.CreateEvaluator(dataset);
+      evaluator.ResetEvaluator(functionTree);
       double result = Evaluate(scope, functionTree, targetVariable, dataset);
 
Index: trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MCCEvaluator.cs
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MCCEvaluator.cs	(revision 395)
+++ trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MCCEvaluator.cs	(revision 396)
@@ -58,7 +58,6 @@
       double negative = 0;
       double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd);
-      functionTree.PrepareEvaluation(dataset);
       for(int sample = trainingStart; sample < trainingEnd; sample++) {
-        double est = functionTree.Evaluate(sample);
+        double est = evaluator.Evaluate(sample);
         double orig = dataset.GetValue(sample, targetVariable);
         if(double.IsNaN(est) || double.IsInfinity(est)) {
Index: trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MeanAbsolutePercentageErrorEvaluator.cs
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MeanAbsolutePercentageErrorEvaluator.cs	(revision 395)
+++ trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MeanAbsolutePercentageErrorEvaluator.cs	(revision 396)
@@ -47,7 +47,6 @@
       int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
       double errorsSum = 0.0;
-      functionTree.PrepareEvaluation(dataset);
       for(int sample = trainingStart; sample < trainingEnd; sample++) {
-        double estimated = functionTree.Evaluate(sample);
+        double estimated = evaluator.Evaluate(sample);
         double original = dataset.GetValue(sample, targetVariable);
         if(!double.IsNaN(original) && !double.IsInfinity(original)) {
Index: trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MeanSquaredErrorEvaluator.cs
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MeanSquaredErrorEvaluator.cs	(revision 395)
+++ trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MeanSquaredErrorEvaluator.cs	(revision 396)
@@ -59,8 +59,6 @@
         }
       }
-
-      functionTree.PrepareEvaluation(dataset);
       for(int sample = trainingStart; sample < trainingEnd; sample++) {
-        double estimated = functionTree.Evaluate(sample);
+        double estimated = evaluator.Evaluate(sample);
         double original = dataset.GetValue(sample, targetVariable);
         if(double.IsNaN(estimated) || double.IsInfinity(estimated)) {
Index: trunk/sources/HeuristicLab.StructureIdentification/Evaluation/SimpleEvaluator.cs
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/Evaluation/SimpleEvaluator.cs	(revision 395)
+++ trunk/sources/HeuristicLab.StructureIdentification/Evaluation/SimpleEvaluator.cs	(revision 396)
@@ -34,4 +34,5 @@
     protected int treeSize;
     protected double totalEvaluatedNodes;
+    private IEvaluator evaluator;
 
     public SimpleEvaluator()
@@ -66,8 +67,9 @@
       }
       values.Clear();
-      functionTree.PrepareEvaluation(dataset);
+      if(evaluator == null) evaluator = functionTree.CreateEvaluator(dataset);
+      evaluator.ResetEvaluator(functionTree);
       for(int sample = trainingStart; sample < trainingEnd; sample++) {
         ItemList row = new ItemList();
-        row.Add(new DoubleData(functionTree.Evaluate(sample)));
+        row.Add(new DoubleData(evaluator.Evaluate(sample)));
         row.Add(new DoubleData(dataset.GetValue(sample, targetVariable)));
         values.Add(row);
Index: trunk/sources/HeuristicLab.StructureIdentification/Evaluation/TheilInequalityCoefficientEvaluator.cs
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/Evaluation/TheilInequalityCoefficientEvaluator.cs	(revision 395)
+++ trunk/sources/HeuristicLab.StructureIdentification/Evaluation/TheilInequalityCoefficientEvaluator.cs	(revision 396)
@@ -51,9 +51,8 @@
       double estimatedSquaredSum = 0.0;
       double originalSquaredSum = 0.0;
-      functionTree.PrepareEvaluation(dataset);
       for(int sample = trainingStart; sample < trainingEnd; sample++) {
         double prevValue = 0.0;
         if(difference) prevValue = dataset.GetValue(sample - 1, targetVariable);
-        double estimatedChange = functionTree.Evaluate(sample) - prevValue;
+        double estimatedChange = evaluator.Evaluate(sample) - prevValue;
         double originalChange = dataset.GetValue(sample, targetVariable) - prevValue;
         if(!double.IsNaN(originalChange) && !double.IsInfinity(originalChange)) {
Index: trunk/sources/HeuristicLab.StructureIdentification/Evaluation/VarianceAccountedForEvaluator.cs
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/Evaluation/VarianceAccountedForEvaluator.cs	(revision 395)
+++ trunk/sources/HeuristicLab.StructureIdentification/Evaluation/VarianceAccountedForEvaluator.cs	(revision 396)
@@ -59,7 +59,6 @@
       double[] originalTargetVariableValues = new double[trainingEnd-trainingStart];
       double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd);
-      functionTree.PrepareEvaluation(dataset);
       for(int sample = trainingStart; sample < trainingEnd; sample++) {
-        double estimated = functionTree.Evaluate(sample);
+        double estimated = evaluator.Evaluate(sample);
         double original = dataset.GetValue(sample, targetVariable);
         if(!double.IsNaN(original) && !double.IsInfinity(original)) {
