public bool Search(out GlobalPath solution, bool returnPartialSolution = false)
        {
            solution = null;
            NodeRecord bestNode = null;

            for (int max = 0; max < this.NodesPerFrame; max++)
            {
                if (Open.CountOpen() == 0)
                {
                    this.InProgress = false;
                    break;
                }
                bestNode = Open.GetBestAndRemove();
                this.TotalExploredNodes++;
                if (bestNode.node == this.GoalNode)
                {
                    solution        = CalculateSolution(bestNode, returnPartialSolution);
                    this.InProgress = false;
                    return(true);
                }
                Closed.AddToClosed(bestNode);
                var outConnections = bestNode.node.OutEdgeCount;
                //Debug.Log(bestNode.hValue);
                for (int i = 0; i < outConnections; i++)
                {
                    this.ProcessChildNode(bestNode, bestNode.node.EdgeOut(i), i);
                }
            }
            this.TotalProcessingTime += Time.deltaTime;
            //solution = CalculateSolution(bestNode, true);
            return(true);
        }
        public bool Search(out GlobalPath solution, bool returnPartialSolution = false)
        {
            NodeRecord currentNode = Open.GetBestAndRemove();

            if (currentNode.node == this.GoalNode)
            {
                solution = CalculateSolution(currentNode, returnPartialSolution);
                return(true);
            }
            Closed.AddToClosed(currentNode);
            this.TotalExploredNodes++;

            var outConnections = currentNode.node.OutEdgeCount;

            for (int i = 0; i < outConnections; i++)
            {
                this.ProcessChildNode(currentNode, currentNode.node.EdgeOut(i), i);
            }

            if (this.TotalExploredNodes % this.NodesPerFrame == 0 && returnPartialSolution)
            {
                solution = CalculateSolution(currentNode, returnPartialSolution);
            }
            else
            {
                solution = null;
            }

            return(false);
        }
        public virtual bool Search(out GlobalPath solution, bool returnPartialSolution = false)
        {
            solution = null;

            if (InitialTime == -1.0f)
            {
                InitialTime = Time.realtimeSinceStartup;
            }

            float finalTime = 0f;

            for (int i = 0; Open.CountOpen() > 0; ++i)
            {
                NodeRecord record = Open.GetBestAndRemove();

                if (i >= NodesPerSearch)
                {
                    if (returnPartialSolution)
                    {
                        solution = CalculateSolution(record, returnPartialSolution);
                    }

                    return(false);
                }

                // update debug information
                if (Open.CountOpen() > MaxOpenNodes)
                {
                    MaxOpenNodes = Open.CountOpen();
                }

                ++TotalProcessedNodes;

                if (record.node == GoalNode)
                {
                    solution = CalculateSolution(record, returnPartialSolution);
                    CleanUp();
                    finalTime           = Time.realtimeSinceStartup;
                    TotalProcessingTime = finalTime - InitialTime;
                    return(true);
                }

                Closed.AddToClosed(record);

                for (int e = 0; e < record.node.OutEdgeCount; ++e)
                {
                    ProcessChildNode(record, record.node.EdgeOut(e));
                }
            }

            CleanUp();
            finalTime           = Time.realtimeSinceStartup;
            TotalProcessingTime = finalTime - InitialTime;
            return(true);
        }
        public bool Search(out GlobalPath solution, bool returnPartialSolution = false)
        {
            var startTime = Time.realtimeSinceStartup;
            int counter   = 0;

            while (true)
            {
                if (Open.CountOpen() == 0)
                {
                    solution             = null;
                    TotalProcessingTime += Time.realtimeSinceStartup - startTime;
                    CleanUp();
                    return(true);
                }
                NodeRecord bestNode = Open.GetBestAndRemove();
                if (bestNode.node.Equals(GoalNode))
                {
                    solution             = CalculateSolution(bestNode, false);
                    this.InProgress      = false;
                    TotalProcessingTime += Time.realtimeSinceStartup - startTime;
                    CleanUp();
                    return(true);
                }
                Closed.AddToClosed(bestNode);

                //to determine the connections of the selected nodeRecord you need to look at the NavigationGraphNode' EdgeOut  list
                //something like this
                var outConnections = bestNode.node.OutEdgeCount;
                for (int i = 0; i < outConnections; i++)
                {
                    this.ProcessChildNode(bestNode, bestNode.node.EdgeOut(i));
                }
                if (counter >= NodesPerSearch)
                {
                    TotalProcessingTime += Time.realtimeSinceStartup - startTime;
                    solution             = CalculateSolution(bestNode, true);
                    return(false);
                }
                counter             += 1;
                TotalProcessedNodes += 1;
                if (MaxOpenNodes <= Open.CountOpen())
                {
                    MaxOpenNodes = Open.CountOpen();
                }
            }
        }
