Index: /branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
===================================================================
--- /branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs	(revision 11389)
+++ /branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs	(revision 11390)
@@ -20,5 +20,5 @@
 #endregion
 
-using System;
+using System.Collections.Generic;
 using System.Linq;
 using HeuristicLab.Analysis;
@@ -125,19 +125,4 @@
     public BoolValue EnableSolutionCreatorTracking {
       get { return EnableSolutionCreatorTrackingParameter.Value; }
-    }
-
-    public IGenealogyGraph<T> GenealogyGraph {
-      get {
-        IResult result;
-        var results = ResultsParameter.ActualValue;
-        if (!results.ContainsKey(PopulationGraphParameterName)) {
-          result = new Result(PopulationGraphParameterName, new GenealogyGraph<T>());
-          results.Add(result);
-        } else {
-          result = results[PopulationGraphParameterName];
-        }
-        var graph = (IGenealogyGraph<T>)result.Value;
-        return graph;
-      }
     }
     #endregion
@@ -242,4 +227,13 @@
 
     public override IOperation Apply() {
+      IGenealogyGraph<T> genealogyGraph;
+      var results = ResultsParameter.ActualValue;
+      if (!results.ContainsKey(PopulationGraphParameterName)) {
+        genealogyGraph = new GenealogyGraph<T>();
+        results.Add(new Result(PopulationGraphParameterName, genealogyGraph));
+      } else {
+        genealogyGraph = (IGenealogyGraph<T>)results[PopulationGraphParameterName].Value;
+      }
+
       var population = PopulationParameter.ActualValue;
       var qualities = QualityParameter.ActualValue.ToList();
@@ -252,5 +246,5 @@
           var individual = population[i];
           var vertex = new GenealogyGraphNode<T>(individual) { Rank = generation };
-          GenealogyGraph.AddVertex(vertex);
+          genealogyGraph.AddVertex(vertex);
           // save the vertex id in the individual scope (so that we can identify graph indices)
           ExecutionContext.Scope.SubScopes[i].Variables.Add(new Variable("Id", new StringValue(vertex.Id)));
@@ -261,5 +255,5 @@
 
         for (int i = 0; i < population.Length; ++i) {
-          if (GenealogyGraph.GetByContent(population[i]).Rank.Equals(generation - 1)) {
+          if (genealogyGraph.GetByContent(population[i]).Rank.Equals(generation - 1)) {
             elite = population[i];
             index = i;
@@ -270,14 +264,12 @@
         #region add elite in the graph and connect it with the previous elite
         if (elite != null) {
-          var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.GetByContent(elite);
+          var prevVertex = genealogyGraph.GetByContent(elite);
           prevVertex.IsElite = true; // mark elites in the graph retroactively
-          var v = new GenealogyGraphNode<T>((IDeepCloneable)prevVertex.Data.Clone()) {
-            Rank = generation,
-            Quality = prevVertex.Quality,
-            IsElite = false
-          };
-          GenealogyGraph.AddVertex(v);
-          GenealogyGraph.AddArc(prevVertex, v);
-
+          var v = (IGenealogyGraphNode<T>)prevVertex.Clone();
+          v.Rank = generation;
+          v.IsElite = false;
+          population[index] = v.Data;
+          genealogyGraph.AddVertex(v);
+          genealogyGraph.AddArc(prevVertex, v);
           // inject the graph node unique id to the scope
           ExecutionContext.Scope.SubScopes[index].Variables[BeforeManipulatorOperator.ChildParameter.ActualName].Value = v.Data;
@@ -286,36 +278,34 @@
         #endregion
 
-        ComputeSuccessRatios();
+        ComputeSuccessRatios(genealogyGraph);
       }
       // update qualities
       for (int i = 0; i < population.Length; ++i) {
-        var vertex = GenealogyGraph.GetByContent(population[i]);
+        var vertex = genealogyGraph.GetByContent(population[i]);
         vertex.Quality = qualities[i].Value;
       }
 
       // remove extra graph nodes (added by the instrumented operators in the case of offspring selection)
-      RemoveUnsuccessfulOffspring();
+      var pop = new HashSet<T>(population);
+      var discarded = genealogyGraph.Ranks[generation].Where(x => !pop.Contains(x.Data)).ToList();
+      for (int i = 0; i < discarded.Count; ++i) {
+        var v = discarded[i];
+        if (v.InDegree == 1) {
+          var p = v.Parents.First();
+          if (p.Rank.Equals(generation - 0.5))
+            // the individual was a product of mutation. since it wasn't selected, we must remove both it and it's parent 
+            // ("intermediate" vertex result of crossover)
+            discarded.Add(v.Parents.First());
+        }
+      }
+      genealogyGraph.RemoveVertices(discarded);
+      //RemoveUnsuccessfulOffspring();
 
       return base.Apply();
-    }
-
-    private void RemoveUnsuccessfulOffspring() {
-      int generation = GenerationsParameter.ActualValue.Value;
-      var population = PopulationParameter.ActualValue;
-      var discardedOffspring = GenealogyGraph.Ranks[generation].Select(x => (T)x.Data).Except(population).ToList();
-      foreach (var vertex in discardedOffspring.Select(individual => GenealogyGraph.GetByContent(individual))) {
-        if (vertex.InDegree == 1) {
-          var p = vertex.Parents.First();
-          if (!p.Rank.Equals(generation - 0.5))
-            throw new InvalidOperationException("Parent must be an intermediate vertex");
-          GenealogyGraph.RemoveVertex(p);
-        }
-        GenealogyGraph.RemoveVertex(vertex);
-      }
     }
 
     // this method works when called before the unsuccesful offspring are removed from the genealogy graph
     // so it must always be called before RemoveUnsuccessfulOffspring()
-    private void ComputeSuccessRatios() {
+    private void ComputeSuccessRatios(IGenealogyGraph<T> genealogyGraph) {
       const string successfulOffspringRatioTableHistoryName = "Successful offspring ratios history";
       const string successfulOffspringAbsoluteValuesTableHistoryName = "Successful offspring values history";
@@ -327,5 +317,5 @@
       // compute the weight of each genealogy graph node as the ratio (produced offspring) / (surviving offspring)
       foreach (var ind in population) {
-        var v = GenealogyGraph.GetByContent(ind);
+        var v = genealogyGraph.GetByContent(ind);
         if (v.Parents.Count() == 1) {
           var p = v.Parents.First();
@@ -356,5 +346,5 @@
         VisualProperties = { ChartType = DataRowVisualProperties.DataRowChartType.Columns, StartIndexZero = true }
       };
-      successfulOffspringRatioRow.Values.Replace(GenealogyGraph.Ranks[generation - 1].OrderByDescending(x => x.Quality).Select(x => x.OutDegree > 0 ? x.Weight / x.OutDegree : 0));
+      successfulOffspringRatioRow.Values.Replace(genealogyGraph.Ranks[generation - 1].OrderByDescending(x => x.Quality).Select(x => x.OutDegree > 0 ? x.Weight / x.OutDegree : 0));
       successfulOffspringRatioTable.Rows.Add(successfulOffspringRatioRow);
       successfulOffspringRatioHistory.Add(successfulOffspringRatioTable);
@@ -379,5 +369,5 @@
         VisualProperties = { ChartType = DataRowVisualProperties.DataRowChartType.Columns, StartIndexZero = true }
       };
-      successfulOffspringValuesRow.Values.Replace(GenealogyGraph.Ranks[generation - 1].OrderByDescending(x => x.Quality).Select(x => x.Weight));
+      successfulOffspringValuesRow.Values.Replace(genealogyGraph.Ranks[generation - 1].OrderByDescending(x => x.Quality).Select(x => x.Weight));
       successfulOffspringValuesTable.Rows.Add(successfulOffspringValuesRow);
       successfulOffspringAbsoluteHistory.Add(successfulOffspringValuesTable);
Index: /branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs
===================================================================
--- /branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs	(revision 11389)
+++ /branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs	(revision 11390)
@@ -38,5 +38,5 @@
 
     [Storable]
-    private Dictionary<double, List<IGenealogyGraphNode>> ranks;
+    protected Dictionary<double, List<IGenealogyGraphNode>> ranks;
 
     public Dictionary<double, List<IGenealogyGraphNode>> Ranks {
@@ -67,6 +67,6 @@
     }
 
-    public new IEnumerable<IGenealogyGraphNode> Vertices {
-      get { return from n in base.Vertices select (IGenealogyGraphNode)n; }
+    new public IEnumerable<IGenealogyGraphNode> Vertices {
+      get { return base.Vertices.Select(x => (IGenealogyGraphNode)x); }
     }
 
@@ -79,16 +79,14 @@
     public override void AddVertex(IVertex vertex) {
       base.AddVertex(vertex);
-      var node = (IGenealogyGraphNode)vertex;
-      if (!Ranks.ContainsKey(node.Rank))
-        Ranks[node.Rank] = new List<IGenealogyGraphNode>();
-      Ranks[node.Rank].Add(node);
-
-      if (contentMap.ContainsKey(node.Data))
+      var genealogyGraphNode = (IGenealogyGraphNode)vertex;
+      if (contentMap.ContainsKey(genealogyGraphNode.Data))
         throw new InvalidOperationException("Duplicate content is not allowed in the genealogy graph.");
-      contentMap[node.Data] = node;
-
-      if (idMap.ContainsKey(node.Id))
+      contentMap[genealogyGraphNode.Data] = genealogyGraphNode;
+      if (idMap.ContainsKey(genealogyGraphNode.Id))
         throw new InvalidOperationException("Duplicate ids are not allowed in the genealogy graph.");
-      idMap[node.Id] = node;
+      idMap[genealogyGraphNode.Id] = genealogyGraphNode;
+      if (!Ranks.ContainsKey(genealogyGraphNode.Rank))
+        Ranks[genealogyGraphNode.Rank] = new List<IGenealogyGraphNode>();
+      Ranks[genealogyGraphNode.Rank].Add(genealogyGraphNode);
     }
 
@@ -137,13 +135,11 @@
   [StorableClass]
   public class GenealogyGraph<T> : GenealogyGraph, IGenealogyGraph<T> where T : class, IItem {
-    public new IEnumerable<IGenealogyGraphNode<T>> Vertices {
-      get { return base.Vertices.Cast<IGenealogyGraphNode<T>>(); }
+    new public IEnumerable<IGenealogyGraphNode<T>> Vertices {
+      get { return base.Vertices.Select(x => (IGenealogyGraphNode<T>)x); }
     }
-
-    public new IGenealogyGraphNode<T> GetByContent(object content) {
+    new public IGenealogyGraphNode<T> GetByContent(object content) {
       return (IGenealogyGraphNode<T>)base.GetByContent(content);
     }
-
-    public new IGenealogyGraphNode<T> GetById(string id) {
+    new public IGenealogyGraphNode<T> GetById(string id) {
       return (IGenealogyGraphNode<T>)base.GetById(id);
     }
Index: /branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraph.cs
===================================================================
--- /branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraph.cs	(revision 11389)
+++ /branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraph.cs	(revision 11390)
@@ -26,8 +26,8 @@
   public interface IGenealogyGraph : IDirectedGraph {
     Dictionary<double, List<IGenealogyGraphNode>> Ranks { get; }
-    new IEnumerable<IGenealogyGraphNode> Vertices { get; }
     IGenealogyGraphNode GetByContent(object content);
     IGenealogyGraphNode GetById(string id);
     bool Contains(object content);
+    new IEnumerable<IGenealogyGraphNode> Vertices { get; }
   }
 
Index: /branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeCrossoverOperator.cs
===================================================================
--- /branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeCrossoverOperator.cs	(revision 11389)
+++ /branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeCrossoverOperator.cs	(revision 11390)
@@ -21,5 +21,4 @@
 
 using System;
-using System.Collections.Generic;
 using System.Linq;
 using HeuristicLab.Common;
@@ -50,4 +49,5 @@
       : base(original, cloner) {
     }
+
     public override IDeepCloneable Clone(Cloner cloner) {
       return new BeforeCrossoverOperator<T>(this, cloner);
@@ -61,12 +61,4 @@
       Parameters.Add(new LookupParameter<T>(ChildParameterName));
       Parameters.Add(new ValueParameter<IntValue>("ExecutionCount", new IntValue(0)));
-    }
-
-    protected List<IGenealogyGraphNode<T>> CurrentGeneration {
-      get {
-        if (GenealogyGraph.Ranks.ContainsKey(Generations.Value))
-          return GenealogyGraph.Ranks[Generations.Value].Cast<IGenealogyGraphNode<T>>().ToList();
-        return null;
-      }
     }
 
