Index: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs
===================================================================
--- branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs	(revision 16593)
+++ branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs	(revision 16596)
@@ -57,5 +57,5 @@
       IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
       IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
-      OnlineCalculatorError errorState;
+      OnlineCalculatorError errorState = OnlineCalculatorError.None;
 
       IntervalConstraintsParser parser = new IntervalConstraintsParser();
@@ -65,25 +65,25 @@
 
 
-      foreach (var constraint in constraints) {
-        if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable))
-          throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser));
-        if (!constraint.IsDerivation) {
-          var res = intervalInterpreter.GetSymbolicExressionTreeInterval(solution, variableRanges);
-          if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
-            constraint.InclusiveUpperBound)) {
-            return 0;
-          }
-        } else {
-          var tree = solution;
-          for (var i = 0; i < constraint.NumberOfDerivation; ++i) {
-            tree = DerivativeCalculator.Derive(tree, constraint.Variable);
-          }
-          var res = intervalInterpreter.GetSymbolicExressionTreeInterval(tree, variableRanges);
-          if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
-            constraint.InclusiveUpperBound)) {
-            return 0;
-          }
-        }
-      }
+      //foreach (var constraint in constraints) {
+      //  if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable))
+      //    throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser));
+      //  if (!constraint.IsDerivation) {
+      //    var res = intervalInterpreter.GetSymbolicExressionTreeInterval(solution, variableRanges);
+      //    if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
+      //      constraint.InclusiveUpperBound)) {
+      //      return 0;
+      //    }
+      //  } else {
+      //    var tree = solution;
+      //    for (var i = 0; i < constraint.NumberOfDerivation; ++i) {
+      //      tree = DerivativeCalculator.Derive(tree, constraint.Variable);
+      //    }
+      //    var res = intervalInterpreter.GetSymbolicExressionTreeInterval(tree, variableRanges);
+      //    if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
+      //      constraint.InclusiveUpperBound)) {
+      //      return 0;
+      //    }
+      //  }
+      //}
       // TODO
       // m = new SymbolicRegressionModel(...)
@@ -97,19 +97,30 @@
       // constraints mit scaledTree berechnen (auch die Ableitungen)
 
-
-
       double r;
       if (applyLinearScaling) {
         var rCalculator = new OnlinePearsonsRCalculator();
         CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows);
+        var model = new SymbolicRegressionModel(problemData.TargetVariable, solution, interpreter, lowerEstimationLimit, upperEstimationLimit);
+        model.Scale(problemData);
+        var e = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices);
+        var scaledTree = model.SymbolicExpressionTree;
         errorState = rCalculator.ErrorState;
-        r = rCalculator.R;
+        if (CheckConstraintsViolations(constraints, intervalInterpreter, variableRanges, scaledTree, out var val)) {
+          r = val;
+        } else {
+          r = rCalculator.R;
+        }
       } else {
         IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
-        r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
+        if (CheckConstraintsViolations(constraints, intervalInterpreter, variableRanges, solution, out var val)) {
+          r = val;
+        } else {
+          r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
+        }
       }
       if (errorState != OnlineCalculatorError.None) return double.NaN;
       return r*r;
     }
+
 
     public override double Evaluate(IExecutionContext context, ISymbolicExpressionTree tree,
@@ -129,4 +140,33 @@
       return r2;
     }
+
+    private static bool CheckConstraintsViolations(List<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter,
+      Dictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution, out double r) {
+      foreach (var constraint in constraints) {
+        if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable))
+          throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser));
+        if (!constraint.IsDerivation) {
+          var res = intervalInterpreter.GetSymbolicExressionTreeInterval(solution, variableRanges);
+          if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
+            constraint.InclusiveUpperBound)) {
+            r = 0;
+            return true;
+          }
+        } else {
+          var tree = solution;
+          for (var i = 0; i < constraint.NumberOfDerivation; ++i) {
+            tree = DerivativeCalculator.Derive(tree, constraint.Variable);
+          }
+          var res = intervalInterpreter.GetSymbolicExressionTreeInterval(tree, variableRanges);
+          if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
+            constraint.InclusiveUpperBound)) {
+            r = 0;
+            return true;
+          }
+        }
+      }
+      r = 1;
+      return false;
+    }
   }
 }
Index: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Parser/IntervalConstraint.cs
===================================================================
--- branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Parser/IntervalConstraint.cs	(revision 16593)
+++ branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Parser/IntervalConstraint.cs	(revision 16596)
@@ -15,4 +15,17 @@
     public string Variable { get; set; }
     public int NumberOfDerivation { get; set; }
+
+    public IntervalConstraint() { }
+
+    public IntervalConstraint(string expression, string definition, Interval interval, bool inclusiveLowerBound, bool inclusiveUpperBound, bool isDerivation, string variable, int numberOfDerivation) {
+      Expression = expression;
+      Definition = definition;
+      Interval = interval;
+      InclusiveLowerBound = inclusiveLowerBound;
+      InclusiveUpperBound = inclusiveUpperBound;
+      IsDerivation = isDerivation;
+      Variable = variable;
+      NumberOfDerivation = numberOfDerivation;
+    }
   }
 }
