Index: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs	(revision 8823)
+++ trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs	(revision 8828)
@@ -134,6 +134,8 @@
       }
       QualityParameter.ActualValue = new DoubleValue(quality);
-      EvaluatedTreesParameter.ActualValue.Value += 1;
-      EvaluatedTreeNodesParameter.ActualValue.Value += solution.Length;
+      lock (locker) {
+        EvaluatedTreesParameter.ActualValue.Value += 1;
+        EvaluatedTreeNodesParameter.ActualValue.Value += solution.Length;
+      }
 
       if (Successor != null)
@@ -143,16 +145,19 @@
     }
 
+    private object locker = new object();
     private void AddResults() {
-      if (EvaluatedTreesParameter.ActualValue == null) {
-        var scope = ExecutionContext.Scope;
-        while (scope.Parent != null)
-          scope = scope.Parent;
-        scope.Variables.Add(new Core.Variable(EvaluatedTreesResultName, new IntValue()));
-      }
-      if (EvaluatedTreeNodesParameter.ActualValue == null) {
-        var scope = ExecutionContext.Scope;
-        while (scope.Parent != null)
-          scope = scope.Parent;
-        scope.Variables.Add(new Core.Variable(EvaluatedTreeNodesResultName, new IntValue()));
+      lock (locker) {
+        if (EvaluatedTreesParameter.ActualValue == null) {
+          var scope = ExecutionContext.Scope;
+          while (scope.Parent != null)
+            scope = scope.Parent;
+          scope.Variables.Add(new Core.Variable(EvaluatedTreesResultName, new IntValue()));
+        }
+        if (EvaluatedTreeNodesParameter.ActualValue == null) {
+          var scope = ExecutionContext.Scope;
+          while (scope.Parent != null)
+            scope = scope.Parent;
+          scope.Variables.Add(new Core.Variable(EvaluatedTreeNodesResultName, new IntValue()));
+        }
       }
     }
@@ -206,5 +211,6 @@
 
       AutoDiff.Term func;
-      if (!TryTransformToAutoDiff(tree.Root.GetSubtree(0), variables, parameters, variableNames, out func)) return 0.0;
+      if (!TryTransformToAutoDiff(tree.Root.GetSubtree(0), variables, parameters, variableNames, out func))
+        throw new NotSupportedException("Could not optimize constants of symbolic expression tree due to not supported symbols used in the tree.");
       if (variableNames.Count == 0) return 0.0;
 
@@ -224,5 +230,5 @@
           if (constantTreeNode != null)
             c[i++] = constantTreeNode.Value;
-          else if (variableTreeNode != null && !variableTreeNode.Weight.IsAlmost(1.0))
+          else if (variableTreeNode != null)
             c[i++] = variableTreeNode.Weight;
         }
@@ -274,5 +280,5 @@
           if (constantTreeNode != null)
             constantTreeNode.Value = c[i++];
-          else if (variableTreeNode != null && !variableTreeNode.Weight.IsAlmost(1.0))
+          else if (variableTreeNode != null)
             variableTreeNode.Weight = c[i++];
         }
@@ -304,16 +310,11 @@
       }
       if (node.Symbol is Variable) {
-        // don't tune weights with a value of 1.0 because it was probably set by the simplifier
         var varNode = node as VariableTreeNode;
         var par = new AutoDiff.Variable();
         parameters.Add(par);
         variableNames.Add(varNode.VariableName);
-        if (!varNode.Weight.IsAlmost(1.0)) {
-          var w = new AutoDiff.Variable();
-          variables.Add(w);
-          term = AutoDiff.TermBuilder.Product(w, par);
-        } else {
-          term = par;
-        }
+        var w = new AutoDiff.Variable();
+        variables.Add(w);
+        term = AutoDiff.TermBuilder.Product(w, par);
         return true;
       }
