Changeset 14575 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
- Timestamp:
- 01/15/17 14:12:11 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
r13877 r14575 35 35 public class TraceCalculator : Item { 36 36 private Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>> nodeListCache; 37 // the trace cache consits of tuples of the current and last vertices, the subtree index to be traced in the current vertex, and the last subtree and fragment indexes 37 38 private HashSet<Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, int, IGenealogyGraphNode<ISymbolicExpressionTree>, int, int>> traceCache; 38 39 public IGenealogyGraph<ISymbolicExpressionTree> TraceGraph { get; private set; } … … 105 106 private void TraceRecursive(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex, IGenealogyGraphNode<ISymbolicExpressionTree> last = null, int lastSi = -1, int lastFi = -1) { 106 107 var g = node; 107 intsi = subtreeIndex; // subtree index108 intfi = 0; // fragment index108 var si = subtreeIndex; // subtree index 109 var fi = 0; // fragment index 109 110 while (((List<IArc>)((IVertex)g).InArcs).Count > 0) { 110 111 if (!(si < g.Data.Length)) throw new ArgumentOutOfRangeException("The subtree index exceeds the size of the tree."); … … 148 149 var n = AddTraceNode(g); // current node becomes "last" as we restart tracing from the parent 149 150 if (CacheTraceNodes) { 150 var t0 = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, int, IGenealogyGraphNode<ISymbolicExpressionTree>, int, int>(parent0, si, n, si, fi);151 var t1 = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, int, IGenealogyGraphNode<ISymbolicExpressionTree>, int, int>(parent1, fragment.Index2, n, si, fi);152 if (!traceCache.Contains(t0)) {153 traceCache.Add(t0);151 var t0 = Tuple.Create(parent0, si, n, si, fi); 152 var t1 = Tuple.Create(parent1, fragment.Index2, n, si, fi); 153 // trace subtree 154 if (traceCache.Add(t0)) 154 155 TraceRecursive(parent0, si, n, si, fi); 155 } else {156 else 156 157 TraceCacheHits++; 157 } 158 if (!traceCache.Contains(t1)) { 159 traceCache.Add(t1); 158 // trace fragment 159 if (traceCache.Add(t1)) 160 160 TraceRecursive(parent1, fragment.Index2, n, si, fi); 161 } else {161 else 162 162 TraceCacheHits++; 163 }164 163 } else { 165 164 TraceRecursive(parent0, si, n, si, fi); … … 182 181 Debug.Assert(fragment.Index1 == fragment.Index2); 183 182 // check if the subtree and the fragment overlap => branch out 183 // optionally we could ignore the case when the fragment contains the subtree: 184 // ((si == fi) || fi < si && si < fi + fl) 184 185 if ((si == fi) || (si < fi && fi < si + sl) || (fi < si && si < fi + fl)) { 185 186 var n = AddTraceNode(g); // current node becomes "last" as we restart tracing from the parent 186 187 int i = si < fi ? si : fi; 187 var t = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, int, IGenealogyGraphNode<ISymbolicExpressionTree>, int, int>(parent0, i, n, si, fi); 188 if (!(CacheTraceNodes && traceCache.Contains(t))) { 188 var t = Tuple.Create(parent0, i, n, si, fi); 189 if (CacheTraceNodes) { 190 if (traceCache.Add(t)) 191 TraceRecursive(parent0, i, n, si, fi); 192 else 193 TraceCacheHits++; 194 } else { 189 195 TraceRecursive(parent0, i, n, si, fi); 190 traceCache.Add(t);191 196 } 192 197 break; … … 198 203 continue; 199 204 } 205 200 206 } 201 207 #endregion
Note: See TracChangeset
for help on using the changeset viewer.