Index: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/UpdateQualityOperator.cs
===================================================================
--- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/UpdateQualityOperator.cs	(revision 13876)
+++ branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/UpdateQualityOperator.cs	(revision 15906)
@@ -1,5 +1,5 @@
 ﻿#region License Information
 /* HeuristicLab
- * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
  *
  * This file is part of HeuristicLab.
@@ -21,4 +21,6 @@
 
 using System;
+using System.Collections;
+using System.Collections.Generic;
 using System.Linq;
 using HeuristicLab.Common;
@@ -40,4 +42,5 @@
     private const string ScaleEstimatedValuesParameterName = "ScaleEstimatedValues";
 
+    #region parameters
     public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
       get { return (ILookupParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }
@@ -55,4 +58,5 @@
       get { return (ILookupParameter<BoolValue>)Parameters[ScaleEstimatedValuesParameterName]; }
     }
+    #endregion
 
     public UpdateQualityOperator() {
@@ -76,30 +80,42 @@
     public override IOperation Apply() {
       var tree = SymbolicExpressionTreeParameter.ActualValue;
-      FixParentLinks(tree);
       var problemData = ProblemDataParameter.ActualValue;
       var estimationLimits = EstimationLimitsParameter.ActualValue;
       var interpreter = InterpreterParameter.ActualValue;
 
-      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, problemData.TrainingIndices).ToArray();
-      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices).ToArray();
+      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, problemData.TrainingIndices);
+      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices);
 
-      if (estimatedValues.Length != targetValues.Length)
-        throw new ArgumentException("Number of elements in target and estimated values enumeration do not match.");
+      var scaleEstimatedValues = ScaleEstimatedValuesParameter.ActualValue.Value;
 
-      var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();
+      IEnumerable<double> scaled;
+      if (scaleEstimatedValues) {
+        var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();
 
-      for (int i = 0; i < estimatedValues.Length; ++i) {
-        var estimated = estimatedValues[i];
-        var target = targetValues[i];
-        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated))
-          linearScalingCalculator.Add(estimated, target);
+        var e1 = estimatedValues.GetEnumerator();
+        var e2 = targetValues.GetEnumerator();
+
+        int count = 0;
+        while (e1.MoveNext() && e2.MoveNext()) {
+          var estimated = e1.Current;
+          var target = e2.Current;
+          if (!double.IsNaN(estimated) && !double.IsInfinity(estimated))
+            linearScalingCalculator.Add(estimated, target);
+          ++count;
+        }
+        if (e1.MoveNext() || e2.MoveNext())
+          throw new ArgumentException("Number of elements in target and estimated values enumeration do not match.");
+
+        double alpha = linearScalingCalculator.Alpha;
+        double beta = linearScalingCalculator.Beta;
+        if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) {
+          alpha = 0.0;
+          beta = 1.0;
+        }
+        scaled = estimatedValues.Select(x => x * beta + alpha).LimitToRange(estimationLimits.Lower, estimationLimits.Upper);
+      } else {
+        scaled = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper);
       }
-      double alpha = linearScalingCalculator.Alpha;
-      double beta = linearScalingCalculator.Beta;
-      if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) {
-        alpha = 0.0;
-        beta = 1.0;
-      }
-      var scaled = estimatedValues.Select(x => x * beta + alpha).LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
+
       OnlineCalculatorError error;
       var r = OnlinePearsonsRCalculator.Calculate(targetValues, scaled, out error);
@@ -111,26 +127,13 @@
 
       ((DoubleValue)variables["Quality"].Value).Value = r2;
-      GenealogyGraph.GetByContent(tree).Quality = r2;
-
-      var scaleEstimatedValues = ScaleEstimatedValuesParameter.ActualValue;
-      if (!scaleEstimatedValues.Value)
-        scaled = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
+      //GenealogyGraph.GetByContent(tree).Quality = r2;
 
       if (variables.ContainsKey("EstimatedValues")) {
-        variables["EstimatedValues"].Value = new DoubleArray(scaled);
+        variables["EstimatedValues"].Value = new DoubleArray(scaled.ToArray());
       } else {
-        variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(scaled)));
+        variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(scaled.ToArray())));
       }
       return base.Apply();
     }
-
-    private static void FixParentLinks(ISymbolicExpressionTree tree) {
-      foreach (var node in tree.IterateNodesPrefix().Where(x => x.SubtreeCount > 0)) {
-        foreach (var s in node.Subtrees) {
-          if (s.Parent != node)
-            s.Parent = node;
-        }
-      }
-    }
   }
 }
