Index: /branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
===================================================================
--- /branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs	(revision 16403)
+++ /branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs	(revision 16404)
@@ -69,21 +69,21 @@
     #endregion
 
-    public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows = null) {
+    public Interval GetSymbolicExressionTreeInterval(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows = null) {
       var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows);
-      return GetSymbolicExressionTreeIntervals(tree, variableRanges);
+      return GetSymbolicExressionTreeInterval(tree, variableRanges);
     }
 
     public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset,
-      out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals, IEnumerable<int> rows = null) {
+      out Dictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals, IEnumerable<int> rows = null) {
       var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows);
-      return GetSymbolicExressionTreeIntervals(tree, variableRanges, out intervals);
-    }
-
-    public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, Dictionary<string, Interval> customIntervalsForVariables) {
+      return GetSymbolicExressionTreeIntervals(tree, variableRanges, out nodeIntervals);
+    }
+
+    public Interval GetSymbolicExressionTreeInterval(ISymbolicExpressionTree tree, Dictionary<string, Interval> variableRanges) {
       lock (syncRoot) {
         EvaluatedSolutions++;
       }
       int instructionCount = 0;
-      var instructions = PrepareInterpreterState(tree, customIntervalsForVariables);
+      var instructions = PrepareInterpreterState(tree, variableRanges);
       var outputInterval = Evaluate(instructions, ref instructionCount);
 
@@ -93,36 +93,41 @@
 
     public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree,
-      Dictionary<string, Interval> customIntervalsForVariables, out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) {
+      Dictionary<string, Interval> variableRanges, out Dictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals) {
       lock (syncRoot) {
         EvaluatedSolutions++;
       }
       int instructionCount = 0;
-      intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
-      var instructions = PrepareInterpreterState(tree, customIntervalsForVariables);
+      var intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
+      var instructions = PrepareInterpreterState(tree, variableRanges);
       var outputInterval = Evaluate(instructions, ref instructionCount, intervals);
 
+      nodeIntervals = intervals;
+
       return outputInterval;
     }
 
 
-    private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, Dictionary<string, Interval> customIntervalsForVariables) {
+    private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, Dictionary<string, Interval> variableRanges) {
+      if (variableRanges == null)
+        throw new ArgumentNullException("No variablew ranges are present!", nameof(variableRanges));
+
+      //Check if all variables used in the tree are present in the dataset
+      foreach (var variable in tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(n => n.VariableName).Distinct()) {
+        if (!variableRanges.ContainsKey(variable)) throw new InvalidOperationException($"No ranges for variable {variable} is present");
+      }
+
       Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode);
-
-      if (customIntervalsForVariables == null)
-        throw new ArgumentException("No interval ranges are present!", nameof(customIntervalsForVariables));
-
-      foreach (var variable in tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(n => n.VariableName).Distinct()) {
-        if (!customIntervalsForVariables.ContainsKey(variable)) throw new InvalidOperationException($"No ranges for variable {variable} is present");
-      }
-
       foreach (Instruction instr in code.Where(i => i.opCode == OpCodes.Variable)) {
         var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
-        instr.data = customIntervalsForVariables[variableTreeNode.VariableName];
+        instr.data = variableRanges[variableTreeNode.VariableName];
       }
       return code;
     }
 
