예제 #1
0
        /// <summary>
        /// Returns true if inner1 can feasibly be swapped into inner2's position
        /// </summary>
        private bool VerifyPoints(GPNode inner1, GPNode inner2)
        {
            // We know they're swap-compatible since we generated inner1
            // to be exactly that.  So don't bother.

            // next check to see if inner1 can fit in inner2's spot
            if (inner1.Depth + inner2.AtDepth() > MaxDepth)
            {
                return(false);
            }

            // check for size
            if (MaxSize != NO_SIZE_LIMIT)
            {
                // first easy check
                var inner1Size = inner1.NumNodes(GPNode.NODESEARCH_ALL);
                var inner2Size = inner2.NumNodes(GPNode.NODESEARCH_ALL);
                if (inner1Size > inner2Size)  // need to test further
                {
                    // let's keep on going for the more complex test
                    GPNode root2     = ((GPTree)(inner2.RootParent())).Child;
                    var    root2Size = root2.NumNodes(GPNode.NODESEARCH_ALL);
                    if (root2Size - inner2Size + inner1Size > MaxSize)  // take root2, remove inner2 and swap in inner1.  Is it still small enough?
                    {
                        return(false);
                    }
                }
            }

            // checks done!
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Returns true if inner1 can feasibly be swapped into inner2's position.
        /// </summary>
        public bool VerifyPoints(GPInitializer initializer, GPNode inner1, GPNode inner2)
        {
            // first check to see if inner1 is swap-compatible with inner2
            // on a type basis
            if (!inner1.SwapCompatibleWith(initializer, inner2))
            {
                return(false);
            }

            // next check to see if inner1 can fit in inner2's spot
            if (inner1.Depth + inner2.AtDepth() > MaxDepth)
            {
                return(false);
            }

            // check for size
            // NOTE: this is done twice, which is more costly than it should be.  But
            // on the other hand it allows us to toss a child without testing both times
            // and it's simpler to have it all here in the verifyPoints code.
            if (MaxSize != NO_SIZE_LIMIT)
            {
                // first easy check
                var inner1Size = inner1.NumNodes(GPNode.NODESEARCH_ALL);
                var inner2Size = inner2.NumNodes(GPNode.NODESEARCH_ALL);
                if (inner1Size > inner2Size)  // need to test further
                {
                    // let's keep on going for the more complex test
                    var root2     = ((GPTree)(inner2.RootParent())).Child;
                    var root2Size = root2.NumNodes(GPNode.NODESEARCH_ALL);
                    if (root2Size - inner2Size + inner1Size > MaxSize)  // take root2, remove inner2 and swap in inner1.  Is it still small enough?
                    {
                        return(false);
                    }
                }
            }

            // checks done!
            return(true);
        }