Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/02/15 23:09:49 (10 years ago)
Author:
bburlacu
Message:

#1772: Introduced TraceData class in order to make the semantics clear from the code. Changed arcs orientation in the trace graphs to match the orientation in the genealogy graph.

File:
1 edited

Legend:

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

    r11858 r11866  
    3535  public class TraceCalculator : Item {
    3636    private IGenealogyGraph<ISymbolicExpressionTree> traceGraph;
    37     private Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>> traceMap;
     37    private Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData> traceMap;
    3838    private Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>> nodeListCache;
    3939
     
    4242    public TraceCalculator() {
    4343      traceGraph = new GenealogyGraph<ISymbolicExpressionTree>();
    44       traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>>();
     44      traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData>();
    4545      nodeListCache = new Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>>();
    4646    }
     
    6363      int subtreeIndex, ISymbolicExpressionTreeNode subtree) {
    6464      traceGraph = new GenealogyGraph<ISymbolicExpressionTree>();
    65       traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>>();
     65      traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData>();
    6666      return null;
    6767    }
     
    6969    public IGenealogyGraph<ISymbolicExpressionTree> Trace(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex) {
    7070      traceGraph = new GenealogyGraph<ISymbolicExpressionTree>();
    71       traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>>();
     71      traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData>();
    7272      nodeListCache = new Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>>();
    7373      TraceRecursive(node, subtreeIndex);
     
    137137            if (fi < si + sl) {
    138138              // 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
    140140              TraceRecursive(parent0, si, n);
    141141              TraceRecursive(parent1, fragment.Index2, n);
     
    157157          // check if the subtree and the fragment overlap => branch out
    158158          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
    160160            int i = si < fi ? si : fi;
    161161            TraceRecursive(parent0, i, n);
     
    190190        traceGraph.AddVertex(n);
    191191        Debug.Assert(!traceMap.ContainsKey(n));
    192         traceMap[n] = new Tuple<int, int>(si, fi);
     192        traceMap[n] = new TraceData(si, fi, -1, -1); // only the first two fields are needed
    193193      }
    194194      return n;
     
    222222        return;
    223223      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 Tuple<int, int, int, int>(si, fi, lastSi, lastFi); // trace data
    227       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));
    228228      if (arc == null) {
    229         arc = new GenealogyGraphArc(last, n) { Data = td };
     229        arc = new GenealogyGraphArc(n, last) { Data = td };
    230230        traceGraph.AddArc(arc);
    231231      }
    232232    }
     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; } }
    233244  }
    234245
Note: See TracChangeset for help on using the changeset viewer.