Changeset 10888 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking
- Timestamp:
- 05/26/14 01:56:35 (11 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs
r10833 r10888 37 37 } 38 38 39 // var parentVertices = childVertex.Parents.ToList();40 //41 // if (parents[0].Length != parentVertices[0].Content.Length || parents[1].Length != parentVertices[1].Content.Length) {42 // throw new Exception("Inconsistency detected in GenealogyGraph.");43 // }44 45 39 return result; 46 40 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs
r10837 r10888 31 31 32 32 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue]; 33 var vClone = (IGenealogyGraphNode<ISymbolicExpressionTree>)vChild.InArcs.Last().Source;33 var vClone = vChild.Parents.Last(); 34 34 vChild.InArcs.First().Data = vClone.Content.IterateNodesPrefix().ToList(); 35 35 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs
r10886 r10888 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 27 using HeuristicLab.EvolutionTracking; 28 using FragmentNode = HeuristicLab.EvolutionTracking.GenealogyGraphNode<HeuristicLab.EvolutionTracking.IFragment<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTreeNode>>;29 using IFragmentNode = HeuristicLab.EvolutionTracking.IGenealogyGraphNode<HeuristicLab.EvolutionTracking.IFragment<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTreeNode>>;30 using IGraphNode = HeuristicLab.EvolutionTracking.IGenealogyGraphNode<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTree>;31 28 32 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 33 30 public static class SymbolicDataAnalysisExpressionTracing { 34 public static IGenealogyGraph<IFragment<ISymbolicExpressionTreeNode>>TraceSubtree(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, int subtreeIndex) {35 var graph = new GenealogyGraph<IFragment<ISymbolicExpressionTreeNode>>();31 public static FragmentGraph TraceSubtree(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, int subtreeIndex) { 32 var graph = new FragmentGraph { AllowDuplicateContent = true }; 36 33 var nodes = Trace(graphNode, subtreeIndex); 37 34 foreach (var n in nodes) { … … 40 37 return graph; 41 38 } 42 43 private static IEnumerable<IFragmentNode> Trace(IGraphNode graphNode, int subtreeIndex, FragmentNode parentNode = null) { 39 /// <summary> 40 /// Traces a subtree in a genealogy of individuals, tracking down it's genetic components 41 /// </summary> 42 /// <param name="graphNode">The point in the genealogy where to start the tracing from</param> 43 /// <param name="subtreeIndex">The traced subtree preorder index in the current tree</param> 44 /// <param name="parentNode">The parent node in the fragment graph if there is any</param> 45 /// <returns></returns> 46 private static IEnumerable<FragmentNode> Trace(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, int subtreeIndex, FragmentNode parentNode = null) { 44 47 var node = graphNode; // current node 45 48 var index = subtreeIndex; // current index … … 49 52 if (!node.Parents.Any()) { 50 53 var fragmentNode = new FragmentNode { 51 Content = new Fragment<ISymbolicExpressionTreeNode> { 52 Root = node.Content.Root, 53 // Root = node.Content.NodeAt(index) 54 Index1 = index 55 }, 56 Rank = node.Rank, 57 Quality = node.Quality 54 Content = node, 55 SubtreeIndex = index, 58 56 }; 59 57 if (parent != null) { 60 var arc = new GenealogyGraphArc(parent, fragmentNode);58 var arc = new Arc(parent, fragmentNode); 61 59 parent.AddForwardArc(arc); 62 60 fragmentNode.AddReverseArc(arc); … … 78 76 var subtreeLength = subtree.GetLength(); 79 77 78 #region mutation tracing 80 79 if (parents.Count == 1) { 81 80 // we are tracing a mutation operation 82 81 var fragmentNode = new FragmentNode { 83 Content = new Fragment<ISymbolicExpressionTreeNode> { 84 Root = tree.Root, 85 // Root = subtree 86 Index1 = index, 87 Index2 = fragment.Index1 88 }, 89 Rank = node.Rank, 90 Quality = node.Quality 82 Content = node, 83 SubtreeIndex = index, 84 FragmentIndex = fragment.Index1 91 85 }; 92 86 if (parent != null) { 93 var arc = new GenealogyGraphArc(parent, fragmentNode);87 var arc = new Arc(parent, fragmentNode); 94 88 parent.AddForwardArc(arc); 95 89 fragmentNode.AddReverseArc(arc); 96 90 } 91 node = parents[0]; 92 if (subtreeIndex == fragment.Index1) { 93 // index stays the same 94 } else if (fragment.Index1 < subtreeIndex) { 95 if (subtreeIndex < fragment.Index1 + fragmentLength) { 96 // subtree contained in fragment, index stays the same 97 } else { 98 index += node.Content.NodeAt(fragment.Index1).GetLength() - fragmentLength; 99 } 100 } else if (subtreeIndex < fragment.Index1) { 101 if (fragment.Index1 < subtreeIndex + subtreeLength) { 102 // subtree contains fragment 103 index = fragment.Index1; 104 } else { 105 // index stays the same 106 } 107 } 108 97 109 yield return fragmentNode; 98 var up = Trace( parents[0], fragment.Index1, fragmentNode);110 var up = Trace(node, index, fragmentNode); 99 111 foreach (var v in up) { yield return v; } 100 112 break; 101 113 } 114 #endregion 102 115 116 #region crossover tracing 103 117 if (parents.Count == 2) { 104 118 // we are tracing a crossover operation … … 125 139 // subtree contains fragment => bifurcation point in the fragment graph 126 140 var fragmentNode = new FragmentNode { 127 Content = new Fragment<ISymbolicExpressionTreeNode> { 128 Root = tree.Root, 129 Index1 = index, 130 Index2 = fragment.Index1 131 }, 132 Rank = node.Rank, 133 Quality = node.Quality 141 Content = node, 142 SubtreeIndex = index, 143 FragmentIndex = fragment.Index1 134 144 }; 135 145 if (parent != null) { 136 var arc = new GenealogyGraphArc(parent, fragmentNode);146 var arc = new Arc(parent, fragmentNode); 137 147 parent.AddForwardArc(arc); 138 148 fragmentNode.AddReverseArc(arc); 139 149 } 140 // fragmentNode.Content.Index1 = fragment.Index1 - index;141 150 yield return fragmentNode; 142 151 … … 154 163 } 155 164 } 165 #endregion 156 166 } 157 167 }
Note: See TracChangeset
for help on using the changeset viewer.