Exemple #5
0
        public bool Search(out GlobalPath solution, bool returnPartialSolution = false)
        {
            int processedNodes = 0;
            int OpenSize       = 1;

            while (OpenSize > 0)
            {
                OpenSize = Open.All().Count;
                if (MaxOpenNodes < OpenSize)
                {
                    MaxOpenNodes = OpenSize;
                }
                NodeRecord bestNode = Open.PeekBest();
                if (processedNodes < NodesPerFrame)
                {
                    if (bestNode.node.Equals(GoalNode))
                    {
                        this.TotalProcessingTime = (Time.time - startTime);
                        solution        = CalculateSolution(bestNode, false);
                        this.InProgress = false;
                        return(false);
                    }
                    Open.RemoveFromOpen(bestNode);
                    Closed.AddToClosed(bestNode);
                    TotalExploredNodes++;
                    processedNodes++;
                    var outConnections = bestNode.node.OutEdgeCount;
                    for (int i = 0; i < outConnections; i++)
                    {
                        this.ProcessChildNode(bestNode, bestNode.node.EdgeOut(i), i);
                    }
                }
                else if (processedNodes == NodesPerFrame)
                {
                    this.TotalProcessingTime = (Time.time - startTime);
                    solution = CalculateSolution(bestNode, true);
                    return(true);
                }
            }
            this.TotalProcessingTime = (Time.time - startTime);
            solution = null;
            return(false);
        }
Exemple #6
0
        public bool Search(out GlobalPath solution, bool returnPartialSolution = false)
        {
            var openCount = Open.CountOpen();

            solution = null;
            for (int j = 0; j < this.NodesPerFrame; j++)
            {
                if (openCount == 0)
                {
                    solution                  = null;
                    this.InProgress           = false;
                    this.TotalProcessingTime += Time.time;
                    return(true);
                }
                var bestNode = Open.GetBestAndRemove();
                this.TotalExploredNodes++;
                Closed.AddToClosed(bestNode);
                if (bestNode.node.Equals(GoalNode))
                {
                    solution                  = CalculateSolution(bestNode, false);
                    this.InProgress           = false;
                    this.TotalProcessingTime += Time.time;
                    return(true);
                }
                var outConnections = bestNode.node.OutEdgeCount;
                for (int i = 0; i < outConnections; i++)
                {
                    this.ProcessChildNode(bestNode, bestNode.node.EdgeOut(i), i);
                }
                openCount = this.Open.CountOpen();
                if (openCount > this.MaxOpenNodes)
                {
                    this.MaxOpenNodes = openCount;
                }
            }
            if (returnPartialSolution)
            {
                solution = CalculateSolution(Open.PeekBest(), true);
            }
            return(false);
        }
Exemple #7
0
        //this method should return true if it finished processing, and false if it still needs to continue
        public bool MapFloodDijkstra()
        {
            var processedNodes = 0;

            while (Open.CountOpen() > 0)
            {
                processedNodes++;

                if (processedNodes > NodesPerFlood)
                {
                    return(false);
                }
                LocationRecord currentRecord = Open.GetBestAndRemove();
                Closed.AddToClosed(currentRecord);

                int outConnections = currentRecord.Location.OutEdgeCount;
                for (int i = 0; i < outConnections; i++)
                {
                    var   location  = GenerateChildNodeRecord(currentRecord, currentRecord.Location.EdgeOut(i));
                    float influence = InfluenceFunction.DetermineInfluence(currentRecord.StrongestInfluenceUnit, location.Location.Position);

                    if (InfluenceThreshold.CompareTo(influence) > 0)
                    {
                        continue;
                    }

                    LocationRecord neighborRecord = Closed.SearchInClosed(location);

                    if (neighborRecord != null)
                    {
                        if (neighborRecord.Influence >= influence)
                        {
                            continue;
                        }
                        else
                        {
                            Closed.RemoveFromClosed(neighborRecord);
                        }
                    }
                    else
                    {
                        neighborRecord = Open.SearchInOpen(location);

                        if (neighborRecord != null)
                        {
                            if (neighborRecord.Influence < influence)
                            {
                                neighborRecord.StrongestInfluenceUnit = currentRecord.StrongestInfluenceUnit;
                                neighborRecord.Influence = influence;
                            }
                            continue;
                        }
                        else //we found a new record not in open or closed
                        {
                            neighborRecord          = new LocationRecord();
                            neighborRecord.Location = location.Location;
                        }
                    }

                    neighborRecord.StrongestInfluenceUnit = currentRecord.StrongestInfluenceUnit;
                    neighborRecord.Influence = influence;
                    Open.AddToOpen(neighborRecord);
                }
            }

            this.InProgress = false;
            //this.CleanUp();
            return(true);
        }
