Esempio n. 1
0
        /** Return the depth of this node in the network. */
        public int Depth(int d, NEATNetwork network, int maxDepth)
        {
            if (d > 100)
            {
                // original code use these number in code, need to find a good way
                // to justify these
                return(10);
            }

            // Base case
            if (this.Type == NodeType.SENSOR)
            {
                return(d);
            }

            d++;

            // recursion
            int curDepth = 0; // The depth of current node

            for (int i = 0; i < IncomingGenes.Count; ++i)
            {
                NEATNode node = IncomingGenes[i].InNode;
                if (!node.IsTraversed)
                {
                    node.IsTraversed = true;
                    curDepth         = node.Depth(d, network, maxDepth);
                    node.InnerLevel  = curDepth - d;
                }
                else
                {
                    curDepth = d + node.InnerLevel;
                }

                maxDepth = Math.Max(curDepth, maxDepth);
            }
            return(maxDepth);
        }