Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/04/15 00:43:44 (10 years ago)
Author:
bburlacu
Message:

#1772:

  • TraceGraph: Improved saving of trace data, changed GetTraceNode method to AddTraceNode and made the code more clear.
  • SymbolicDataAnalysisGenealogyGraphView: added highlighting of trace information (when visualizing trace graphs)
  • GenealogyGraphChart: removed useless code
File:
1 edited

Legend:

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

    r11866 r11881  
    5858      tc.Trace(node, subtreeIndex);
    5959      return tc.TraceGraph;
    60     }
    61 
    62     public IGenealogyGraph<ISymbolicExpressionTree> PartialTrace(IGenealogyGraphNode<ISymbolicExpressionTree> node,
    63       int subtreeIndex, ISymbolicExpressionTreeNode subtree) {
    64       traceGraph = new GenealogyGraph<ISymbolicExpressionTree>();
    65       traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData>();
    66       return null;
    6760    }
    6861
     
    9790    private void TraceRecursive(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex, IGenealogyGraphNode<ISymbolicExpressionTree> last = null) {
    9891      var g = node;
    99       int si = subtreeIndex;
     92      int si = subtreeIndex; // subtree index
     93      int fi = 0; // fragment index
    10094      while (g.Parents.Any()) {
    10195        Debug.Assert(si < g.Data.Length);
     
    109103        }
    110104
    111         int fi = fragment.Index1;               // fragment index
     105        fi = fragment.Index1;               // fragment index
    112106        int fl = fragment.Root.GetLength();     // fragment length
    113107        int sl = NodeAt(g.Data, si).GetLength(); // subtree length
     
    137131            if (fi < si + sl) {
    138132              // subtree contains fragment => branching point in the fragment graph
    139               var n = GetTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent
     133              var n = AddTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent
    140134              TraceRecursive(parent0, si, n);
    141135              TraceRecursive(parent1, fragment.Index2, n);
     
    157151          // check if the subtree and the fragment overlap => branch out
    158152          if ((si == fi) || (si < fi && fi < si + sl) || (fi < si && si < fi + fl)) {
    159             var n = GetTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent
     153            var n = AddTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent
    160154            int i = si < fi ? si : fi;
    161155            TraceRecursive(parent0, i, n);
     
    173167      }
    174168      // when we are out of the while the last vertex must be connected with the current one
    175       ConnectLast(g, si, last);
     169      // if there is no last vertex, it means the tracing reached the top of the genealogy graph
     170      var current = AddTraceNode(g, si, fi);
     171      if (last != null)
     172        ConnectLast(current, last, si, fi);
    176173    }
    177174
     
    184181    /// <param name="fi">The fragment index</param>
    185182    /// <returns></returns>
    186     private IGenealogyGraphNode<ISymbolicExpressionTree> GetTraceNode(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, int fi) {
     183    private IGenealogyGraphNode<ISymbolicExpressionTree> AddTraceNode(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, int fi) {
    187184      var n = traceGraph.GetByContent(g.Data);
    188185      if (n == null) {
     
    211208    /// of the genealogy graph node @g. 
    212209    /// </summary>
    213     /// <param name="g">The current node in the genealogy graph</param>
     210    /// <param name="current">The current node in the genealogy graph</param>
     211    /// <param name="last">The last added node in the trace graph</param>   
    214212    /// <param name="si">The index of the traced subtree</param>
    215     /// <param name="last">The last added node in the trace graph</param>
    216     private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, IGenealogyGraphNode<ISymbolicExpressionTree> last) {
    217       var inArcs = (List<IArc>)((IVertex)g).InArcs;
    218       var fragment = g.Parents.Any() ? (IFragment<ISymbolicExpressionTreeNode>)inArcs.Last().Data : null;
    219       int fi = fragment == null ? 0 : fragment.Index1; // fragment index
    220       var n = GetTraceNode(g, si, fi); // will append n to the trace graph if it does not exist
    221       if (last == null)
    222         return;
     213    /// <param name="fi">The index of the fragment</param>
     214    private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> current, IGenealogyGraphNode<ISymbolicExpressionTree> last, int si, int fi) {
    223215      var lastTraceData = traceMap[last];
    224216      int lastSi = lastTraceData.SubtreeIndex; // last subtree index (index of the traced subtree in the previous trace node)
    225217      int lastFi = lastTraceData.FragmentIndex; // last fragment index (index of the fragment in the previous trace node)
    226218      var td = new TraceData(si, fi, lastSi, lastFi); // trace data
    227       var arc = n.OutArcs.SingleOrDefault(a => a.Target == last && a.Data.Equals(td));
     219      var arc = current.OutArcs.SingleOrDefault(a => a.Target == last && a.Data.Equals(td));
    228220      if (arc == null) {
    229         arc = new GenealogyGraphArc(n, last) { Data = td };
     221        arc = new GenealogyGraphArc(current, last) { Data = td };
    230222        traceGraph.AddArc(arc);
    231223      }
     
    233225  }
    234226  // this class is here to help clarify the semantics
    235   internal class TraceData : Tuple<int, int, int, int> {
     227  public class TraceData : Tuple<int, int, int, int> {
    236228    public TraceData(int currentSubtreeIndex, int currentFragmentIndex, int lastSubtreeIndex, int lastFragmentIndex)
    237229      : base(currentSubtreeIndex, currentFragmentIndex, lastSubtreeIndex, lastFragmentIndex) {
Note: See TracChangeset for help on using the changeset viewer.