Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/22/14 12:42:20 (10 years ago)
Author:
bburlacu
Message:

#2215: Code clean-up and small performance improvements.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeDistance/BottomUpTreeDistanceCalculator.cs

    r11212 r11215  
    2626using System.Linq;
    2727using System.Text;
    28 using System.Text.RegularExpressions;
    2928using HeuristicLab.Common;
    3029using HeuristicLab.Core;
     
    9493    private static Dictionary<ISymbolicExpressionTreeNode, IVertex> Compact(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) {
    9594      var nodesToVertices = new Dictionary<ISymbolicExpressionTreeNode, IVertex>(); // K
    96       var disjointUnion = new DisjointUnion(t1, t2); // F
    9795      var labelsToVertices = new Dictionary<string, IVertex>(); // L
    9896      var childrenCount = new Dictionary<ISymbolicExpressionTreeNode, int>(); // Children
    9997      var vertices = new List<IVertex>(); // G
    100 
    101       var nodes = disjointUnion.Nodes.ToList();
     98      var nodes = t1.IterateNodesPostfix().Concat(t2.IterateNodesPostfix()); // the disjoint union F
    10299
    103100      // for all leaf labels l in F
     
    125122        } else {
    126123          bool found = false;
     124          var height = Height(v);
    127125          // for all nodes w in G in reverse order
    128126          for (int i = vertices.Count - 1; i >= 0; --i) {
    129127            var w = vertices[i];
    130             if (Height(v) != Height(w) || v.SubtreeCount != w.OutDegree || label != w.Label)
     128            if (height != Height(w) || v.SubtreeCount != w.OutDegree || label != w.Label)
    131129              continue;
    132130
     
    182180    }
    183181
    184 
    185182    private static string Label(ISymbolicExpressionTreeNode n) {
    186183      return n.ToString();
     
    195192    }
    196193
    197     private class DisjointUnion : Tuple<ISymbolicExpressionTree, ISymbolicExpressionTree> {
    198       public DisjointUnion(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2)
    199         : base(t1, t2) {
    200       }
    201 
    202       public IEnumerable<ISymbolicExpressionTreeNode> Nodes {
    203         get { return Item1.Root.IterateNodesPostfix().Concat(Item2.Root.IterateNodesPostfix()); }
    204       }
    205     }
    206 
    207     public static string RemoveFirstLines(string text, int linesCount) {
    208       var lines = Regex.Split(text, "\r\n|\r|\n").Skip(linesCount);
    209       return string.Join(Environment.NewLine, lines.ToArray());
    210     }
    211 
     194    // this is here for debugging purposes only
    212195    // draw the mapping between t1 and t2 as a tikz picture
    213196    private static string FormatMapping(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2, Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> map) {
Note: See TracChangeset for help on using the changeset viewer.