Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/29/15 23:40:57 (8 years ago)
Author:
bburlacu
Message:

#1772: Some more work on subtree sample counting.

File:
1 edited

Legend:

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

    r12231 r12265  
    155155                traceCache.Add(t1);
    156156              }
    157               // gather statistics about sampled individuals and sampled subtrees
    158               if (UpdateVertexWeights)
    159                 n.Weight++;
    160               if (UpdateSubtreeWeights) {
    161                 var arcs = (List<IArc>)((IVertex)n).InArcs; // at this moment n will have been added as a child to the next trace node
    162 
    163                 // TODO: try to simplify the code below
    164                 for (int i = 0; i < arcs.Count; ++i) {
    165                   var td = (TraceData)((IArc<IDeepCloneable>)arcs[i]).Data;
    166                   var p = (IGenealogyGraphNode<ISymbolicExpressionTree>)arcs[i].Source;
    167                   var s = NodeAt(p.Data, td.SubtreeIndex);
    168                   if (td.LastFragmentIndex == td.SubtreeIndex && fragment.Root.Difference(s) == null) {
    169                     foreach (var ss in s.IterateNodesPrefix()) ss.NodeWeight++; // the node weight will represent the total sample count for a given node
    170                     arcs[i].Weight++; // the arc weights (since there are multiple arcs) will sum up to the same count but give more detail
    171                     break;
    172                   }
    173                 }
    174               }
    175157              break;
    176158            } else {
     
    197179              traceCache.Add(t);
    198180            }
    199             if (UpdateVertexWeights)
    200               n.Weight++;
    201181            break;
    202182          } else {
     
    257237    /// <param name="si">The index of the traced subtree</param>
    258238    /// <param name="fi">The index of the fragment</param>
    259     private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> current,
    260       IGenealogyGraphNode<ISymbolicExpressionTree> last, int si, int fi) {
     239    private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> current, IGenealogyGraphNode<ISymbolicExpressionTree> last, int si, int fi) {
    261240      var lastTraceData = traceMap[last];
    262241      int lastSi = lastTraceData.SubtreeIndex; // last subtree index (index of the traced subtree in the previous trace node)
    263242      int lastFi = lastTraceData.FragmentIndex; // last fragment index (index of the fragment in the previous trace node)
    264243      var td = new TraceData(si, fi, lastSi, lastFi); // trace data
    265       // using the inArcs seems to be slightly more efficient than using the outArcs
     244
    266245      // TODO: more testing
    267       var inArcs = (List<IArc>)((IVertex)last).InArcs;
     246      var inArcs = (List<IArc>)((IVertex)last).InArcs; // using the InArcs seems to be slightly more efficient than using the OutArcs
    268247      var arc = inArcs.FirstOrDefault(a => a.Source == current && ((IArc<IDeepCloneable>)a).Data.Equals(td));
    269248      if (arc == null) {
    270249        arc = new GenealogyGraphArc(current, last) { Data = td };
    271250        TraceGraph.AddArc(arc);
     251      } else {
     252        if (UpdateVertexWeights) {
     253          arc.Weight++;
     254          current.Weight++;
     255        }
     256        if (UpdateSubtreeWeights) {
     257          var subtree = NodeAt(current.Data, td.SubtreeIndex);
     258          foreach (var s in subtree.IterateNodesPrefix())
     259            s.NodeWeight++;
     260        }
    272261      }
    273262    }
Note: See TracChangeset for help on using the changeset viewer.