Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11392


Ignore:
Timestamp:
09/26/14 17:02:57 (10 years ago)
Author:
bburlacu
Message:

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

File:
1 edited

Legend:

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

    r11384 r11392  
    8080
    8181    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();
    8684      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;
    9193      }
    92 
    93       return list.Count > 0 ? LowestCommonAncestor(node, list) : null;
     94      ISymbolicExpressionTreeNode result = list.Count > 0 ? LowestCommonAncestor(node, list) : null;
     95      return result;
    9496    }
    9597
     
    101103        return nodes[0];
    102104
    103       int lowestLevel = nodes.Min(x => root.GetBranchLevel(x));
     105      int minLevel = nodes.Min(x => root.GetBranchLevel(x));
    104106
    105107      // bring the nodes in the nodes to the same level (relative to the root)
     
    107109        var node = nodes[i];
    108110        var level = root.GetBranchLevel(node);
    109         for (int j = lowestLevel; j < level; ++j)
     111        for (int j = minLevel; j < level; ++j)
    110112          node = node.Parent;
    111113        nodes[i] = node;
Note: See TracChangeset for help on using the changeset viewer.