Index: /branches/HeuristicLab.LinqExpressionTreeInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs
===================================================================
--- /branches/HeuristicLab.LinqExpressionTreeInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs	(revision 13138)
+++ /branches/HeuristicLab.LinqExpressionTreeInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs	(revision 13139)
@@ -22,5 +22,4 @@
 using System;
 using System.Collections.Generic;
-using System.Collections.ObjectModel;
 using System.Linq;
 using System.Linq.Expressions;
@@ -62,6 +61,6 @@
     #endregion
 
-    private static readonly Func<ReadOnlyCollection<double>, IList<double>> ReadOnlyCollectionRetrieveList = GetField<ReadOnlyCollection<double>, IList<double>>("list"); // retrieve underlying field of type List from a ReadOnlyCollection
-    private static readonly Func<List<double>, double[]> ListRetrieveItems = GetField<List<double>, double[]>("_items"); // retrieve underlying field of type double[] from a List<double>
+    private static readonly MethodInfo ListGetValue = typeof(IList<double>).GetProperty("Item", new Type[] { typeof(int) }).GetGetMethod();
+    private static readonly MethodInfo DatasetGetReadOnlyDoubleValues = typeof(IDataset).GetMethod("GetReadOnlyDoubleValues", new[] { typeof(string) });
 
     public override bool CanChangeName { get { return false; } }
@@ -123,25 +122,22 @@
         EvaluatedSolutions.Value++; // increment the evaluated solutions counter
       }
-
-      var columns = dataset.DoubleVariables.Select(x => ListRetrieveItems((List<double>)ReadOnlyCollectionRetrieveList(dataset.GetReadOnlyDoubleValues(x)))).ToArray();
       var compiled = CompileTree(tree, dataset);
-      return rows.Select(x => compiled(x, columns));
-    }
-
-    public static Func<int, double[][], double> CompileTree(ISymbolicExpressionTree tree, IDataset dataset) {
+      return rows.Select(x => compiled(x, dataset));
+    }
+
+    public static Func<int, IDataset, double> CompileTree(ISymbolicExpressionTree tree, IDataset dataset) {
       var row = Expression.Parameter(typeof(int));
-      var columns = Expression.Parameter(typeof(double[][]));
-      var variableIndices = dataset.DoubleVariables.Select((x, i) => new { x, i }).ToDictionary(e => e.x, e => e.i);
-      var expr = MakeExpr(tree, variableIndices, row, columns);
-      var lambda = Expression.Lambda<Func<int, double[][], double>>(expr, row, columns);
+      var ds = Expression.Parameter(typeof(IDataset));
+      var expr = MakeExpr(tree, row, ds);
+      var lambda = Expression.Lambda<Func<int, IDataset, double>>(expr, row, ds);
       return lambda.Compile();
     }
 
