- Timestamp:
- 09/26/14 17:02:57 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Matching/SymbolicExpressionTreeMatching.cs
r11384 r11392 80 80 81 81 public static ISymbolicExpressionTreeNode Difference(this ISymbolicExpressionTreeNode node, ISymbolicExpressionTreeNode other) { 82 var these = node.IterateNodesPrefix().ToList(); 83 var others = other.IterateNodesPrefix().ToList(); 84 85 var minCount = Math.Min(these.Count, others.Count); 82 var a = node.IterateNodesPrefix().ToList(); 83 var b = other.IterateNodesPrefix().ToList(); 86 84 var list = new List<ISymbolicExpressionTreeNode>(); 87 88 for (int i = 0; i < minCount; ++i) { 89 if (these[i].ToString() != others[i].ToString()) 90 list.Add(these[i]); 85 for (int i = 0, j = 0; i < a.Count && j < b.Count; ++i, ++j) { 86 var s1 = a[i].ToString(); 87 var s2 = b[j].ToString(); 88 if (s1 == s2) continue; 89 list.Add(a[i]); 90 // skip subtrees since the parents are already different 91 i += a[i].SubtreeCount; 92 j += b[j].SubtreeCount; 91 93 } 92 93 return list.Count > 0 ? LowestCommonAncestor(node, list) : null;94 ISymbolicExpressionTreeNode result = list.Count > 0 ? LowestCommonAncestor(node, list) : null; 95 return result; 94 96 } 95 97 … … 101 103 return nodes[0]; 102 104 103 int lowestLevel = nodes.Min(x => root.GetBranchLevel(x));105 int minLevel = nodes.Min(x => root.GetBranchLevel(x)); 104 106 105 107 // bring the nodes in the nodes to the same level (relative to the root) … … 107 109 var node = nodes[i]; 108 110 var level = root.GetBranchLevel(node); 109 for (int j = lowestLevel; j < level; ++j)111 for (int j = minLevel; j < level; ++j) 110 112 node = node.Parent; 111 113 nodes[i] = node;
Note: See TracChangeset
for help on using the changeset viewer.