Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12933


Ignore:
Timestamp:
09/02/15 16:26:23 (9 years ago)
Author:
bburlacu
Message:

#1772: Added a parameter to the tree query matching algorithm to specify whether only strict parent-child pairs in the data tree should be matched with the query (otherwise ancestor-descendant pairs are also considered valid).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/QueryMatch.cs

    r12929 r12933  
    4747    }
    4848
     49    // whether matching nodes should also have matching parents
     50    // in theory, this restricts the matching so that parent-child
     51    // pairs in the query tree are matched by parent-child pairs in
     52    // the data tree (and not ancestor-descendant pairs)
     53    public bool MatchParents { get; set; }
     54
    4955    public QueryMatch(ISymbolicExpressionTreeNodeEqualityComparer comparer) {
    5056      this.comparer = comparer;
     
    7076    }
    7177
     78    private bool AreMatching(NodeInfo a, NodeInfo b) {
     79      bool equals = comparer.Equals(a.Node, b.Node);
     80
     81      if (equals && MatchParents) {
     82        var pa = a.Parent();
     83        var pb = b.Parent();
     84        if (pa != null && pb != null)
     85          return comparer.Equals(pa.Node, pb.Node);
     86        if (!(pa == null && pb == null))
     87          return false;
     88      }
     89      return equals;
     90    }
     91
    7292    private NodeInfo Tmatch(NodeInfo d, NodeInfo qFrom, NodeInfo qUntil, int tab = 0) {
    7393#if DEBUG
     
    7797
    7898      var next = qBest.Next();
    79       if (next.Index <= qUntil.Index && comparer.Equals(d.Node, next.Node)) {
     99      if (next.Index <= qUntil.Index && AreMatching(d, next)) {
    80100        qBest = next;
    81101        next = qBest.Next();
Note: See TracChangeset for help on using the changeset viewer.