Index: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
===================================================================
--- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs	(revision 14574)
+++ branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs	(revision 14575)
@@ -35,4 +35,5 @@
   public class TraceCalculator : Item {
     private Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>> nodeListCache;
+    // the trace cache consits of tuples of the current and last vertices, the subtree index to be traced in the current vertex, and the last subtree and fragment indexes
     private HashSet<Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, int, IGenealogyGraphNode<ISymbolicExpressionTree>, int, int>> traceCache;
     public IGenealogyGraph<ISymbolicExpressionTree> TraceGraph { get; private set; }
@@ -105,6 +106,6 @@
     private void TraceRecursive(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex, IGenealogyGraphNode<ISymbolicExpressionTree> last = null, int lastSi = -1, int lastFi = -1) {
       var g = node;
-      int si = subtreeIndex; // subtree index
-      int fi = 0; // fragment index
+      var si = subtreeIndex; // subtree index
+      var fi = 0; // fragment index
       while (((List<IArc>)((IVertex)g).InArcs).Count > 0) {
         if (!(si < g.Data.Length)) throw new ArgumentOutOfRangeException("The subtree index exceeds the size of the tree.");
@@ -148,18 +149,16 @@
               var n = AddTraceNode(g); // current node becomes "last" as we restart tracing from the parent
               if (CacheTraceNodes) {
-                var t0 = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, int, IGenealogyGraphNode<ISymbolicExpressionTree>, int, int>(parent0, si, n, si, fi);
-                var t1 = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, int, IGenealogyGraphNode<ISymbolicExpressionTree>, int, int>(parent1, fragment.Index2, n, si, fi);
-                if (!traceCache.Contains(t0)) {
-                  traceCache.Add(t0);
+                var t0 = Tuple.Create(parent0, si, n, si, fi);
+                var t1 = Tuple.Create(parent1, fragment.Index2, n, si, fi);
+                // trace subtree
+                if (traceCache.Add(t0))
                   TraceRecursive(parent0, si, n, si, fi);
-                } else {
+                else
                   TraceCacheHits++;
-                }
-                if (!traceCache.Contains(t1)) {
-                  traceCache.Add(t1);
+                // trace fragment
+                if (traceCache.Add(t1))
                   TraceRecursive(parent1, fragment.Index2, n, si, fi);
-                } else {
+                else
                   TraceCacheHits++;
-                }
               } else {
                 TraceRecursive(parent0, si, n, si, fi);
@@ -182,11 +181,17 @@
           Debug.Assert(fragment.Index1 == fragment.Index2);
           // check if the subtree and the fragment overlap => branch out
+          // optionally we could ignore the case when the fragment contains the subtree:
+          // ((si == fi) || fi < si && si < fi + fl) 
           if ((si == fi) || (si < fi && fi < si + sl) || (fi < si && si < fi + fl)) {
             var n = AddTraceNode(g); // current node becomes "last" as we restart tracing from the parent
             int i = si < fi ? si : fi;
-            var t = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, int, IGenealogyGraphNode<ISymbolicExpressionTree>, int, int>(parent0, i, n, si, fi);
-            if (!(CacheTraceNodes && traceCache.Contains(t))) {
+            var t = Tuple.Create(parent0, i, n, si, fi);
+            if (CacheTraceNodes) {
+              if (traceCache.Add(t))
+                TraceRecursive(parent0, i, n, si, fi);
+              else
+                TraceCacheHits++;
+            } else {
               TraceRecursive(parent0, i, n, si, fi);
-              traceCache.Add(t);
             }
             break;
@@ -198,4 +203,5 @@
             continue;
           }
+
         }
         #endregion
