Changeset 10888 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs
- Timestamp:
- 05/26/14 01:56:35 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs
r10886 r10888 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using System.Linq; 24 23 using HeuristicLab.Common; … … 50 49 51 50 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)) { 53 53 // if the graph already contains a vertex representing the child, it means that the child is a product of crossover 54 54 // 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 }; 59 59 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) { 63 62 arc.Target = vClone; 64 63 vClone.AddReverseArc(arc); … … 66 65 67 66 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 clone69 67 GenealogyGraph.AddArc(vClone, vChild); 70 68 … … 75 73 GenealogyGraph[parent.Content] = parent; 76 74 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); 80 81 } 81 82 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.