Index: /branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/DiversificationStatisticsOperator.cs
===================================================================
--- /branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/DiversificationStatisticsOperator.cs	(revision 13495)
+++ /branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/DiversificationStatisticsOperator.cs	(revision 13496)
@@ -38,4 +38,6 @@
     private const string ResultCollectionParameterName = "Results";
     private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
+
+    private readonly object locker = new object();
 
     public ILookupParameter<IntValue> NumberOfChangedTreesParameter {
@@ -83,5 +85,5 @@
         table = new DataTable();
         results.Add(new Result("NumberOfChangedTrees", table));
-        var row = new DataRow("Changed trees");
+        var row = new DataRow("Changed trees") { VisualProperties = { StartIndexZero = true } };
         table.Rows.Add(row);
       }
@@ -89,5 +91,5 @@
         table = new DataTable();
         results.Add(new Result("AverageSchemaLength", table));
-        var row = new DataRow("Average schema length");
+        var row = new DataRow("Average schema length") { VisualProperties = { StartIndexZero = true } };
         table.Rows.Add(row);
       }
@@ -95,5 +97,5 @@
         table = new DataTable();
         results.Add(new Result("NumberOfSchemas", table));
-        var row = new DataRow("Number of schemas");
+        var row = new DataRow("Number of schemas") { VisualProperties = { StartIndexZero = true } };
         table.Rows.Add(row);
       }
@@ -101,10 +103,17 @@
         table = new DataTable();
         results.Add(new Result("EvaluatedSolutionsPerGeneration", table));
-        var row = new DataRow("Evaluated solutions");
+        var row = new DataRow("Evaluated solutions") { VisualProperties = { StartIndexZero = true } };
         table.Rows.Add(row);
         row.Values.Add(0);
       }
 
-      var evaluatedSolutions = EvaluatedSolutionsParameter.ActualValue.Value - evaluatedSolutionsTracker;
+      lock (locker) {
+        // count the extra evaluations performed after diversification
+        EvaluatedSolutionsParameter.ActualValue.Value += NumberOfChangedTreesParameter.ActualValue.Value;
+      }
+
+      var evaluatedSolutions = EvaluatedSolutionsParameter.ActualValue.Value;
+      if (evaluatedSolutions > 0)
+        evaluatedSolutions -= evaluatedSolutionsTracker;
       ((DataTable)results["NumberOfChangedTrees"].Value).Rows["Changed trees"].Values.Add(NumberOfChangedTreesParameter.ActualValue.Value);
       ((DataTable)results["AverageSchemaLength"].Value).Rows["Average schema length"].Values.Add(AverageSchemaLengthParameter.ActualValue.Value);
Index: /branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaCreator.cs
===================================================================
--- /branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaCreator.cs	(revision 13495)
+++ /branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaCreator.cs	(revision 13496)
@@ -51,4 +51,5 @@
     private const string UseAdaptiveReplacementRatioParameterName = "UseAdaptiveReplacementRatio";
     private const string ReplacementRatioUpdateRuleParameterName = "ReplacementRatioUpdateRule";
+    private const string StrictSchemaMatchingParameterName = "StrictSchemaMatching";
     #endregion
 
