public AddEdge ( int sourceNodeId, int destNodeId, int cost, int level = 1, bool inter = false ) : void | ||
sourceNodeId | int | |
destNodeId | int | |
cost | int | |
level | int | |
inter | bool | |
Résultat | void |
public void RemoveAbstractNode(HierarchicalMap map, int nodeId, int stal) { var abstractGraph = map.AbstractGraph; if (m_stalUsed[stal]) { // The node was an existing entrance point in the graph. Restore it with // the information we kept when inserting var nodeInfo = abstractGraph.GetNodeInfo(nodeId); nodeInfo.Level = m_stalLevel[stal]; abstractGraph.RemoveEdgesFromNode(nodeId); abstractGraph.AddNode(nodeId, nodeInfo); foreach (var edge in m_stalEdges[stal]) { var targetNodeId = edge.TargetNodeId; map.AddEdge(nodeId, targetNodeId, edge.Info.Cost, edge.Info.Level, edge.Info.IsInterEdge); map.AddEdge(targetNodeId, nodeId, edge.Info.Cost, edge.Info.Level, edge.Info.IsInterEdge); } } else { // Just delete the node from the graph var currentNodeInfo = abstractGraph.GetNodeInfo(nodeId); var clusterId = currentNodeInfo.ClusterId; var cluster = map.Clusters[clusterId]; cluster.RemoveLastEntranceRecord(); map.AbsNodeIds[currentNodeInfo.CenterId] = Constants.NO_NODE; abstractGraph.RemoveEdgesFromNode(nodeId); abstractGraph.RemoveLastNode(); } }
// insert a new node, such as start or target, to the abstract graph and // returns the id of the newly created node in the abstract graph // x and y are the positions where I want to put the node private int InsertStal(HierarchicalMap map, int nodeId, Position pos, int start) { // If the node already existed (for instance, it was the an entrance point already // existing in the graph, we need to keep track of the previous status in order // to be able to restore it once we delete this STAL if (map.AbsNodeIds[nodeId] != Constants.NO_NODE) { m_stalLevel[start] = map.AbstractGraph.GetNodeInfo(map.AbsNodeIds[nodeId]).Level; m_stalEdges[start] = map.GetNodeEdges(nodeId); m_stalUsed[start] = true; return map.AbsNodeIds[nodeId]; } m_stalUsed[start] = false; var cluster = map.FindClusterForPosition(pos); // create global entrance var absNodeId = map.NrNodes; var localEntranceIdx = cluster.AddEntrance(absNodeId, new Position(pos.X - cluster.Origin.X, pos.Y - cluster.Origin.Y)); cluster.UpdatePaths(localEntranceIdx); map.AbsNodeIds[nodeId] = absNodeId; var info = new AbsTilingNodeInfo( absNodeId, 1, cluster.Id, pos, nodeId, localEntranceIdx); map.AbstractGraph.AddNode(absNodeId, info); // add new edges to the abstract graph for (var k = 0; k < cluster.GetNrEntrances() - 1; k++) { if (cluster.AreConnected(localEntranceIdx, k)) { map.AddEdge( cluster.GetGlobalAbsNodeId(k), cluster.GetGlobalAbsNodeId(localEntranceIdx), cluster.GetDistance(localEntranceIdx, k)); map.AddEdge( cluster.GetGlobalAbsNodeId(localEntranceIdx), cluster.GetGlobalAbsNodeId(k), cluster.GetDistance(k, localEntranceIdx)); } } return absNodeId; }
/// <summary> /// Adds an edge between two abstract nodes for a given level /// </summary> private static void AddEdgesBetweenAbstractNodes(HierarchicalMap map, int absNodeId1, int absNodeId2, int level) { if (absNodeId1 == absNodeId2 || !IsValidAbstractNode(map, absNodeId2, level)) return; var search = new AStar(); var path = search.FindPath(map, absNodeId1, absNodeId2); if (path.PathCost >= 0) { map.AddEdge(absNodeId1, absNodeId2, path.PathCost, level, false); map.AddEdge(absNodeId2, absNodeId1, path.PathCost, level, false); } }