-    private static Expression MakeExpr(ISymbolicExpressionTree tree, Dictionary<string, int> variableIndices, ParameterExpression row, ParameterExpression columns) {
+    private static Expression MakeExpr(ISymbolicExpressionTree tree, ParameterExpression row, ParameterExpression ds) {
       var actualRoot = tree.Root.GetSubtree(0).GetSubtree(0);
-      return MakeExpr(actualRoot, variableIndices, row, columns);
-    }
-
-    private static Expression MakeExpr(ISymbolicExpressionTreeNode node, Dictionary<string, int> variableIndices, ParameterExpression row, ParameterExpression columns) {
+      return MakeExpr(actualRoot, row, ds);
+    }
+
+    private static Expression MakeExpr(ISymbolicExpressionTreeNode node, ParameterExpression row, ParameterExpression ds) {
       var opcode = OpCodes.MapSymbolToOpCode(node);
       switch (opcode) {
@@ -149,5 +145,5 @@
           {
             var functionSymbol = (FunctionSymbol)node.Symbol;
-            return Expression.Call(functionSymbol.MethodInfo, node.Subtrees.Select(x => MakeExpr(x, variableIndices, row, columns)));
+            return Expression.Call(functionSymbol.MethodInfo, node.Subtrees.Select(x => MakeExpr(x, row, ds)));
           }
         case OpCodes.Constant:
@@ -160,15 +156,14 @@
             var variableTreeNode = (VariableTreeNode)node;
             var variableWeight = Expression.Constant(variableTreeNode.Weight);
-            var variableName = variableTreeNode.VariableName;
-            var indexExpr = Expression.Constant(variableIndices[variableName]);
-            var valuesExpr = Expression.ArrayIndex(columns, indexExpr);
-            var variableValue = Expression.ArrayIndex(valuesExpr, row);
+            var variableName = Expression.Constant(variableTreeNode.VariableName);
+            var valuesExpr = Expression.Call(ds, DatasetGetReadOnlyDoubleValues, variableName);
+            var variableValue = Expression.Call(valuesExpr, ListGetValue, row);
             return Expression.Multiply(variableWeight, variableValue);
           }
         case OpCodes.Add:
           {
-            Expression result = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            Expression result = MakeExpr(node.GetSubtree(0), row, ds);
             for (int i = 1; i < node.SubtreeCount; ++i) {
-              result = Expression.Add(result, MakeExpr(node.GetSubtree(i), variableIndices, row, columns));
+              result = Expression.Add(result, MakeExpr(node.GetSubtree(i), row, ds));
             }
             return result;
@@ -176,9 +171,9 @@
         case OpCodes.Sub:
           {
-            Expression result = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            Expression result = MakeExpr(node.GetSubtree(0), row, ds);
             if (node.SubtreeCount == 1)
               return Expression.Negate(result);
             for (int i = 1; i < node.SubtreeCount; ++i) {
-              result = Expression.Subtract(result, MakeExpr(node.GetSubtree(i), variableIndices, row, columns));
+              result = Expression.Subtract(result, MakeExpr(node.GetSubtree(i), row, ds));
             }
             return result;
@@ -186,7 +181,7 @@
         case OpCodes.Mul:
           {
-            Expression result = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            Expression result = MakeExpr(node.GetSubtree(0), row, ds);
             for (int i = 1; i < node.SubtreeCount; ++i) {
-              result = Expression.Multiply(result, MakeExpr(node.GetSubtree(i), variableIndices, row, columns));
+              result = Expression.Multiply(result, MakeExpr(node.GetSubtree(i), row, ds));
             }
             return result;
@@ -194,9 +189,9 @@
         case OpCodes.Div:
           {
-            Expression result = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            Expression result = MakeExpr(node.GetSubtree(0), row, ds);
             if (node.SubtreeCount == 1)
               return Expression.Divide(Expression.Constant(1.0), result);
             for (int i = 1; i < node.SubtreeCount; ++i) {
-              result = Expression.Divide(result, MakeExpr(node.GetSubtree(i), variableIndices, row, columns));
+              result = Expression.Divide(result, MakeExpr(node.GetSubtree(i), row, ds));
             }
             return result;
@@ -204,7 +199,7 @@
         case OpCodes.Average:
           {
-            Expression result = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            Expression result = MakeExpr(node.GetSubtree(0), row, ds);
             for (int i = 1; i < node.SubtreeCount; ++i) {
-              result = Expression.Add(result, MakeExpr(node.GetSubtree(i), variableIndices, row, columns));
+              result = Expression.Add(result, MakeExpr(node.GetSubtree(i), row, ds));
             }
             return Expression.Divide(result, Expression.Constant((double)node.SubtreeCount));
@@ -212,52 +207,52 @@
         case OpCodes.Cos:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             return Expression.Call(Cos, arg);
           }
         case OpCodes.Sin:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             return Expression.Call(Sin, arg);
           }
         case OpCodes.Tan:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             return Expression.Call(Tan, arg);
           }
         case OpCodes.Square:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             return Expression.Power(arg, Expression.Constant(2));
           }
         case OpCodes.Power:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
-            var power = MakeExpr(node.GetSubtree(1), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
+            var power = MakeExpr(node.GetSubtree(1), row, ds);
             return Expression.Power(arg, Expression.Call(Floor, power));
           }
         case OpCodes.SquareRoot:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             return Expression.Call(Sqrt, arg);
           }
         case OpCodes.Root:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
-            var power = MakeExpr(node.GetSubtree(1), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
+            var power = MakeExpr(node.GetSubtree(1), row, ds);
             return Expression.Power(arg, Expression.Divide(Expression.Constant(1.0), power));
           }
         case OpCodes.Exp:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             return Expression.Call(Exp, arg);
           }
         case OpCodes.Log:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             return Expression.Call(Log, arg);
           }
         case OpCodes.Gamma:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var gamma = Expression.Call(Gamma, arg);
