예제 #1
0
        public int Calc_H(World w, GridSearchNode gridNode)
        {
            var bcc = new BiconnectedComponents(w, gridNode);

            if (!bcc.LinearLocationWasVisitedDuringBuild(w.Goal))
            {
                if (gridNode is RsdGridSearchNode)
                {
                    ((RsdGridSearchNode)gridNode).Reachable = new BitArray(w.LinearSize); //TODO: head location valid?
                }
                return(0);                                                                //Goal not reachable
            }
            var valid      = bcc.GetValidPlacesForMaxPath(gridNode.HeadLocation, w.Goal);
            int validCount = 0;

            foreach (var linearLocation in valid)
            {
                if (linearLocation)
                {
                    validCount++;
                }
            }
            if (validCount > 0)
            {
                validCount--;               //Minus 1 because we are counting the head location too
            }
            if (gridNode is RsdGridSearchNode)
            {
                ((RsdGridSearchNode)gridNode).Reachable = new BitArray(valid); //TODO: head location valid?
            }
            return(validCount);                                                //Minus 1 because we are counting the head location too
        }
예제 #2
0
        public void InitBcc()
        {
            var bcc   = new BiconnectedComponents(this);
            var valid = bcc.GetValidPlacesForMaxPath(Start, Goal);

            for (int i = 0; i < valid.Length; i++)
            {
                if (!valid[i])
                {
                    _isPostBccInitBlockedLocations[i] = true;
                }
            }
        }
        public int Calc_H(World w, GridSearchNode gridNode)
        {
            var bcc = new BiconnectedComponents(w, gridNode);

            if (!bcc.LinearLocationWasVisitedDuringBuild(w.Goal))
            {
                if (gridNode is RsdGridSearchNode)
                {
                    ((RsdGridSearchNode)gridNode).Reachable = new BitArray(w.LinearSize);
                }
                return(0); //Goal not reachable
            }
            var valid = bcc.GetValidPlacesForMaxPath(gridNode.HeadLocation, w.Goal);
            //instead of g we will count odd and even separatly
            int odd  = 0;
            int even = 0;

            int head = gridNode.HeadLocation.GetLinearLocationRepresentation(w);

            for (int i = 0; i < valid.Length; i++)
            {
                if (valid[i])
                {
                    if (i == head)
                    {
                        continue;
                    }

                    if (IsEvenLocation(w, i))
                    {
                        even++;
                    }
                    else
                    {
                        odd++;
                    }
                }
            }

            if (gridNode is RsdGridSearchNode)
            {
                ((RsdGridSearchNode)gridNode).Reachable = new BitArray(valid); //TODO: head location valid?
            }


            bool firstStepEven = !IsEvenLocation(w, head);
            bool goalEven      = IsEvenLocation(w, w.Goal.GetLinearLocationRepresentation(w));

            return(AlternateStepsHeuristic.CalculateAlternateStepHeuristic(firstStepEven, goalEven, odd, even));
        }