Ejemplo n.º 1
0
        /// <summary>
        /// Create a symbolic expression tree using 'RampedHalfAndHalf' strategy.
        /// Half the trees are created with the 'Grow' method, and the other half are created with the 'Full' method.
        /// </summary>
        /// <param name="random">Random generator</param>
        /// <param name="grammar">Available tree grammar</param>
        /// <param name="maxTreeLength">Maximum tree length (this parameter is ignored)</param>
        /// <param name="maxTreeDepth">Maximum tree depth</param>
        /// <returns></returns>
        public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth)
        {
            var tree     = new SymbolicExpressionTree();
            var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();

            if (rootNode.HasLocalParameters)
            {
                rootNode.ResetLocalParameters(random);
            }
            rootNode.SetGrammar(grammar.CreateExpressionTreeGrammar());

            var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode();

            if (startNode.HasLocalParameters)
            {
                startNode.ResetLocalParameters(random);
            }
            startNode.SetGrammar(grammar.CreateExpressionTreeGrammar());

            rootNode.AddSubtree(startNode);

            double p = random.NextDouble();

            if (p < 0.5)
            {
                GrowTreeCreator.Create(random, startNode, maxTreeDepth - 2);
            }
            else
            {
                FullTreeCreator.Create(random, startNode, maxTreeDepth - 2);
            }

            tree.Root = rootNode;
            return(tree);
        }
Ejemplo n.º 2
0
 protected FullTreeCreator(FullTreeCreator original, Cloner cloner) : base(original, cloner)
 {
 }
Ejemplo n.º 3
0
 protected FullTreeCreator(FullTreeCreator original, Cloner cloner) : base(original, cloner) { }