public override int GetMaximumSubtreeCount(ISymbol symbol)
 {
     if (grammar.ContainsSymbol(symbol))
     {
         return(grammar.GetMaximumSubtreeCount(symbol));
     }
     return(base.GetMaximumSubtreeCount(symbol));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Randomly determines an arity for the given node.
        /// </summary>
        /// <param name="random">random number generator</param>
        /// <param name="node">node, for which a random arity is determined</param>
        /// <param name="grammar">symbolic expression grammar to use</param>
        /// <returns>random arity in the interval [minArity, maxArity]</returns>
        protected int SampleArity(IRandom random,
                                  ISymbolicExpressionTreeNode node,
                                  ISymbolicExpressionGrammar grammar)
        {
            int minArity = grammar.GetMinimumSubtreeCount(node.Symbol);
            int maxArity = grammar.GetMaximumSubtreeCount(node.Symbol);

            if (minArity == maxArity)
            {
                return(minArity);
            }

            return(random.Next(minArity, maxArity));
        }
Ejemplo n.º 3
0
 public int GetMaximumSubtreeCount(ISymbol symbol)
 {
     return(grammar.GetMaximumSubtreeCount(symbol));
 }
    /// <summary>
    /// Randomly determines an arity for the given node.
    /// </summary>
    /// <param name="random">random number generator</param>
    /// <param name="node">node, for which a random arity is determined</param>
    /// <param name="grammar">symbolic expression grammar to use</param>
    /// <returns>random arity in the interval [minArity, maxArity]</returns>
    protected int SampleArity(IRandom random,
                              ISymbolicExpressionTreeNode node,
                              ISymbolicExpressionGrammar grammar) {

      int minArity = grammar.GetMinimumSubtreeCount(node.Symbol);
      int maxArity = grammar.GetMaximumSubtreeCount(node.Symbol);

      if (minArity == maxArity) {
        return minArity;
      }

      return random.Next(minArity, maxArity);
    }