Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13479


Ignore:
Timestamp:
12/17/15 20:09:28 (8 years ago)
Author:
bburlacu
Message:

#1772: Improve caching in TraceCalculator

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs

    r13424 r13479  
    3535  public class TraceCalculator : Item {
    3636    private Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>> nodeListCache;
    37     private HashSet<Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, IGenealogyGraphNode<ISymbolicExpressionTree>, int>> traceCache;
     37    private HashSet<Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, int, IGenealogyGraphNode<ISymbolicExpressionTree>, int, int>> traceCache;
    3838    public IGenealogyGraph<ISymbolicExpressionTree> TraceGraph { get; private set; }
    3939
     
    4242    public bool CacheTraceNodes { get; set; }
    4343
     44    public int TraceCacheHits { get; set; }
     45
    4446    public TraceCalculator() {
    4547      ResetState();
     
    6062      TraceGraph = new GenealogyGraph<ISymbolicExpressionTree>();
    6163      nodeListCache = new Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>>();
    62       traceCache = new HashSet<Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, IGenealogyGraphNode<ISymbolicExpressionTree>, int>>();
     64      traceCache = new HashSet<Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, int, IGenealogyGraphNode<ISymbolicExpressionTree>, int, int>>();
    6365    }
    6466
     
    145147              // subtree contains fragment => branching point in the fragment graph
    146148              var n = AddTraceNode(g); // current node becomes "last" as we restart tracing from the parent
    147               var t0 = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, IGenealogyGraphNode<ISymbolicExpressionTree>, int>(parent0, n, si);
    148               if (!(CacheTraceNodes && traceCache.Contains(t0))) {
     149              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);
     154                  TraceRecursive(parent0, si, n, si, fi);
     155                } else {
     156                  TraceCacheHits++;
     157                }
     158                if (!traceCache.Contains(t1)) {
     159                  traceCache.Add(t1);
     160                  TraceRecursive(parent1, fragment.Index2, n, si, fi);
     161                } else {
     162                  TraceCacheHits++;
     163                }
     164              } else {
    149165                TraceRecursive(parent0, si, n, si, fi);
    150                 traceCache.Add(t0);
    151               }
    152               var t1 = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, IGenealogyGraphNode<ISymbolicExpressionTree>, int>(parent1, n, fragment.Index2);
    153               if (!(CacheTraceNodes && traceCache.Contains(t1))) {
    154166                TraceRecursive(parent1, fragment.Index2, n, si, fi);
    155                 traceCache.Add(t1);
    156167              }
    157168              break;
     
    174185            var n = AddTraceNode(g); // current node becomes "last" as we restart tracing from the parent
    175186            int i = si < fi ? si : fi;
    176             var t = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, IGenealogyGraphNode<ISymbolicExpressionTree>, int>(parent0, n, i);
     187            var t = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, int, IGenealogyGraphNode<ISymbolicExpressionTree>, int, int>(parent0, i, n, si, fi);
    177188            if (!(CacheTraceNodes && traceCache.Contains(t))) {
    178189              TraceRecursive(parent0, i, n, si, fi);
Note: See TracChangeset for help on using the changeset viewer.