public void Search(NavigationGraphNode startNode, NodeGoalBounds nodeGoalBounds) { //TODO: Implement the algorithm that calculates the goal bounds using a dijkstra //Given that the nodes in the graph correspond to the edges of a polygon, we won't be able to use the vertices of the polygon to update the bounding boxes this.Open.Initialize(); this.Closed.Initialize(); NodeRecord StartNode = NodeRecordArray.GetNodeRecord(startNode); StartNode.StartNodeOutConnectionIndex = -1; Open.AddToOpen(StartNode); int OpenSize = Open.All().Count; while (OpenSize > 0) { NodeRecord currentNode = Open.GetBestAndRemove(); Open.RemoveFromOpen(currentNode); Closed.AddToClosed(currentNode); if (currentNode.StartNodeOutConnectionIndex != -1) { nodeGoalBounds.connectionBounds[currentNode.StartNodeOutConnectionIndex].UpdateBounds(currentNode.node.Position); } //Initialize start node edge colors: var outConnections = currentNode.node.OutEdgeCount; for (int i = 0; i < outConnections; i++) { this.ProcessChildNode(currentNode, currentNode.node.EdgeOut(i), i); } OpenSize = Open.All().Count; } }
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); }
ICollection<NodeRecord> IOpenSet.All() { return Open.All(); }