Changeset 11866
- Timestamp:
- 02/02/15 23:09:49 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
r11858 r11866 35 35 public class TraceCalculator : Item { 36 36 private IGenealogyGraph<ISymbolicExpressionTree> traceGraph; 37 private Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, T uple<int, int>> traceMap;37 private Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData> traceMap; 38 38 private Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>> nodeListCache; 39 39 … … 42 42 public TraceCalculator() { 43 43 traceGraph = new GenealogyGraph<ISymbolicExpressionTree>(); 44 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, T uple<int, int>>();44 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData>(); 45 45 nodeListCache = new Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>>(); 46 46 } … … 63 63 int subtreeIndex, ISymbolicExpressionTreeNode subtree) { 64 64 traceGraph = new GenealogyGraph<ISymbolicExpressionTree>(); 65 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, T uple<int, int>>();65 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData>(); 66 66 return null; 67 67 } … … 69 69 public IGenealogyGraph<ISymbolicExpressionTree> Trace(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex) { 70 70 traceGraph = new GenealogyGraph<ISymbolicExpressionTree>(); 71 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, T uple<int, int>>();71 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData>(); 72 72 nodeListCache = new Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>>(); 73 73 TraceRecursive(node, subtreeIndex); … … 137 137 if (fi < si + sl) { 138 138 // subtree contains fragment => branching point in the fragment graph 139 var n = GetTraceNode(g, si, fi); 139 var n = GetTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent 140 140 TraceRecursive(parent0, si, n); 141 141 TraceRecursive(parent1, fragment.Index2, n); … … 157 157 // check if the subtree and the fragment overlap => branch out 158 158 if ((si == fi) || (si < fi && fi < si + sl) || (fi < si && si < fi + fl)) { 159 var n = GetTraceNode(g, si, fi); 159 var n = GetTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent 160 160 int i = si < fi ? si : fi; 161 161 TraceRecursive(parent0, i, n); … … 190 190 traceGraph.AddVertex(n); 191 191 Debug.Assert(!traceMap.ContainsKey(n)); 192 traceMap[n] = new T uple<int, int>(si, fi);192 traceMap[n] = new TraceData(si, fi, -1, -1); // only the first two fields are needed 193 193 } 194 194 return n; … … 222 222 return; 223 223 var lastTraceData = traceMap[last]; 224 int lastSi = lastTraceData. Item1; // last subtree index (index of the traced subtree in the parent)225 int lastFi = lastTraceData. Item2; // last fragment index (index of the fragment in the parent)226 var td = new T uple<int, int, int, int>(si, fi, lastSi, lastFi); // trace data227 var arc = n. InArcs.SingleOrDefault(a => a.Source== last && a.Data.Equals(td));224 int lastSi = lastTraceData.SubtreeIndex; // last subtree index (index of the traced subtree in the previous trace node) 225 int lastFi = lastTraceData.FragmentIndex; // last fragment index (index of the fragment in the previous trace node) 226 var td = new TraceData(si, fi, lastSi, lastFi); // trace data 227 var arc = n.OutArcs.SingleOrDefault(a => a.Target == last && a.Data.Equals(td)); 228 228 if (arc == null) { 229 arc = new GenealogyGraphArc( last, n) { Data = td };229 arc = new GenealogyGraphArc(n, last) { Data = td }; 230 230 traceGraph.AddArc(arc); 231 231 } 232 232 } 233 } 234 // this class is here to help clarify the semantics 235 internal class TraceData : Tuple<int, int, int, int> { 236 public TraceData(int currentSubtreeIndex, int currentFragmentIndex, int lastSubtreeIndex, int lastFragmentIndex) 237 : base(currentSubtreeIndex, currentFragmentIndex, lastSubtreeIndex, lastFragmentIndex) { 238 } 239 240 public int SubtreeIndex { get { return Item1; } } 241 public int FragmentIndex { get { return Item2; } } 242 public int LastSubtreeIndex { get { return Item3; } } 243 public int LastFragmentIndex { get { return Item4; } } 233 244 } 234 245
Note: See TracChangeset
for help on using the changeset viewer.