Index: branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
===================================================================
--- branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs	(revision 12263)
+++ branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs	(revision 12265)
@@ -1,5 +1,5 @@
 ﻿#region License Information
 /* HeuristicLab
- * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
  *
  * This file is part of HeuristicLab.
Index: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicDataAnalysisGenealogyGraphView.cs
===================================================================
--- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicDataAnalysisGenealogyGraphView.cs	(revision 12263)
+++ branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicDataAnalysisGenealogyGraphView.cs	(revision 12265)
@@ -1,5 +1,5 @@
 ﻿#region License Information
 /* HeuristicLab
- * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
  *
  * This file is part of HeuristicLab.
@@ -84,4 +84,6 @@
       nodeWeightLabel.Text = String.Format("{0:0.00}", graphNode.Weight);
 
+      if (!graphNode.InArcs.Any()) return;
+
       if (openNew_CheckBox.Checked) {
         // get the ancestors into a new view
@@ -96,39 +98,98 @@
       }
 
-      if (graphNode.InArcs.Any()) {
-        var data = graphNode.InArcs.Last().Data;
-        var fragment = data as IFragment<ISymbolicExpressionTreeNode>;
-        var td = data as TraceData;
-        //        double max = Content.Vertices.Max(x => x.Data.IterateNodesPrefix().Max(y => y.NodeWeight));
-
-        // calculate max only in the current generation
-        double max = Content.GetByRank(graphNode.Rank).Max(x => ((IGenealogyGraphNode<ISymbolicExpressionTree>)x).Data.IterateNodesPrefix().Max(y => y.NodeWeight));
-        if (max.IsAlmost(0)) max = 1;
-        int c = ColorGradient.Colors.Count - 1;
-        const int alpha = 100;
-        if (fragment != null) {
-          // highlight the fragment with a blue line color
-          foreach (var n in graphNode.Data.NodeAt(fragment.Index1).IterateNodesPrefix()) {
-            treeChart_HighlightSubtree(n, Color.CornflowerBlue);
-          }
-          // highlight all the nodes according to their sample count
-          var nodes = graphNode.Data.IterateNodesPrefix().ToList();
-          foreach (var n in nodes.Skip(1)) {
-            var i = (int)Math.Round(n.NodeWeight / max * c);
-            var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]);
-            treeChart_HighlightSubtree(n, null, fillColor);
-          }
-        } else if (td != null) {
-          var nodes = graphNode.Data.IterateNodesPrefix().ToList();
-          foreach (var n in nodes.Skip(1)) { // skip program root symbol 
-            var i = (int)Math.Round(n.NodeWeight / max * c);
-            var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]);
-            treeChart_HighlightSubtree(n, null, fillColor);
-          }
-          treeChart_HighlightSubtree(nodes[td.LastSubtreeIndex], Color.Orange);
-          treeChart_HighlightSubtree(nodes[td.LastFragmentIndex], Color.CornflowerBlue);
-        }
-      }
-    }
+      var data = graphNode.InArcs.Last().Data;
+      var fragment = data as IFragment<ISymbolicExpressionTreeNode>;
+      var td = data as TraceData;
+      // calculate max only in the current generation
+      var max = Content.GetByRank(graphNode.Rank).Max(x => ((IGenealogyGraphNode<ISymbolicExpressionTree>)x).Data.IterateNodesPrefix().Max(y => y.NodeWeight));
+      //      var max = Content.GetByRank(graphNode.Rank).Max(x => x.Weight);
+
+      if (max.IsAlmost(0))
+        max = 1;
+
+      int colorCount = ColorGradient.Colors.Count - 1;
+      const int alpha = 100;
+      if (fragment != null) {
+        // highlight the fragment with a blue line color
+        foreach (var n in graphNode.Data.NodeAt(fragment.Index1).IterateNodesPrefix()) {
+          treeChart_HighlightSubtree(n, Color.CornflowerBlue);
+        }
+        // highlight all the nodes according to their sample count
+        var nodes = graphNode.Data.IterateNodesPrefix().ToList();
+        foreach (var n in nodes.Skip(1)) {
+          var i = (int)Math.Round(n.NodeWeight / max * colorCount);
+          var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]);
+          treeChart_HighlightSubtree(n, null, fillColor);
+        }
+      } else if (td != null) {
+        var nodes = graphNode.Data.IterateNodesPrefix().ToList();
+        foreach (var n in nodes.Skip(1)) { // skip program root symbol 
+          var i = (int)Math.Round(n.NodeWeight / max * colorCount);
+          var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]);
+          treeChart_HighlightSubtree(n, null, fillColor);
+        }
+        treeChart_HighlightSubtree(nodes[td.LastSubtreeIndex], Color.Orange);
+        treeChart_HighlightSubtree(nodes[td.LastFragmentIndex], Color.CornflowerBlue);
+      }
+    }
+
+    #region specific symbolic expression tree node click actions
+    private void OnTreeNodeLeftClicked(ISymbolicExpressionTreeNode node) {
+      SelectedSubtree = node;
+      bool trace = genealogyGraphChart.TraceFragments;
+
+      // check whether we are in 'trace' or 'match' mode
+      if (trace) {
+        // TODO: maybe highlight based on per generation maximum
+        //        double max = Content.Vertices.Max(x => x.Data.IterateNodesPrefix().Average(y => y.NodeWeight));
+        // perform fragment tracing
+        var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode;
+        var max = Content.GetByRank(graphNode.Rank).Max(x => x.Weight);
+        var subtreeIndex = graphNode.Data.IterateNodesPrefix().ToList().IndexOf(node);
+        var traceGraph = TraceCalculator.TraceSubtree(graphNode, subtreeIndex, updateVertexWeights: false, updateSubtreeWeights: false, cacheTraceNodes: true);
+        if (traceGraph.Vertices.Any()) {
+          var vertices = traceGraph.Vertices.Select(x => Content.GetByContent(x.Data));
+          genealogyGraphChart.UpdateEnabled = false;
+          genealogyGraphChart.ClearPrimitives();
+          foreach (var v in vertices) {
+            var vNode = genealogyGraphChart.GetMappedNode(v);
+            var wSum = v.Data.IterateNodesPrefix().Average(x => x.NodeWeight);
+            // use a grayscale gradient
+            var color = ColorGradient.GrayscaledColors[(int)Math.Round(wSum / max * (ColorGradient.GrayscaledColors.Count - 1))];
+            vNode.Brush = new SolidBrush(color);
+          }
+          genealogyGraphChart.UpdateEnabled = true;
+          genealogyGraphChart.EnforceUpdate();
+
+          if (openNew_CheckBox.Checked) {
+            MainFormManager.MainForm.ShowContent(traceGraph); // display the fragment graph on the screen
+          }
+        }
+      } else {
+        // perform matching like it was done before
+        // currently there is no possibility to specify the subtree matching criteria
+        var trees = Content.Vertices.Select(x => x.Data);
+        var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(node, comparer));
+
+        var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x));
+        graphChart_HighlightMatchingVertices(matchingVertices);
+      }
+    }
+
+    private void OnTreeNodeMiddleClicked(ISymbolicExpressionTreeNode node) {
+      var index = SelectedSubtree.IterateNodesPrefix().ToList().IndexOf(node);
+      if (index > 0) {
+        var s = ClonedSubtree.NodeAt(index);
+        s.Parent.RemoveSubtree(s.Parent.IndexOfSubtree(s));
+
+        var trees = Content.Vertices.Select(x => x.Data);
+        var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(ClonedSubtree, comparer));
+
+        var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x));
+        treeChart_HighlightSubtree(node, Color.Black, Color.White);
+        graphChart_HighlightMatchingVertices(matchingVertices);
+      }
+    }
+    #endregion
 
     public void treeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs args) {
@@ -139,58 +200,11 @@
       treeChart_HighlightSubtree(subtree, Color.Black, Color.RoyalBlue);
 
-      bool trace = genealogyGraphChart.TraceFragments; // check whether we are in 'trace' or 'match' mode
-
       switch (args.Button) {
         case MouseButtons.Left: {
-            SelectedSubtree = subtree;
-            if (trace) {
-              // TODO: maybe highlight based on per generation maximum
-              double max = Content.Vertices.Max(x => x.Data.IterateNodesPrefix().Average(y => y.NodeWeight));
-              // perform fragment tracing
-              var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode;
-              var subtreeIndex = graphNode.Data.IterateNodesPrefix().ToList().IndexOf(subtree);
-              var traceGraph = TraceCalculator.TraceSubtree(graphNode, subtreeIndex, updateVertexWeights: false, updateSubtreeWeights: false, cacheTraceNodes: true);
-              if (traceGraph.Vertices.Any()) {
-                var vertices = traceGraph.Vertices.Select(x => Content.GetByContent(x.Data));
-                genealogyGraphChart.UpdateEnabled = false;
-                genealogyGraphChart.ClearPrimitives();
-                foreach (var v in vertices) {
-                  var vNode = genealogyGraphChart.GetMappedNode(v);
-                  var wSum = v.Data.IterateNodesPrefix().Average(x => x.NodeWeight);
-                  // use a grayscal gradient
-                  var color = ColorGradient.GrayscaledColors[(int)Math.Round(wSum / max * (ColorGradient.GrayscaledColors.Count - 1))];
-                  vNode.Brush = new SolidBrush(color);
-                }
-                genealogyGraphChart.UpdateEnabled = true;
-                genealogyGraphChart.EnforceUpdate();
-
-                if (openNew_CheckBox.Checked) {
-                  MainFormManager.MainForm.ShowContent(traceGraph); // display the fragment graph on the screen
-                }
-              }
-            } else {
-              // perform matching like it was done before
-              // currently there is no possibility to specify the subtree matching criteria
-              var trees = Content.Vertices.Select(x => x.Data);
-              var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer));
-
-              var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x));
-              graphChart_HighlightMatchingVertices(matchingVertices);
-            }
+            OnTreeNodeLeftClicked(subtree);
             break;
           }
         case MouseButtons.Middle: {
-            var index = SelectedSubtree.IterateNodesPrefix().ToList().IndexOf(subtree);
-            if (index > 0) {
-              var s = ClonedSubtree.NodeAt(index);
-              s.Parent.RemoveSubtree(s.Parent.IndexOfSubtree(s));
-
-              var trees = Content.Vertices.Select(x => x.Data);
-              var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(ClonedSubtree, comparer));
-
-              var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x));
-              treeChart_HighlightSubtree(subtree, Color.Black, Color.White);
-              graphChart_HighlightMatchingVertices(matchingVertices);
-            }
+            OnTreeNodeMiddleClicked(subtree);
             break;
           }
@@ -260,34 +274,27 @@
     private void navigateRightButton_Click(object sender, EventArgs e) {
       var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode;
-      var inArcs = graphNode.InArcs.ToList();
+      var inArcs = (List<IArc>)((IVertex)graphNode).InArcs;
       if (inArcs.Count > 0) {
-        var data = inArcs.Last().Data;
-        var fragment = (data as IFragment<ISymbolicExpressionTreeNode>);
-        var td = data as TraceData;
+        if (inArcs.Count == 1) {
+          genealogyGraphChart.SelectedGraphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[0].Source;
+          return;
+        }
+        IGenealogyGraphNode<ISymbolicExpressionTree> source = null;
+        var fragment = ((IArc<IDeepCloneable>)inArcs.Last()).Data as IFragment<ISymbolicExpressionTreeNode>;
+        var traceData = ((IArc<IDeepCloneable>)inArcs[0]).Data as TraceData;
         if (fragment != null) {
-          genealogyGraphChart.SelectedGraphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs.Last().Source;
-        } else if (td != null) {
-          if (inArcs.Count == 1) {
-            genealogyGraphChart.SelectedGraphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[0].Source;
-            return;
-          }
-          // the first arc from inArcs will always represent the connection to the root parent
-          // (tracing the body of the traced subtree)
-          // therefore, in order to follow the correct non-root parent, we have to find the correct arc
-          // But, the FragmentIndex recorded in the TraceData of the first arc has to match the SubtreeIndex recorded in the TraceData of the searched arc
-          td = (TraceData)inArcs[0].Data;
-          var f1 = (graphNode.Data).NodeAt(td.LastFragmentIndex);
-          for (int i = 1; i < inArcs.Count; ++i) {
-            td = (TraceData)inArcs[i].Data;
-            var f2 = ((IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[i].Source).Data.NodeAt(td.SubtreeIndex);
-            // if the subtrees are the same we have found a match
-            // note: this is not necessarily 100% correct if in the trace graph we have identical fragments on different arcs
-            if (f1.Difference(f2) == null) {
-              genealogyGraphChart.SelectedGraphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[i].Source;
-              return;
-            }
-          }
-          throw new InvalidOperationException("Error calculating the next step.");
-        }
+          source = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs.Last().Source;
+        }
+        if (traceData != null) {
+          var f = graphNode.Data.NodeAt(traceData.LastFragmentIndex);
+          var selected = inArcs.Skip(1).First(x => {
+            var td = (TraceData)((IArc<IDeepCloneable>)x).Data;
+            var s = (IGenealogyGraphNode<ISymbolicExpressionTree>)x.Source;
+            return f.Difference(s.Data.NodeAt(td.SubtreeIndex)) == null;
+          });
+          source = (IGenealogyGraphNode<ISymbolicExpressionTree>)selected.Source;
+        }
+        if (source != null)
+          genealogyGraphChart.SelectedGraphNode = source;
       }
     }
Index: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicExpressionChartControl.Designer.cs
===================================================================
--- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicExpressionChartControl.Designer.cs	(revision 12263)
+++ 	(revision )
@@ -1,43 +1,0 @@
-﻿namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
-  partial class SymbolicExpressionChartControl {
-    /// <summary> 
-    /// Required designer variable.
-    /// </summary>
-    private System.ComponentModel.IContainer components = null;
-
-    /// <summary> 
-    /// Clean up any resources being used.
-    /// </summary>
-    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
-    protected override void Dispose(bool disposing) {
-      if (disposing && (components != null)) {
-        components.Dispose();
-      }
-      base.Dispose(disposing);
-    }
-
-    #region Component Designer generated code
-
-    /// <summary> 
-    /// Required method for Designer support - do not modify 
-    /// the contents of this method with the code editor.
-    /// </summary>
-    private void InitializeComponent() {
-      ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
-      this.SuspendLayout();
-      // 
-      // SymbolicExpressionChartControl
-      // 
-      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
-      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-      this.DoubleBuffered = true;
-      this.Name = "SymbolicExpressionChartControl";
-      this.Controls.SetChildIndex(this.pictureBox, 0);
-      ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
-      this.ResumeLayout(false);
-
-    }
-
-    #endregion
-  }
-}
Index: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisSubtreeSampleCountAnalyzer.cs
===================================================================
--- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisSubtreeSampleCountAnalyzer.cs	(revision 12263)
+++ branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisSubtreeSampleCountAnalyzer.cs	(revision 12265)
@@ -1,3 +1,3 @@
-﻿#region License Information
+﻿#region License information
 /* HeuristicLab
  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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 12263)
+++ branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs	(revision 12265)
@@ -155,22 +155,4 @@
                 traceCache.Add(t1);
               }
-              // gather statistics about sampled individuals and sampled subtrees
-              if (UpdateVertexWeights)
-                n.Weight++;
-              if (UpdateSubtreeWeights) {
-                var arcs = (List<IArc>)((IVertex)n).InArcs; // at this moment n will have been added as a child to the next trace node
-
-                // TODO: try to simplify the code below
-                for (int i = 0; i < arcs.Count; ++i) {
-                  var td = (TraceData)((IArc<IDeepCloneable>)arcs[i]).Data;
-                  var p = (IGenealogyGraphNode<ISymbolicExpressionTree>)arcs[i].Source;
-                  var s = NodeAt(p.Data, td.SubtreeIndex);
-                  if (td.LastFragmentIndex == td.SubtreeIndex && fragment.Root.Difference(s) == null) {
-                    foreach (var ss in s.IterateNodesPrefix()) ss.NodeWeight++; // the node weight will represent the total sample count for a given node
-                    arcs[i].Weight++; // the arc weights (since there are multiple arcs) will sum up to the same count but give more detail
-                    break;
-                  }
-                }
-              }
               break;
             } else {
@@ -197,6 +179,4 @@
               traceCache.Add(t);
             }
-            if (UpdateVertexWeights)
-              n.Weight++;
             break;
           } else {
@@ -257,17 +237,26 @@
     /// <param name="si">The index of the traced subtree</param>
     /// <param name="fi">The index of the fragment</param>
-    private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> current,
-      IGenealogyGraphNode<ISymbolicExpressionTree> last, int si, int fi) {
+    private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> current, IGenealogyGraphNode<ISymbolicExpressionTree> last, int si, int fi) {
       var lastTraceData = traceMap[last];
       int lastSi = lastTraceData.SubtreeIndex; // last subtree index (index of the traced subtree in the previous trace node)
       int lastFi = lastTraceData.FragmentIndex; // last fragment index (index of the fragment in the previous trace node)
       var td = new TraceData(si, fi, lastSi, lastFi); // trace data
-      // using the inArcs seems to be slightly more efficient than using the outArcs
+
       // TODO: more testing
-      var inArcs = (List<IArc>)((IVertex)last).InArcs;
+      var inArcs = (List<IArc>)((IVertex)last).InArcs; // using the InArcs seems to be slightly more efficient than using the OutArcs
       var arc = inArcs.FirstOrDefault(a => a.Source == current && ((IArc<IDeepCloneable>)a).Data.Equals(td));
       if (arc == null) {
         arc = new GenealogyGraphArc(current, last) { Data = td };
         TraceGraph.AddArc(arc);
+      } else {
+        if (UpdateVertexWeights) {
+          arc.Weight++;
+          current.Weight++;
+        }
+        if (UpdateSubtreeWeights) {
+          var subtree = NodeAt(current.Data, td.SubtreeIndex);
+          foreach (var s in subtree.IterateNodesPrefix())
+            s.NodeWeight++;
+        }
       }
     }
