コード例 #1
0
        /// <summary>
        /// Restores a node from the array representation back into a tree representation
        /// </summary>
        /// <param name="FunctionSet"></param>
        /// <returns>Reference to the converted tree</returns>
        public GPNode ConvertNode(IGPFunctionSet FunctionSet)
        {
            //
            // Determine the type of the node
            // < 200 : User Defined function
            // 200 to 210 : Terminal
            // 253 : ADR
            // 254 : ADL
            // 255 : ADF
            if (m_TreeArrayNew[m_ArrayPos] == 255)
            {
                m_ArrayPos++;
                byte WhichADF             = m_TreeArrayNew[m_ArrayPos++];
                byte NumberArgs           = m_TreeArrayNew[m_ArrayPos++];
                GPNodeFunctionADF NodeNew = new GPNodeFunctionADF(WhichADF, NumberArgs);
                //
                // Build up the children before returning
                for (byte Child = 0; Child < NumberArgs; Child++)
                {
                    NodeNew.Children.Add(ConvertNode(FunctionSet));
                }
                return(NodeNew);
            }
            else if (m_TreeArrayNew[m_ArrayPos] == 254)
            {
                m_ArrayPos++;
                byte WhichADL             = m_TreeArrayNew[m_ArrayPos++];
                byte NumberArgs           = m_TreeArrayNew[m_ArrayPos++];
                GPNodeFunctionADL NodeNew = new GPNodeFunctionADL(WhichADL, NumberArgs);
                //
                // Build up the children before returning
                for (byte Child = 0; Child < NumberArgs; Child++)
                {
                    NodeNew.Children.Add(ConvertNode(FunctionSet));
                }
                return(NodeNew);
            }
            else if (m_TreeArrayNew[m_ArrayPos] == 253)
            {
                m_ArrayPos++;
                byte WhichADR             = m_TreeArrayNew[m_ArrayPos++];
                byte NumberArgs           = m_TreeArrayNew[m_ArrayPos++];
                GPNodeFunctionADR NodeNew = new GPNodeFunctionADR(WhichADR, NumberArgs);
                //
                // Build up the children before returning
                for (byte Child = 0; Child < NumberArgs; Child++)
                {
                    NodeNew.Children.Add(ConvertNode(FunctionSet));
                }
                return(NodeNew);
            }
            else if (m_TreeArrayNew[m_ArrayPos] < 200)
            {
                GPNodeFunction NodeNew = (GPNodeFunction)((GPNodeFunction)FunctionSet[m_TreeArrayNew[m_ArrayPos++]]).Clone();
                //
                // Build up this node's children first
                byte ChildCount = m_TreeArrayNew[m_ArrayPos++];
                for (byte Child = 0; Child < ChildCount; Child++)
                {
                    NodeNew.Children.Add(ConvertNode(FunctionSet));
                }
                return(NodeNew);
            }
            else             // Terminal
            {
                switch (m_TreeArrayNew[m_ArrayPos++])
                {
                case 200:
                    byte WhichADFParam             = m_TreeArrayNew[m_ArrayPos++];
                    GPNodeTerminalADFParam NodeADF = new GPNodeTerminalADFParam(WhichADFParam);
                    return(NodeADF);

                case 201:
                    byte WhichUserDefined = m_TreeArrayNew[m_ArrayPos++];
                    GPNodeTerminalUserDefined NodeUser = new GPNodeTerminalUserDefined(WhichUserDefined);
                    return(NodeUser);

                case 202:
                    double dValue;
                    unsafe
                    {
                        byte *ptr = (byte *)&dValue;
                        for (int pos = 0; pos < sizeof(double); pos++)
                        {
                            ptr[pos] = m_TreeArrayNew[m_ArrayPos++];
                        }
                    }
                    GPNodeTerminalDouble NodeDouble = new GPNodeTerminalDouble(dValue);
                    return(NodeDouble);

                case 203:
                    int nValue;
                    unsafe
                    {
                        byte *ptr = (byte *)&nValue;
                        for (int pos = 0; pos < sizeof(int); pos++)
                        {
                            ptr[pos] = m_TreeArrayNew[m_ArrayPos++];
                        }
                    }
                    GPNodeTerminalInteger NodeInteger = new GPNodeTerminalInteger(nValue);
                    return(NodeInteger);
                }
            }

            //
            // TODO: Throw an exception, instead of this lazy crap! :)
            return(null);
        }
コード例 #2
0
        //
        // Cloneable interface
        public override Object Clone()
        {
            GPNodeTerminalUserDefined obj = (GPNodeTerminalUserDefined)this.MemberwiseClone();

            return(obj);
        }