Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/26/14 16:28:09 (10 years ago)
Author:
bburlacu
Message:

#1772: Deleted unused VisualGenealogyGraphTextLabel.cs, fixed tracking code in BeforeManipulatorOperator.cs, re-added setters for vertex in- and outArcs.

File:
1 edited

Legend:

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

    r10888 r10890  
    2020#endregion
    2121
     22using System;
    2223using System.Linq;
    2324using HeuristicLab.Common;
     
    4950
    5051    public override IOperation Apply() {
    51       var vChild = (IGenealogyGraphNode<T>)GenealogyGraph[ChildParameter.ActualValue];
    52       if (vChild.Rank.IsAlmost(Generations.Value + 1)) {
    53         // if the graph already contains a vertex representing the child, it means that the child is a product of crossover
    54         // when mutation follows after crossover, some changes need to be made to the graph to maintain consistency
    55         var vClone = new GenealogyGraphNode<T> {
    56           Content = (T)ChildParameter.ActualValue.Clone(),
    57           Rank = vChild.Parents.Last().Rank + 0.5
    58         };
    59         GenealogyGraph.AddVertex(vClone);
     52      // since mutation always takes place after crossover, the vertex for the current child is already in the tree
     53      var v = (IGenealogyGraphNode<T>)GenealogyGraph[ChildParameter.ActualValue];
    6054
    61         foreach (var arc in vChild.InArcs) {
    62           arc.Target = vClone;
    63           vClone.AddReverseArc(arc);
    64         }
     55      if (!v.Rank.IsAlmost(Generations.Value + 1)) {
     56        throw new Exception("Child rank should be generations.value + 1");
     57      }
     58      var clone = (T)ChildParameter.ActualValue.Clone();
    6559
    66         vClone.InArcs.Last().Data = vChild.InArcs.Last().Data; // fragment of child becomes fragment of clone
    67         GenealogyGraph.AddArc(vClone, vChild);
     60      var c = new GenealogyGraphNode<T> {
     61        Rank = v.Rank - 0.5,
     62        Content = clone
     63      };
    6864
    69         // the following step in necessary because some mutation operators change values while the reference stays the same
    70         // so we clone in order to prevent mutations to be "shadowed" in the parent
    71         var parent = vClone.Parents.First();
    72         parent.Content = (T)parent.Content.Clone();
    73         GenealogyGraph[parent.Content] = parent;
     65      foreach (var a in v.InArcs) {
     66        a.Target = c;
     67        c.AddReverseArc(a);
     68      }
    7469
    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);
    81       }
     70      v.InArcs = Enumerable.Empty<IGenealogyGraphArc>();
     71
     72      GenealogyGraph.AddVertex(c);
     73      GenealogyGraph.AddArc(c, v);
     74
    8275      return base.Apply();
    8376    }
Note: See TracChangeset for help on using the changeset viewer.