Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11497


Ignore:
Timestamp:
10/24/14 16:48:53 (10 years ago)
Author:
mkommend
Message:

#2268: Stored a reference to the grammar object in the cut point to avoid multiple traversion of the parents nodes for grammar access.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/CutPoint.cs

    r11171 r11497  
    2323namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    2424  public class CutPoint {
    25     public ISymbolicExpressionTreeNode Parent { get; set; }
    26     public ISymbolicExpressionTreeNode Child { get; set; }
    27     private int childIndex;
    28     public int ChildIndex {
    29       get { return childIndex; }
    30     }
    31     public CutPoint(ISymbolicExpressionTreeNode parent, ISymbolicExpressionTreeNode child) {
     25    public ISymbolicExpressionTreeNode Parent { get; private set; }
     26    public ISymbolicExpressionTreeNode Child { get; private set; }
     27    private readonly ISymbolicExpressionTreeGrammar grammar;
     28
     29    public int ChildIndex { get; private set; }
     30
     31    public CutPoint(ISymbolicExpressionTreeNode parent, ISymbolicExpressionTreeNode child) {     
    3232      this.Parent = parent;
    3333      this.Child = child;
    34       this.childIndex = parent.IndexOfSubtree(child);
     34      this.ChildIndex = parent.IndexOfSubtree(child);
     35      this.grammar = parent.Grammar;
    3536    }
    3637    public CutPoint(ISymbolicExpressionTreeNode parent, int childIndex) {
    3738      this.Parent = parent;
    38       this.childIndex = childIndex;
     39      this.ChildIndex = childIndex;
    3940      this.Child = null;
     41      this.grammar = parent.Grammar;
    4042    }
    4143
     
    4446      if (newChild == null) {
    4547        // make sure that one subtree can be removed and that only the last subtree is removed
    46         return parent.Grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.SubtreeCount &&
     48        return grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.SubtreeCount &&
    4749          this.ChildIndex == parent.SubtreeCount - 1;
    4850      } else {
    4951        // check syntax constraints of direct parent - child relation
    50         if (!parent.Grammar.ContainsSymbol(newChild.Symbol) ||
    51             !parent.Grammar.IsAllowedChildSymbol(parent.Symbol, newChild.Symbol, this.ChildIndex))
     52        if (!grammar.ContainsSymbol(newChild.Symbol) ||
     53            !grammar.IsAllowedChildSymbol(parent.Symbol, newChild.Symbol, this.ChildIndex))
    5254          return false;
    5355
     
    5759          result =
    5860            result &&
    59             parent.Grammar.ContainsSymbol(n.Symbol) &&
    60             n.SubtreeCount >= parent.Grammar.GetMinimumSubtreeCount(n.Symbol) &&
    61             n.SubtreeCount <= parent.Grammar.GetMaximumSubtreeCount(n.Symbol);
     61            grammar.ContainsSymbol(n.Symbol) &&
     62            n.SubtreeCount >= grammar.GetMinimumSubtreeCount(n.Symbol) &&
     63            n.SubtreeCount <= grammar.GetMaximumSubtreeCount(n.Symbol);
    6264        });
    6365        return result;
Note: See TracChangeset for help on using the changeset viewer.