protected virtual void ProcessChildNode(NodeRecord parent, NavigationGraphEdge connectionEdge) { var childNode = connectionEdge.ToNode; var childNodeRecord = new NodeRecord { node = childNode, parent = parent, gValue = parent.gValue + connectionEdge.Cost, hValue = this.Heuristic.H(childNode, this.GoalNode) }; childNodeRecord.fValue = F(childNodeRecord); NodeRecord openNode = Open.SearchInOpen(childNodeRecord); NodeRecord closedNode = Closed.SearchInClosed(childNodeRecord); if (openNode == null && closedNode == null) { Open.AddToOpen(childNodeRecord); } else if (openNode != null && openNode.fValue > childNodeRecord.fValue) { Open.Replace(openNode, childNodeRecord); } else if (closedNode != null && closedNode.fValue > childNodeRecord.fValue) { Closed.RemoveFromClosed(closedNode); Open.AddToOpen(childNodeRecord); } }
protected virtual void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex) { //this is where you process a child node var childNode = GenerateChildNodeRecord(parentNode, connectionEdge); NodeRecord childOpen = Open.SearchInOpen(childNode); NodeRecord childClose = Closed.SearchInClosed(childNode); if (childOpen == null && childClose == null) { Open.AddToOpen(childNode); if (this.MaxOpenNodes < Open.CountOpen()) { this.MaxOpenNodes = Open.CountOpen(); } // childOpen.status = NodeStatus.Open; } else if (childOpen != null && childOpen.fValue > childNode.fValue) { Open.Replace(childOpen, childNode); } else if (childClose != null && childClose.fValue > childNode.fValue) { Closed.RemoveFromClosed(childClose); Open.AddToOpen(childNode); //childOpen.status = NodeStatus.Open; } }
protected virtual void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex) { //this is where you process a child node var childNode = GenerateChildNodeRecord(parentNode, connectionEdge); //TODO: implement the rest of the code here var nodeOpen = Open.SearchInOpen(childNode); var nodeClose = Closed.SearchInClosed(childNode); if (nodeOpen != null) { if (nodeOpen.fValue >= childNode.fValue) { Open.RemoveFromOpen(nodeOpen); Open.AddToOpen(childNode); } return; } else if (nodeClose != null) { if (nodeClose.fValue > childNode.fValue) { Closed.RemoveFromClosed(nodeClose); Open.AddToOpen(childNode); } return; } Open.AddToOpen(childNode); }
protected virtual void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int connectionIndex) { //this is where you process a child node var childNode = GenerateChildNodeRecord(parentNode, connectionEdge); NodeRecord openNode = Open.SearchInOpen(childNode); NodeRecord closeNode = Closed.SearchInClosed(childNode); if (openNode == null && closeNode == null) { this.Open.AddToOpen(childNode); } else if (openNode != null && childNode.fValue < openNode.fValue) { Open.Replace(openNode, childNode); } else if (openNode != null && childNode.fValue == openNode.fValue) { if (childNode.hValue < openNode.hValue) { Open.Replace(openNode, childNode); } } else if (closeNode != null && childNode.fValue < closeNode.fValue) { Closed.RemoveFromClosed(closeNode); Open.AddToOpen(childNode); } }
protected override void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge) { float f; float g; float h; var childNode = connectionEdge.ToNode; var childNodeRecord = this.NodeRecordArray.GetNodeRecord(childNode); if (childNodeRecord == null) { //this piece of code is used just because of the special start nodes and goal nodes added to the RAIN Navigation graph when a new search is performed. //Since these special goals were not in the original navigation graph, they will not be stored in the NodeRecordArray and we will have to add them //to a special structure //it's ok if you don't understand this, this is a hack and not part of the NodeArrayA* algorithm, just do NOT CHANGE THIS, or you algorithm wont work childNodeRecord = new NodeRecord { node = childNode, parent = bestNode, status = NodeStatus.Unvisited }; this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord); } g = bestNode.gValue + connectionEdge.Cost; h = this.Heuristic.H(childNode, this.GoalNode); f = g + h; var ChildNodeOpen = Open.SearchInOpen(childNodeRecord); var ChildNodeClosed = Closed.SearchInClosed(childNodeRecord); if ((ChildNodeClosed == null) && (ChildNodeOpen == null)) { childNodeRecord.parent = bestNode; childNodeRecord.gValue = g; childNodeRecord.hValue = h; childNodeRecord.fValue = f; Open.AddToOpen(childNodeRecord); } else if ((ChildNodeOpen != null) && f < childNodeRecord.fValue) { childNodeRecord.parent = bestNode; childNodeRecord.gValue = g; childNodeRecord.hValue = h; childNodeRecord.fValue = f; Open.Replace(ChildNodeOpen, childNodeRecord); } else if ((ChildNodeClosed != null) && f < childNodeRecord.fValue) { childNodeRecord.parent = bestNode; childNodeRecord.gValue = g; childNodeRecord.hValue = h; childNodeRecord.fValue = f; Open.AddToOpen(childNodeRecord); } }
protected override void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge, int edgeIndex) { var childNode = connectionEdge.ToNode; var childNodeRecord = this.NodeRecordArray.GetNodeRecord(childNode); if (childNodeRecord == null) { //this piece of code is used just because of the special start nodes and goal nodes added to the RAIN Navigation graph when a new search is performed. //Since these special goals were not in the original navigation graph, they will not be stored in the NodeRecordArray and we will have to add them //to a special structure //it's ok if you don't understand this, this is a hack and not part of the NodeArrayA* algorithm, just do NOT CHANGE THIS, or your algorithm will not work childNodeRecord = new NodeRecord { node = childNode, parent = bestNode, status = NodeStatus.Unvisited }; this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord); } //this is where you process a child node var parent = bestNode; var g = bestNode.gValue + (childNode.LocalPosition - bestNode.node.LocalPosition).magnitude; var h = this.Heuristic.H(childNode, this.GoalNode); //var h = this.Heuristic.Fast_H(childNode.Position, this.GoalNode.Position); var f = F(g, h); NodeRecord nodeInOpen = Open.SearchInOpen(childNodeRecord); NodeRecord nodeInClosed = Closed.SearchInClosed(childNodeRecord); if (nodeInOpen == null && nodeInClosed == null) { childNodeRecord.parent = parent; childNodeRecord.gValue = g; childNodeRecord.hValue = h; childNodeRecord.fValue = f; Open.AddToOpen(childNodeRecord); } else if (nodeInOpen != null && nodeInOpen.fValue > f) { childNodeRecord.parent = parent; childNodeRecord.gValue = g; childNodeRecord.hValue = h; childNodeRecord.fValue = f; Open.Replace(nodeInOpen, childNodeRecord); } }
protected virtual void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex) { //this is where you process a child node var childNode = GenerateChildNodeRecord(parentNode, connectionEdge); NodeRecord nodeInOpen = Open.SearchInOpen(childNode); NodeRecord nodeInClosed = Closed.SearchInClosed(childNode); if (nodeInOpen == null && nodeInClosed == null) { Open.AddToOpen(childNode); } else if (nodeInOpen != null && childNode.fValue < nodeInOpen.fValue) { Open.Replace(nodeInOpen, childNode); } }
protected override void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge, int edgeIndex) { float f; float g; float h; var childNode = connectionEdge.ToNode; var childNodeRecord = this.NodeRecordArray.GetNodeRecord(childNode); if (childNodeRecord == null) { //this piece of code is used just because of the special start nodes and goal nodes added to the RAIN Navigation graph when a new search is performed. //Since these special goals were not in the original navigation graph, they will not be stored in the NodeRecordArray and we will have to add them //to a special structure //it's ok if you don't understand this, this is a hack and not part of the NodeArrayA* algorithm, just do NOT CHANGE THIS, or your algorithm will not work childNodeRecord = new NodeRecord { node = childNode, parent = bestNode, status = NodeStatus.Unvisited }; this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord); } //TODO: implement the rest of your code here //this is where you process a child node childNodeRecord = GenerateChildNodeRecord(bestNode, connectionEdge); var openChildNode = Open.SearchInOpen(childNodeRecord); var closedChildNode = Closed.SearchInClosed(childNodeRecord); if (openChildNode == null && closedChildNode == null) { Open.AddToOpen(childNodeRecord); } else if (openChildNode != null && openChildNode.fValue > childNodeRecord.fValue) { Open.Replace(openChildNode, childNodeRecord); } else if (closedChildNode != null && closedChildNode.fValue > childNodeRecord.fValue) { //Closed.RemoveFromClosed(closedChildNode); Open.AddToOpen(childNodeRecord); } }
protected virtual void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge) { var childNodeRecord = GenerateChildNodeRecord(bestNode, connectionEdge); var oldChildNodeOpen = Open.SearchInOpen(childNodeRecord); var oldChildNodeClosed = Closed.SearchInClosed(childNodeRecord); if ((oldChildNodeClosed == null) && (oldChildNodeOpen == null)) { Open.AddToOpen(childNodeRecord); } else if ((oldChildNodeOpen != null) && oldChildNodeOpen.fValue > childNodeRecord.fValue) { Open.Replace(oldChildNodeOpen, childNodeRecord); } else if ((oldChildNodeClosed != null) && oldChildNodeClosed.fValue > childNodeRecord.fValue) { Closed.RemoveFromClosed(oldChildNodeClosed); Open.AddToOpen(childNodeRecord); } }
//don't forget to add the override keyword here if you define a ProcessChildNode method in the base class protected void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge) { var childNode = connectionEdge.ToNode; var childNodeRecord = this.NodeRecordArray.GetNodeRecord(childNode); if (childNodeRecord == null) { //this piece of code is used just because of the special start nodes and goal nodes added to the RAIN Navigation graph when a new search is performed. //Since these special goals were not in the original navigation graph, they will not be stored in the NodeRecordArray and we will have to add them //to a special structure //it's ok if you don't understand this, this is a hack and not part of the NodeArrayA* algorithm, just do NOT CHANGE THIS, or you algorithm wont work childNodeRecord = new NodeRecord { node = childNode, parent = bestNode, status = NodeStatus.Unvisited }; this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord); } childNodeRecord.gValue = bestNode.gValue + connectionEdge.Cost; childNodeRecord.hValue = this.Heuristic.H(childNode, this.GoalNode); childNodeRecord.fValue = F(childNodeRecord); NodeRecord openNode = Open.SearchInOpen(childNodeRecord); NodeRecord closedNode = Closed.SearchInClosed(childNodeRecord); if (openNode == null && closedNode == null) { Open.AddToOpen(childNodeRecord); } else if (openNode != null && openNode.fValue > childNodeRecord.fValue) { Open.Replace(openNode, childNodeRecord); } else if (closedNode != null && closedNode.fValue > childNodeRecord.fValue) { Closed.RemoveFromClosed(closedNode); Open.AddToOpen(childNodeRecord); } }
protected virtual void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge) { //this is where you process a child node var ChildNode = GenerateChildNodeRecord(bestNode, connectionEdge); var ChildNodeOpen = Open.SearchInOpen(ChildNode); var ChildNodeClosed = Closed.SearchInClosed(ChildNode); if ((ChildNodeClosed == null) && (ChildNodeOpen == null)) { Open.AddToOpen(ChildNode); } else if ((ChildNodeOpen != null) && ChildNodeOpen.fValue >= ChildNode.fValue) { Open.Replace(ChildNodeOpen, ChildNode); } else if ((ChildNodeClosed != null) && ChildNodeClosed.fValue > ChildNode.fValue) { Closed.RemoveFromClosed(ChildNodeClosed); Open.AddToOpen(ChildNode); } }
protected virtual void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge) { //this is where you process a child node NodeRecord childNode = GenerateChildNodeRecord(bestNode, connectionEdge); NodeRecord openNode = Open.SearchInOpen(childNode); NodeRecord closedNode = Closed.SearchInClosed(childNode); bool inOpen = openNode != null ? true : false; bool inClosed = closedNode != null ? true : false; if (!inOpen && !inClosed) { Open.AddToOpen(childNode); } else if (inOpen && childNode.fValue < openNode.fValue) { Open.RemoveFromOpen(openNode); Open.AddToOpen(childNode); } else if (inClosed && childNode.fValue < closedNode.fValue) { Closed.RemoveFromClosed(closedNode); Open.AddToOpen(childNode); } }
//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); }