@@ -277,5 +272,5 @@
         case OpCodes.Psi:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var psi = Expression.Call(Psi, arg);
@@ -300,5 +295,5 @@
         case OpCodes.Dawson:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var exprDawsonIntegral = Expression.Call(DawsonIntegral, arg);
@@ -317,5 +312,5 @@
         case OpCodes.ExponentialIntegralEi:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var expIntegrapEi =
@@ -334,5 +329,5 @@
         case OpCodes.SineIntegral:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var si = Expression.Variable(typeof(double));
@@ -356,5 +351,5 @@
         case OpCodes.CosineIntegral:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var si = Expression.Variable(typeof(double));
@@ -378,5 +373,5 @@
         case OpCodes.HyperbolicSineIntegral:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var shi = Expression.Variable(typeof(double));
@@ -400,5 +395,5 @@
         case OpCodes.HyperbolicCosineIntegral:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var shi = Expression.Variable(typeof(double));
@@ -422,5 +417,5 @@
         case OpCodes.FresnelSineIntegral:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var s = Expression.Variable(typeof(double));
@@ -440,5 +435,5 @@
         case OpCodes.FresnelCosineIntegral:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var s = Expression.Variable(typeof(double));
@@ -458,5 +453,5 @@
         case OpCodes.AiryA:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var ai = Expression.Variable(typeof(double));
@@ -478,5 +473,5 @@
         case OpCodes.AiryB:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var ai = Expression.Variable(typeof(double));
@@ -498,5 +493,5 @@
         case OpCodes.Norm:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var result = Expression.Variable(typeof(double));
@@ -511,5 +506,5 @@
         case OpCodes.Erf:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var result = Expression.Variable(typeof(double));
@@ -524,5 +519,5 @@
         case OpCodes.Bessel:
           {
-            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var arg = MakeExpr(node.GetSubtree(0), row, ds);
             var isNaN = Expression.Call(IsNaN, arg);
             var result = Expression.Variable(typeof(double));
@@ -540,9 +535,9 @@
         case OpCodes.IfThenElse:
           {
-            var test = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var test = MakeExpr(node.GetSubtree(0), row, ds);
             var result = Expression.Variable(typeof(double));
             var condition = Expression.IfThenElse(Expression.GreaterThan(test, Expression.Constant(0.0)),
-              Expression.Assign(result, MakeExpr(node.GetSubtree(1), variableIndices, row, columns)),
-              Expression.Assign(result, MakeExpr(node.GetSubtree(2), variableIndices, row, columns)));
+              Expression.Assign(result, MakeExpr(node.GetSubtree(1), row, ds)),
+              Expression.Assign(result, MakeExpr(node.GetSubtree(2), row, ds)));
             return Expression.Block(new[] { result }, condition, result);
           }
