Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/26/14 01:56:35 (10 years ago)
Author:
bburlacu
Message:

#1772: Introduced separate class for FragmentNodes and adjusted tracing code. Fixed small bug creating the genealogy graph.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs

    r10886 r10888  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using System.Linq;
    2423using HeuristicLab.Common;
     
    5049
    5150    public override IOperation Apply() {
    52       if (GenealogyGraph.Contains(ChildParameter.ActualValue)) {
     51      var vChild = (IGenealogyGraphNode<T>)GenealogyGraph[ChildParameter.ActualValue];
     52      if (vChild.Rank.IsAlmost(Generations.Value + 1)) {
    5353        // if the graph already contains a vertex representing the child, it means that the child is a product of crossover
    5454        // when mutation follows after crossover, some changes need to be made to the graph to maintain consistency
    55         var child = ChildParameter.ActualValue;
    56         var clone = (T)child.Clone();
    57         var vChild = (IGenealogyGraphNode<T>)GenealogyGraph[child];
    58         var vClone = new GenealogyGraphNode<T> { Content = clone, Rank = vChild.Rank - 0.5 };
     55        var vClone = new GenealogyGraphNode<T> {
     56          Content = (T)ChildParameter.ActualValue.Clone(),
     57          Rank = vChild.Parents.Last().Rank + 0.5
     58        };
    5959        GenealogyGraph.AddVertex(vClone);
    60         var parents = vChild.Parents; // parents of child become parents of clone
    61         foreach (var p in parents) {
    62           var arc = p.OutArcs.First(a => a.Target == vChild);
     60
     61        foreach (var arc in vChild.InArcs) {
    6362          arc.Target = vClone;
    6463          vClone.AddReverseArc(arc);
     
    6665
    6766        vClone.InArcs.Last().Data = vChild.InArcs.Last().Data; // fragment of child becomes fragment of clone
    68         vChild.InArcs = new List<IGenealogyGraphArc>(); // child will be connected to clone
    6967        GenealogyGraph.AddArc(vClone, vChild);
    7068
     
    7573        GenealogyGraph[parent.Content] = parent;
    7674
    77       } else { // this needs to be checked
    78         var vChild = new GenealogyGraphNode<T> { Content = ChildParameter.ActualValue, Rank = Generations.Value };
    79         GenealogyGraph.AddVertex(vChild);
     75      } else if (vChild.Rank.IsAlmost(Generations.Value)) {
     76        var clone = (T)ChildParameter.ActualValue.Clone();
     77        GenealogyGraph.SetContent(vChild, clone);
     78        var xx = new GenealogyGraphNode<T> { Content = ChildParameter.ActualValue, Rank = Generations.Value + 1 };
     79        GenealogyGraph.AddVertex(xx);
     80        GenealogyGraph.AddArc(vChild, xx);
    8081      }
    8182      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.