Changeset 11751


Ignore:
Timestamp:
01/13/15 17:14:45 (5 years ago)
Author:
bburlacu
Message:

#1772: TraceCalculator: Added static TraceSubtree method, renamed private Trace method to TraceRecursive to avoid method name confusion.

File:
1 edited

Legend:

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

    r11638 r11751  
    3434  [StorableClass]
    3535  public class TraceCalculator : Item {
    36     private readonly IGenealogyGraph<ISymbolicExpressionTree> traceGraph;
    37     private readonly Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>> traceMap;
     36    private IGenealogyGraph<ISymbolicExpressionTree> traceGraph;
     37    private Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>> traceMap;
    3838
    3939    public IGenealogyGraph<ISymbolicExpressionTree> TraceGraph { get { return traceGraph; } }
     
    5858    }
    5959
     60    public IGenealogyGraph<ISymbolicExpressionTree> PartialTrace(IGenealogyGraphNode<ISymbolicExpressionTree> node,
     61      int subtreeIndex, ISymbolicExpressionTreeNode subtree) {
     62      traceGraph = new GenealogyGraph<ISymbolicExpressionTree>();
     63      traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>>();
     64      return null;
     65    }
     66
    6067    public IGenealogyGraph<ISymbolicExpressionTree> Trace(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex) {
    61       traceGraph.Clear();
    62       traceMap.Clear();
    63       Trace(node, subtreeIndex, null);
     68      traceGraph = new GenealogyGraph<ISymbolicExpressionTree>();
     69      traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>>();
     70      TraceRecursive(node, subtreeIndex);
    6471      return traceGraph;
    6572    }
     
    8289    /// - lastFi is the subtree index in the previous trace node
    8390    /// </summary>
    84     /// <param name="g">The current node in the genealogy graph</param>
    85     /// <param name="si">The index of the traced subtree</param>
     91    /// <param name="node">The current node in the genealogy graph</param>
     92    /// <param name="subtreeIndex">The index of the traced subtree</param>
    8693    /// <param name="last">The last added node in the trace graph</param>
    87     private void Trace(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, IGenealogyGraphNode<ISymbolicExpressionTree> last = null) {
     94    private void TraceRecursive(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex, IGenealogyGraphNode<ISymbolicExpressionTree> last = null) {
     95      var g = node;
     96      int si = subtreeIndex;
    8897      while (g.Parents.Any()) {
     98        Debug.Assert(si < g.Data.Length);
    8999        var parents = g.Parents.ToList();
    90100        var fragment = (IFragment<ISymbolicExpressionTreeNode>)g.InArcs.Last().Data;
     
    124134              // subtree contains fragment => branching point in the fragment graph
    125135              var n = GetTraceNode(g, si, fi);
    126               Trace(parents[0], si, n);
    127               Trace(parents[1], fragment.Index2, n);
     136              TraceRecursive(parents[0], si, n);
     137              TraceRecursive(parents[1], fragment.Index2, n);
    128138              break;
    129139            } else {
     
    144154            var n = GetTraceNode(g, si, fi);
    145155            int i = si < fi ? si : fi;
    146             Trace(parents[0], i, n);
     156            TraceRecursive(parents[0], i, n);
    147157            break;
    148158          } else {
     
    207217  internal static class Util {
    208218    // shallow node copy (does not clone the data or the arcs)
     219    #region some helper methods for shortening the tracing code
    209220    public static IGenealogyGraphNode<ISymbolicExpressionTree> Copy(this IGenealogyGraphNode<ISymbolicExpressionTree> node) {
    210221      return new GenealogyGraphNode<ISymbolicExpressionTree>(node.Data) { Rank = node.Rank, Quality = node.Quality };
    211222    }
    212     #region some helper methods for shortening the tracing code
    213223    public static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTree tree, int index) {
    214224      return NodeAt(tree.Root, index);
Note: See TracChangeset for help on using the changeset viewer.