@@ -550,5 +545,5 @@
           {
             var result = Expression.Variable(typeof(double));
-            var expr = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var expr = MakeExpr(node.GetSubtree(0), row, ds);
 
             for (int i = 1; i < node.SubtreeCount; ++i) {
@@ -556,5 +551,5 @@
                 Expression.IfThenElse(
                   Expression.GreaterThan(expr, Expression.Constant(0.0)),
-                  Expression.Assign(result, MakeExpr(node.GetSubtree(i), variableIndices, row, columns)),
+                  Expression.Assign(result, MakeExpr(node.GetSubtree(i), row, ds)),
                   Expression.Assign(result, expr)),
                 result
@@ -576,5 +571,5 @@
           {
             var result = Expression.Variable(typeof(double));
-            var expr = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var expr = MakeExpr(node.GetSubtree(0), row, ds);
 
             for (int i = 1; i < node.SubtreeCount; ++i) {
@@ -582,5 +577,5 @@
                 Expression.IfThenElse(
                   Expression.LessThanOrEqual(expr, Expression.Constant(0.0)),
-                  Expression.Assign(result, MakeExpr(node.GetSubtree(i), variableIndices, row, columns)),
+                  Expression.Assign(result, MakeExpr(node.GetSubtree(i), row, ds)),
                   Expression.Assign(result, expr)),
                 result
@@ -601,5 +596,5 @@
         case OpCodes.NOT:
           {
-            var value = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
+            var value = MakeExpr(node.GetSubtree(0), row, ds);
             var result = Expression.Variable(typeof(double));
             var condition = Expression.IfThenElse(Expression.GreaterThan(value, Expression.Constant(0.0)),
@@ -618,5 +613,5 @@
 
             foreach (var subtree in node.Subtrees) {
-              var expr = MakeExpr(subtree, variableIndices, row, columns);
+              var expr = MakeExpr(subtree, row, ds);
               block = Expression.Block(
                 new[] { ps },
@@ -642,6 +637,6 @@
         case OpCodes.GT:
           {
-            var left = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
-            var right = MakeExpr(node.GetSubtree(1), variableIndices, row, columns);
+            var left = MakeExpr(node.GetSubtree(0), row, ds);
+            var right = MakeExpr(node.GetSubtree(1), row, ds);
             var result = Expression.Variable(typeof(double));
 
@@ -655,6 +650,6 @@
         case OpCodes.LT:
           {
-            var left = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
-            var right = MakeExpr(node.GetSubtree(1), variableIndices, row, columns);
+            var left = MakeExpr(node.GetSubtree(0), row, ds);
+            var right = MakeExpr(node.GetSubtree(1), row, ds);
             var result = Expression.Variable(typeof(double));
 
@@ -666,8 +661,7 @@
           {
             var variableConditionTreeNode = (VariableConditionTreeNode)node;
-            var variableName = variableConditionTreeNode.VariableName;
-            var indexExpr = Expression.Constant(variableIndices[variableName]);
-            var valuesExpr = Expression.ArrayIndex(columns, indexExpr);
-            var variableValue = Expression.ArrayIndex(valuesExpr, row);
+            var variableName = Expression.Constant(variableConditionTreeNode.VariableName);
+            var valuesExpr = Expression.Call(ds, DatasetGetReadOnlyDoubleValues, variableName);
+            var variableValue = Expression.Call(valuesExpr, ListGetValue, row);
             var variableThreshold = Expression.Constant(variableConditionTreeNode.Threshold);
             var variableSlope = Expression.Constant(variableConditionTreeNode.Slope);
@@ -677,6 +671,6 @@
             var xSlopeExp = Expression.Call(Exp, xSlope);
             var p = Expression.Divide(Expression.Constant(1), Expression.Add(Expression.Constant(1), xSlopeExp));
-            var trueBranch = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
-            var falseBranch = MakeExpr(node.GetSubtree(1), variableIndices, row, columns);
+            var trueBranch = MakeExpr(node.GetSubtree(0), row, ds);
+            var falseBranch = MakeExpr(node.GetSubtree(1), row, ds);
             return Expression.Add(
               Expression.Multiply(trueBranch, p),