@@ -60,4 +61,7 @@
     public IFixedValueParameter<BoolValue> UseAdaptiveReplacementRatioParameter {
       get { return (IFixedValueParameter<BoolValue>)Parameters[UseAdaptiveReplacementRatioParameterName]; }
+    }
+    public IFixedValueParameter<BoolValue> StrictSchemaMatchingParameter {
+      get { return (IFixedValueParameter<BoolValue>)Parameters[StrictSchemaMatchingParameterName]; }
     }
     public IFixedValueParameter<BoolValue> ExclusiveMatchingParameter {
@@ -104,8 +108,16 @@
     public bool ExecuteInParallel { get { return ExecuteInParallelParameter.Value.Value; } }
     public double PercentageOfPopulation { get { return PercentageOfPopulationParameter.Value.Value; } }
+    public bool StrictSchemaMatching { get { return StrictSchemaMatchingParameter.Value.Value; } }
     #endregion
 
     private UpdateEstimatedValuesOperator updateEstimatedValuesOperator;
     private DiversificationStatisticsOperator diversificationStatisticsOperator;
+
+    public override void ClearState() {
+      NumberOfChangedTreesParameter.Value.Value = 0;
+      NumberOfChangedTreesParameter.Value.Value = 0;
+      AverageSchemaLengthParameter.Value.Value = 0;
+      base.ClearState();
+    }
 
     public SchemaCreator() {
@@ -121,4 +133,5 @@
       Parameters.Add(new FixedValueParameter<BoolValue>(ScaleEstimatedValuesParameterName, new BoolValue(true)));
       Parameters.Add(new FixedValueParameter<BoolValue>(ExclusiveMatchingParameterName, new BoolValue(false)));
+      Parameters.Add(new FixedValueParameter<BoolValue>(StrictSchemaMatchingParameterName, new BoolValue(false)));
       Parameters.Add(new ValueParameter<IntValue>(NumberOfChangedTreesParameterName, new IntValue(0)));
       Parameters.Add(new ValueParameter<IntValue>(NumberOfSchemasParameterName, new IntValue(0)));
@@ -126,5 +139,12 @@
       Parameters.Add(new FixedValueParameter<BoolValue>(UseAdaptiveReplacementRatioParameterName, new BoolValue(true)));
 
-      var replacementRatioUpdateRules = new ItemSet<StringValue>(new[] { new StringValue("f(x) = x"), new StringValue("f(x) = tanh(x)"), new StringValue("f(x) = tanh(2x)"), new StringValue("f(x) = tanh(3x)") });
+      var replacementRatioUpdateRules = new ItemSet<StringValue>(new[] {
+        new StringValue("f(x) = x"),
+        new StringValue("f(x) = tanh(x)"),
+        new StringValue("f(x) = tanh(2x)"),
+        new StringValue("f(x) = tanh(3x)"),
+        new StringValue("f(x) = tanh(4x)"),
+        new StringValue("f(x) = 1-sqrt(1-x)")
+      });
       Parameters.Add(new ConstrainedValueParameter<StringValue>(ReplacementRatioUpdateRuleParameterName, replacementRatioUpdateRules));
       #endregion
@@ -146,4 +166,11 @@
     protected SchemaCreator(bool deserializing) : base(deserializing) { }
 
+
+    [StorableHook(HookType.AfterDeserialization)]
+    private void AfterDeserialization() {
+      if (!Parameters.ContainsKey(StrictSchemaMatchingParameterName))
+        Parameters.Add(new FixedValueParameter<BoolValue>(StrictSchemaMatchingParameterName, new BoolValue(false)));
+    }
+
     public override IOperation Apply() {
       // apply only when at least one generation has passed
@@ -153,5 +180,4 @@
 
       var n = (int)Math.Round(ExecutionContext.Scope.SubScopes.Count * PercentageOfPopulation);
-      var scopes = new ScopeList(ExecutionContext.Scope.SubScopes.Take(n));
 
       var updateEstimatedValues = new OperationCollection { Parallel = true };
@@ -159,7 +185,5 @@
         updateEstimatedValuesOperator = new UpdateEstimatedValuesOperator();
 
-      foreach (var s in scopes) {
-        if (!s.Variables.ContainsKey("EstimatedValues"))
-          s.Variables.Add(new Core.Variable("EstimatedValues"));
+      foreach (var s in ExecutionContext.Scope.SubScopes.Where(s => !s.Variables.ContainsKey("EstimatedValues"))) {
         updateEstimatedValues.Add(ExecutionContext.CreateChildOperation(updateEstimatedValuesOperator, s));
       }
@@ -185,4 +209,12 @@
             break;
           }
+        case "f(x) = tanh(4x)": {
+            rule = x => Math.Tanh(4 * x);
+            break;
+          }
+        case "f(x) = 1-sqrt(1-x)": {
+            rule = x => 1 - Math.Sqrt(1 - x);
+            break;
+          }
         default:
           throw new ArgumentException("Unknown replacement rule");
@@ -192,4 +224,5 @@
 
       // for now, only consider crossover offspring
+      var scopes = new ScopeList(ExecutionContext.Scope.SubScopes.OrderByDescending(x => ((DoubleValue)x.Variables["Quality"].Value).Value).Take(n));
       var vertices = from s in scopes
                      let t = (ISymbolicExpressionTree)s.Variables["SymbolicExpressionTree"].Value
@@ -222,5 +255,5 @@
     public static IEnumerable<ISymbolicExpressionTree> GenerateSchemas(IEnumerable<IGenealogyGraphNode<ISymbolicExpressionTree>> vertices, int minimumSchemaLength) {
       var anySubtreeSymbol = new AnySubtreeSymbol();
-      //      var anyNodeSymbol = new AnyNodeSymbol();
+      //            var anyNodeSymbol = new AnyNodeSymbol();
       var groups = vertices.GroupBy(x => x.Parents.First()).OrderByDescending(g => g.Count()).ToList();
       var hash = new HashSet<string>();
@@ -246,8 +279,8 @@
             continue;
 
-          //          var replacement = anySubtreeSymbol.CreateTreeNode();
-          //          ReplaceSubtree(node, replacement, false);
-          var replacement = new AnyNodeSymbol(node.Symbol.MinimumArity, node.Symbol.MinimumArity).CreateTreeNode();
-          ReplaceSubtree(node, replacement, true);
+          var replacement = anySubtreeSymbol.CreateTreeNode();
+          ReplaceSubtree(node, replacement, false);
+          //          var replacement = new AnyNodeSymbol(node.Symbol.MinimumArity, node.Symbol.MinimumArity).CreateTreeNode();
+          //          ReplaceSubtree(node, replacement, true);
           replaced = true;
         }
Index: /branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaEvaluator.cs
===================================================================
--- /branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaEvaluator.cs	(revision 13495)
+++ /branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaEvaluator.cs	(revision 13496)
@@ -58,4 +58,5 @@
     private const string ExclusiveMatchingParameterName = "ExclusiveMatching";
     private const string UseAdaptiveReplacementRatioParameterName = "UseAdaptiveReplacementRatio";
+    private const string StrictSchemaMatchingParameterName = "StrictSchemaMatching";
     #endregion
 
@@ -117,4 +118,7 @@
     public LookupParameter<IntValue> NumberOfChangedTreesParameter {
       get { return (LookupParameter<IntValue>)Parameters[NumberOfChangedTreesParameterName]; }
+    }
+    public LookupParameter<BoolValue> StrictSchemaMatchingParameter {
+      get { return (LookupParameter<BoolValue>)Parameters[StrictSchemaMatchingParameterName]; }
     }
     #endregion
@@ -143,4 +147,10 @@
     [Storable]
     private readonly UpdateEstimatedValuesOperator updateEstimatedValuesOperator;
+
+    [StorableHook(HookType.AfterDeserialization)]
+    private void AfterDeserialization() {
+      if (!Parameters.ContainsKey(StrictSchemaMatchingParameterName))
+        Parameters.Add(new LookupParameter<BoolValue>(StrictSchemaMatchingParameterName));
+    }
 
     public SchemaEvaluator() {
@@ -159,4 +169,5 @@
       Parameters.Add(new LookupParameter<DoubleLimit>(EstimationLimitsParameterName));
       Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName));
+      Parameters.Add(new LookupParameter<BoolValue>(StrictSchemaMatchingParameterName));
       Parameters.Add(new LookupParameter<ISymbolicExpressionTreeManipulator>(MutatorParameterName));
       Parameters.Add(new LookupParameter<ISymbolicExpressionTreeCrossover>(CrossoverParameterName));
@@ -188,7 +199,15 @@
 
     public override IOperation Apply() {
+      var strictSchemaMatching = StrictSchemaMatchingParameter.ActualValue.Value;
+      if (strictSchemaMatching) {
+        comp.MatchVariableWeights = true;
+        comp.MatchConstantValues = true;
+      } else {
+        comp.MatchVariableWeights = false;
+        comp.MatchConstantValues = false;
+      }
+
       var individuals = ExecutionContext.Scope.SubScopes; // the scopes represent the individuals
       var trees = individuals.Select(x => (ISymbolicExpressionTree)x.Variables["SymbolicExpressionTree"].Value).ToList();
-      var qualities = individuals.Select(x => (DoubleValue)x.Variables["Quality"].Value).ToList();
 
       var random = RandomParameter.ActualValue;
Index: /branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/UpdateEstimatedValuesOperator.cs
===================================================================
--- /branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/UpdateEstimatedValuesOperator.cs	(revision 13495)
+++ /branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/UpdateEstimatedValuesOperator.cs	(revision 13496)
@@ -100,5 +100,4 @@
         beta = 1.0;
       }
-
       var scaled = estimatedValues.Select(x => x * beta + alpha).LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
       OnlineCalculatorError error;
@@ -109,4 +108,5 @@
 
       var variables = ExecutionContext.Scope.Variables;
+
       ((DoubleValue)variables["Quality"].Value).Value = r2;
 
