Changeset 11215 for branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeDistance/BottomUpTreeDistanceCalculator.cs
- Timestamp:
- 07/22/14 12:42:20 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeDistance/BottomUpTreeDistanceCalculator.cs
r11212 r11215 26 26 using System.Linq; 27 27 using System.Text; 28 using System.Text.RegularExpressions;29 28 using HeuristicLab.Common; 30 29 using HeuristicLab.Core; … … 94 93 private static Dictionary<ISymbolicExpressionTreeNode, IVertex> Compact(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) { 95 94 var nodesToVertices = new Dictionary<ISymbolicExpressionTreeNode, IVertex>(); // K 96 var disjointUnion = new DisjointUnion(t1, t2); // F97 95 var labelsToVertices = new Dictionary<string, IVertex>(); // L 98 96 var childrenCount = new Dictionary<ISymbolicExpressionTreeNode, int>(); // Children 99 97 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 102 99 103 100 // for all leaf labels l in F … … 125 122 } else { 126 123 bool found = false; 124 var height = Height(v); 127 125 // for all nodes w in G in reverse order 128 126 for (int i = vertices.Count - 1; i >= 0; --i) { 129 127 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) 131 129 continue; 132 130 … … 182 180 } 183 181 184 185 182 private static string Label(ISymbolicExpressionTreeNode n) { 186 183 return n.ToString(); … … 195 192 } 196 193 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 212 195 // draw the mapping between t1 and t2 as a tikz picture 213 196 private static string FormatMapping(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2, Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> map) {
Note: See TracChangeset
for help on using the changeset viewer.