示例#1
0
        private CodeTree <S, G, R> Combine(GenePool <S, G, R> genePool, CodeTree <S, G, R> source,
                                           CodeTree <S, G, R> remove, CodeTree <S, G, R> replace)
        {
            var copy = source;

            if (source == remove)
            {
                return(replace.Clone());
            }

            if (copy.Node.Kind != NodeKind.Terminal)
            {
                for (int i = 0; i <= copy.Children.GetUpperBound(0); i++)
                {
                    var child = Combine(genePool, copy.Children[i], remove, replace);

                    copy.Children[i] = child;

                    if (genePool.GetCanMutate())
                    {
                        copy.Children[i].Node = genePool.GetTerminal();
                    }
                }
            }

            return(copy);
        }
示例#2
0
 private Node GetNode(GenePool <S, G, R> genePool, int maxDepth)
 {
     if (maxDepth > 0)
     {
         return(genePool.GetFunctionOrTerminal());
     }
     else
     {
         return(genePool.GetTerminal());
     }
 }