Free cookie consent management tool by TermsFeed Policy Generator

# Changeset 11392

Ignore:
Timestamp:
09/26/14 17:02:57 (9 years ago)
Message:

#2164: Corrected Difference method. The way the differing nodes were collected was wrong.

File:
1 edited

Unmodified
Added
Removed
• ## trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Matching/SymbolicExpressionTreeMatching.cs

 r11384 public static ISymbolicExpressionTreeNode Difference(this ISymbolicExpressionTreeNode node, ISymbolicExpressionTreeNode other) { var these = node.IterateNodesPrefix().ToList(); var others = other.IterateNodesPrefix().ToList(); var minCount = Math.Min(these.Count, others.Count); var a = node.IterateNodesPrefix().ToList(); var b = other.IterateNodesPrefix().ToList(); var list = new List(); for (int i = 0; i < minCount; ++i) { if (these[i].ToString() != others[i].ToString()) list.Add(these[i]); for (int i = 0, j = 0; i < a.Count && j < b.Count; ++i, ++j) { var s1 = a[i].ToString(); var s2 = b[j].ToString(); if (s1 == s2) continue; list.Add(a[i]); // skip subtrees since the parents are already different i += a[i].SubtreeCount; j += b[j].SubtreeCount; } return list.Count > 0 ? LowestCommonAncestor(node, list) : null; ISymbolicExpressionTreeNode result = list.Count > 0 ? LowestCommonAncestor(node, list) : null; return result; } return nodes[0]; int lowestLevel = nodes.Min(x => root.GetBranchLevel(x)); int minLevel = nodes.Min(x => root.GetBranchLevel(x)); // bring the nodes in the nodes to the same level (relative to the root) var node = nodes[i]; var level = root.GetBranchLevel(node); for (int j = lowestLevel; j < level; ++j) for (int j = minLevel; j < level; ++j) node = node.Parent; nodes[i] = node;
Note: See TracChangeset for help on using the changeset viewer.