コード例 #1
0
ファイル: CutPoint.cs プロジェクト: YChuan1115/HeuristicLab
        public bool IsMatchingPointType(ISymbolicExpressionTreeNode newChild)
        {
            var parent = this.Parent;

            if (newChild == null)
            {
                // make sure that one subtree can be removed and that only the last subtree is removed
                return(grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.SubtreeCount &&
                       this.ChildIndex == parent.SubtreeCount - 1);
            }
            else
            {
                // check syntax constraints of direct parent - child relation
                if (!grammar.ContainsSymbol(newChild.Symbol) ||
                    !grammar.IsAllowedChildSymbol(parent.Symbol, newChild.Symbol, this.ChildIndex))
                {
                    return(false);
                }

                bool result = true;
                // check point type for the whole branch
                newChild.ForEachNodePostfix((n) => {
                    result =
                        result &&
                        grammar.ContainsSymbol(n.Symbol) &&
                        n.SubtreeCount >= grammar.GetMinimumSubtreeCount(n.Symbol) &&
                        n.SubtreeCount <= grammar.GetMaximumSubtreeCount(n.Symbol);
                });
                return(result);
            }
        }
コード例 #2
0
ファイル: CutPoint.cs プロジェクト: t-h-e/HeuristicLab
    public bool IsMatchingPointType(ISymbolicExpressionTreeNode newChild) {
      var parent = this.Parent;
      if (newChild == null) {
        // make sure that one subtree can be removed and that only the last subtree is removed 
        return grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.SubtreeCount &&
          this.ChildIndex == parent.SubtreeCount - 1;
      } else {
        // check syntax constraints of direct parent - child relation
        if (!grammar.ContainsSymbol(newChild.Symbol) ||
            !grammar.IsAllowedChildSymbol(parent.Symbol, newChild.Symbol, this.ChildIndex))
          return false;

        bool result = true;
        // check point type for the whole branch
        newChild.ForEachNodePostfix((n) => {
          result =
            result &&
            grammar.ContainsSymbol(n.Symbol) &&
            n.SubtreeCount >= grammar.GetMinimumSubtreeCount(n.Symbol) &&
            n.SubtreeCount <= grammar.GetMaximumSubtreeCount(n.Symbol);
        });
        return result;
      }
    }