Changeset 11751 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 01/13/15 17:14:45 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
r11638 r11751 34 34 [StorableClass] 35 35 public class TraceCalculator : Item { 36 private readonlyIGenealogyGraph<ISymbolicExpressionTree> traceGraph;37 private readonlyDictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>> traceMap;36 private IGenealogyGraph<ISymbolicExpressionTree> traceGraph; 37 private Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>> traceMap; 38 38 39 39 public IGenealogyGraph<ISymbolicExpressionTree> TraceGraph { get { return traceGraph; } } … … 58 58 } 59 59 60 public IGenealogyGraph<ISymbolicExpressionTree> PartialTrace(IGenealogyGraphNode<ISymbolicExpressionTree> node, 61 int subtreeIndex, ISymbolicExpressionTreeNode subtree) { 62 traceGraph = new GenealogyGraph<ISymbolicExpressionTree>(); 63 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>>(); 64 return null; 65 } 66 60 67 public IGenealogyGraph<ISymbolicExpressionTree> Trace(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex) { 61 traceGraph .Clear();62 traceMap .Clear();63 Trace (node, subtreeIndex, null);68 traceGraph = new GenealogyGraph<ISymbolicExpressionTree>(); 69 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>>(); 70 TraceRecursive(node, subtreeIndex); 64 71 return traceGraph; 65 72 } … … 82 89 /// - lastFi is the subtree index in the previous trace node 83 90 /// </summary> 84 /// <param name=" g">The current node in the genealogy graph</param>85 /// <param name="s i">The index of the traced subtree</param>91 /// <param name="node">The current node in the genealogy graph</param> 92 /// <param name="subtreeIndex">The index of the traced subtree</param> 86 93 /// <param name="last">The last added node in the trace graph</param> 87 private void Trace(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, IGenealogyGraphNode<ISymbolicExpressionTree> last = null) { 94 private void TraceRecursive(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex, IGenealogyGraphNode<ISymbolicExpressionTree> last = null) { 95 var g = node; 96 int si = subtreeIndex; 88 97 while (g.Parents.Any()) { 98 Debug.Assert(si < g.Data.Length); 89 99 var parents = g.Parents.ToList(); 90 100 var fragment = (IFragment<ISymbolicExpressionTreeNode>)g.InArcs.Last().Data; … … 124 134 // subtree contains fragment => branching point in the fragment graph 125 135 var n = GetTraceNode(g, si, fi); 126 Trace (parents[0], si, n);127 Trace (parents[1], fragment.Index2, n);136 TraceRecursive(parents[0], si, n); 137 TraceRecursive(parents[1], fragment.Index2, n); 128 138 break; 129 139 } else { … … 144 154 var n = GetTraceNode(g, si, fi); 145 155 int i = si < fi ? si : fi; 146 Trace (parents[0], i, n);156 TraceRecursive(parents[0], i, n); 147 157 break; 148 158 } else { … … 207 217 internal static class Util { 208 218 // shallow node copy (does not clone the data or the arcs) 219 #region some helper methods for shortening the tracing code 209 220 public static IGenealogyGraphNode<ISymbolicExpressionTree> Copy(this IGenealogyGraphNode<ISymbolicExpressionTree> node) { 210 221 return new GenealogyGraphNode<ISymbolicExpressionTree>(node.Data) { Rank = node.Rank, Quality = node.Quality }; 211 222 } 212 #region some helper methods for shortening the tracing code213 223 public static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTree tree, int index) { 214 224 return NodeAt(tree.Root, index);
Note: See TracChangeset
for help on using the changeset viewer.