-    private Interval Evaluate(Instruction[] instructions, ref int instructionCount, Dictionary<ISymbolicExpressionTreeNode, Interval> intervals = null) {
-      Instruction currentInstr = instructions[instructionCount++];
+    private Interval Evaluate(Instruction[] instructions, ref int instructionCounter, Dictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = null) {
+      Instruction currentInstr = instructions[instructionCounter];
+      //Use ref parameter, because the tree will be iterated through recursively from the left-side branch to the right side
+      //Update instructionCounter, whenever Evaluate is called
+      instructionCounter++;
       Interval result = null;
 
@@ -131,8 +136,8 @@
         case OpCodes.Variable: {
             var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode;
-            var variableWeight = variableTreeNode.Weight;
-            var varibleWeightInterval = new Interval(variableWeight, variableWeight);
-
-            result = Interval.Multiply((Interval)currentInstr.data, varibleWeightInterval);
+            var weightInterval = new Interval(variableTreeNode.Weight, variableTreeNode.Weight);
+            var variableInterval = (Interval)currentInstr.data;
+
+            result = Interval.Multiply(variableInterval, weightInterval);
             break;
           }
@@ -144,7 +149,7 @@
         //Elementary arithmetic rules
         case OpCodes.Add: {
-            result = Evaluate(instructions, ref instructionCount, intervals);
-            for (int i = 1; i < currentInstr.nArguments; i++) {
-              var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+            result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
+            for (int i = 1; i < currentInstr.nArguments; i++) {
+              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
               result = Interval.Add(result, argumentInterval);
             }
@@ -152,10 +157,10 @@
           }
         case OpCodes.Sub: {
-            result = Evaluate(instructions, ref instructionCount, intervals);
+            result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
             if (currentInstr.nArguments == 1)
               result = Interval.Multiply(new Interval(-1, -1), result);
-            
-            for (int i = 1; i < currentInstr.nArguments; i++) {
-              var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+
+            for (int i = 1; i < currentInstr.nArguments; i++) {
+              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
               result = Interval.Subtract(result, argumentInterval);
             }
@@ -163,7 +168,7 @@
           }
         case OpCodes.Mul: {
-            result = Evaluate(instructions, ref instructionCount, intervals);
-            for (int i = 1; i < currentInstr.nArguments; i++) {
-              var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+            result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
+            for (int i = 1; i < currentInstr.nArguments; i++) {
+              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
               result = Interval.Multiply(result, argumentInterval);
             }
@@ -171,10 +176,10 @@
           }
         case OpCodes.Div: {
-            result = Evaluate(instructions, ref instructionCount, intervals);
-            if(currentInstr.nArguments == 1)
-              result = Interval.Divide(new Interval(1,1),result);
-
-            for (int i = 1; i < currentInstr.nArguments; i++) {
-              var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+            result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
+            if (currentInstr.nArguments == 1)
+              result = Interval.Divide(new Interval(1, 1), result);
+
+            for (int i = 1; i < currentInstr.nArguments; i++) {
+              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
               result = Interval.Divide(result, argumentInterval);
             }
@@ -183,15 +188,15 @@
         //Trigonometric functions
         case OpCodes.Sin: {
-            var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
             result = Interval.Sine(argumentInterval);
             break;
           }
         case OpCodes.Cos: {
-            var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
             result = Interval.Cosine(argumentInterval);
             break;
           }
         case OpCodes.Tan: {
-            var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
             result = Interval.Tangens(argumentInterval);
             break;
@@ -199,17 +204,17 @@
         //Exponential functions
         case OpCodes.Log: {
-            var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
             result = Interval.Logarithm(argumentInterval);
             break;
           }
         case OpCodes.Exp: {
-            var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
             result = Interval.Exponential(argumentInterval);
             break;
           }
         case OpCodes.Power: {
-            result = Evaluate(instructions, ref instructionCount, intervals);
-            for (int i = 1; i < currentInstr.nArguments; i++) {
-              var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+            result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
+            for (int i = 1; i < currentInstr.nArguments; i++) {
+              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
               result = Interval.Power(result, argumentInterval);
             }
@@ -217,12 +222,12 @@
           }
         case OpCodes.Square: {
-            var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
             result = Interval.Square(argumentInterval);
             break;
           }
         case OpCodes.Root: {
-            result = Evaluate(instructions, ref instructionCount, intervals);
-            for (int i = 1; i < currentInstr.nArguments; i++) {
-              var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+            result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
+            for (int i = 1; i < currentInstr.nArguments; i++) {
+              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
               result = Interval.Root(result, argumentInterval);
             }
@@ -230,5 +235,5 @@
           }
         case OpCodes.SquareRoot: {
-            var argumentInterval = Evaluate(instructions, ref instructionCount, intervals);
+            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
             result = Interval.SquareRoot(argumentInterval);
             break;
@@ -238,6 +243,6 @@
       }
 
-      if (intervals != null)
-        intervals.Add(currentInstr.dynamicNode, result);
+      if (nodeIntervals != null)
+        nodeIntervals.Add(currentInstr.dynamicNode, result);
 
       return result;
Index: /branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis/3.4/DatasetUtil.cs
===================================================================
--- /branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis/3.4/DatasetUtil.cs	(revision 16403)
+++ /branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis/3.4/DatasetUtil.cs	(revision 16404)
@@ -97,6 +97,4 @@
 
       foreach (var variable in dataset.VariableNames) {
-        var min = double.MaxValue;
-        var max = double.MinValue;
         IEnumerable<double> values = null;
 
@@ -104,10 +102,6 @@
         else values = dataset.GetDoubleValues(variable, rows);
 
-        foreach (var val in values) {
-          if (val < min) min = val;
-          if (val > max) max = val;
-        }
-
-        variableRanges.Add(variable, new Interval(min, max));
+        var range = Interval.GetInterval(values);
+        variableRanges.Add(variable, range);
       }
 
Index: /branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval.cs
===================================================================
--- /branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval.cs	(revision 16403)
+++ /branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval.cs	(revision 16404)
@@ -51,4 +51,22 @@
                 double.IsNaN(LowerBound) || double.IsNaN(UpperBound);
       }
+    }
+
+    public static Interval GetInterval(IEnumerable<double> values) {
+      if (values == null) throw new ArgumentNullException("The given value set is not defined.");
+      if (!values.Any()) throw new ArgumentException($"No valid values are present.");
+
+      var min = double.MaxValue;
+      var max = double.MinValue;
+
+      foreach (var value in values) {
+        //If an value is NaN return an interval [NaN, NaN]
+        if (double.IsNaN(value)) return new Interval(double.NaN, double.NaN);
+
+        if (value < min) min = value;
+        if (value > max) max = value;
+      }
+
+      return new Interval(min, max);
     }
 
