Changeset 11458 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking
- Timestamp:
- 10/13/14 13:03:24 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Property svn:ignore
-
old new 5 5 TreeDistance 6 6 SymbolicDataAnalysisExpressionTreeMatching.cs 7 Importer
-
- Property svn:ignore
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs
r11388 r11458 48 48 var parent = parentNode; // current parent 49 49 50 IGenealogyGraphNode<ISymbolicExpressionTree> n1 = null; 51 int i1 = -1; 52 50 53 while (true) { 54 if (node == n1 && index == i1) 55 throw new InvalidOperationException("Infinite loop detected"); 56 57 n1 = node; 58 i1 = index; 59 51 60 if (!node.Parents.Any()) { 52 61 // no tracing if there are no parents, return a fragment node representing the current trace 53 var fragmentNode = new FragmentNode(node ) { SubtreeIndex = index };62 var fragmentNode = new FragmentNode(node.Data) { SubtreeIndex = index }; 54 63 if (parent != null) { 55 var arc = new Arc(parent, fragmentNode);64 var arc = new GenealogyGraphArc(parent, fragmentNode); 56 65 parent.AddArc(arc); 57 66 fragmentNode.AddArc(arc); … … 82 91 if (parents.Count == 1) { 83 92 // we are tracing a mutation operation 84 var fragmentNode = new FragmentNode(node ) {93 var fragmentNode = new FragmentNode(node.Data) { 85 94 SubtreeIndex = index, 86 95 FragmentIndex = fragment.Index1 … … 91 100 fragmentNode.AddArc(arc); 92 101 } 102 if (node == parents[0]) 103 throw new InvalidOperationException("Node == parents[0]"); 104 93 105 node = parents[0]; 94 if (subtreeIndex == fragment.Index1) { 106 107 if (index == fragment.Index1) { 95 108 // index stays the same 96 } else if (fragment.Index1 < subtreeIndex) {97 if ( subtreeIndex < fragment.Index1 + fragmentLength) {109 } else if (fragment.Index1 < index) { 110 if (index < fragment.Index1 + fragmentLength) { 98 111 // in the case of mutation, the fragment could have been introduced via a node replacement 99 112 // there is no guarantee the subtree exists above this level, therefore the index is set to the fragment index … … 103 116 index += node.Data.NodeAt(fragment.Index1).GetLength() - fragmentLength; 104 117 } 105 } else if ( subtreeIndex < fragment.Index1) {106 if (fragment.Index1 < subtreeIndex + subtreeLength) {118 } else if (index < fragment.Index1) { 119 if (fragment.Index1 < index + subtreeLength) { 107 120 // subtree contains fragment 108 121 index = fragment.Index1; … … 111 124 } 112 125 } 113 114 126 yield return fragmentNode; 115 var up = Trace(node, index, fragmentNode); // force immediate query execution 127 if (node == graphNode && index == subtreeIndex) 128 throw new ArgumentException("Infinite recursion detected"); 129 var up = Trace(node, index, fragmentNode).ToList(); // force immediate query execution 116 130 foreach (var v in up) { yield return v; } 117 131 break; … … 121 135 #region crossover tracing 122 136 if (parents.Count == 2) { 137 if (node == parents[0]) 138 throw new InvalidOperationException("Node == parents[0]"); 139 if (node == parents[1]) 140 throw new InvalidOperationException("Node == parents[1]"); 123 141 // we are tracing a crossover operation 124 142 if (fragment.Index1 == index) { … … 143 161 if (fragment.Index1 < index + subtreeLength) { 144 162 // subtree contains fragment => branching point in the fragment graph 145 var fragmentNode = new FragmentNode(node ) {163 var fragmentNode = new FragmentNode(node.Data) { 146 164 SubtreeIndex = index, 147 165 FragmentIndex = fragment.Index1 148 166 }; 149 167 if (parent != null) { 150 var arc = new Arc(parent, fragmentNode);168 var arc = new GenealogyGraphArc(parent, fragmentNode); 151 169 parent.AddArc(arc); 152 170 fragmentNode.AddArc(arc); … … 176 194 return writer.ToString(); 177 195 } 178 #region some helper methods for shortening the tracing code179 private static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTree tree, int position) {180 return NodeAt(tree.Root, position);181 }182 private static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTreeNode root, int position) {183 return root.IterateNodesPrefix().ElementAt(position);184 }185 #endregion186 196 } 187 197 }
Note: See TracChangeset
for help on using the changeset viewer.