Exemple #8
0
        public bool Search(out GlobalPath solution, bool returnPartialSolution = false)
        {
            var time           = UnityEngine.Time.realtimeSinceStartup;
            var nodesprocessed = 0;
            var maximumOpen    = 0;



            //to determine the connections of the selected nodeRecord you need to look at the NavigationGraphNode' EdgeOut  list
            //something like this

            while (true)
            {
                if (Open.CountOpen() > maximumOpen)
                {
                    maximumOpen = Open.CountOpen();
                }

                if (Open.CountOpen() == 0)
                {
                    solution             = null;
                    InProgress           = false;
                    TotalProcessedNodes += (uint)nodesprocessed;
                    TotalProcessingTime  = UnityEngine.Time.realtimeSinceStartup - time;
                    MaxOpenNodes         = maximumOpen;
                    return(true);
                }

                NodeRecord bestNode = Open.GetBestAndRemove();

                if (nodesprocessed > NodesPerSearch)
                {
                    if (returnPartialSolution)
                    {
                        solution = CalculateSolution(bestNode, returnPartialSolution);
                    }
                    else
                    {
                        solution = null;
                    }
                    InProgress           = true;
                    TotalProcessedNodes += (uint)nodesprocessed;
                    TotalProcessingTime  = UnityEngine.Time.realtimeSinceStartup - time;
                    MaxOpenNodes         = maximumOpen;
                    return(false);
                }


                if (bestNode.node == GoalNode)
                {
                    solution             = CalculateSolution(bestNode, false);
                    InProgress           = false;
                    TotalProcessedNodes += (uint)nodesprocessed;
                    TotalProcessingTime  = UnityEngine.Time.realtimeSinceStartup - time;
                    MaxOpenNodes         = maximumOpen;
                    return(true);
                }

                Closed.AddToClosed(bestNode);
                nodesprocessed++;


                //
                //TODO put your code here
                //or if you would like, you can change just these lines of code this in the original A* Pathfinding Base Class,
                //create a ProcessChildNode method in the base class with the code from the previous A* algorithm.
                //if you do this, then you don't need to implement this search method method. Just delete this and don't forget to override the ProcessChildMethod if you do this
                var outConnections = bestNode.node.OutEdgeCount;
                for (int i = 0; i < outConnections; i++)
                {
                    this.ProcessChildNode(bestNode, bestNode.node.EdgeOut(i));
                }
            }
        }
Exemple #9
0
        public bool Search(out GlobalPath solution, bool returnPartialSolution = false)
        {
            //TODO put the code from the previous LAB here
            //you will get compiler errors, because I change the method names in the IOpenSet and IClosedSet interfaces
            //sorry but I had to do it because if not, Unity profiler would consider the Search method in Open and Closed to be the same
            //and you would not be able to see the difference in performance searching the Open Set and in searching the closed set

            //so just replace this.Open.Search(...) by this.Open.SearchInOpen(...) and all other methods where you get the compilation errors

            var   CurrentSearchNodes = 0;
            var   NodesProcessed     = 0;
            var   MaxOpenSize        = 0;
            float StartTime          = Time.realtimeSinceStartup;

            while (true)
            {
                if (Open.CountOpen() > MaxOpenSize)
                {
                    MaxOpenSize = Open.CountOpen();
                }

                if (Open.CountOpen() == 0)
                {
                    solution            = null;
                    TotalProcessedNodes = (uint)NodesProcessed;
                    MaxOpenNodes        = MaxOpenSize;
                    this.InProgress     = false;
                    TotalProcessingTime = Time.realtimeSinceStartup - StartTime;
                    return(true);
                }


                if (NodesPerSearch < CurrentSearchNodes)
                {
                    if (returnPartialSolution)
                    {
                        solution = CalculateSolution(this.Open.PeekBest(), returnPartialSolution);
                    }
                    else
                    {
                        solution = null;
                    }

                    TotalProcessedNodes = (uint)NodesProcessed;
                    MaxOpenNodes        = MaxOpenSize;
                    TotalProcessingTime = Time.realtimeSinceStartup - StartTime;
                    return(false);
                }

                NodeRecord CurrentNode = Open.GetBestAndRemove();

                if (CurrentNode.node == GoalNode)
                {
                    InProgress          = false;
                    TotalProcessedNodes = (uint)NodesProcessed;
                    MaxOpenNodes        = MaxOpenSize;
                    TotalProcessingTime = Time.realtimeSinceStartup - StartTime;
                    solution            = CalculateSolution(CurrentNode, false);
                    return(true);
                }

                Closed.AddToClosed(CurrentNode);
                CurrentSearchNodes++;
                NodesProcessed++;
                var NodeActions = CurrentNode.node.OutEdgeCount;

                for (int i = 0; i < NodeActions; i++)
                {
                    ProcessChildNode(CurrentNode, CurrentNode.node.EdgeOut(i));
                }
            }
        }