public List <IPathNode> AbstractPathToLowLevelPath(HierarchicalMap map, List <AbstractPathNode> abstractPath, int mapWidth, int maxPathsToCalculate = int.MaxValue) { var result = new List <IPathNode>(); if (abstractPath.Count == 0) { return(result); } var calculatedPaths = 0; var lastAbstractNodeId = abstractPath[0].Id; if (abstractPath[0].Level != 1) { result.Add(abstractPath[0]); } else { var abstractNode = map.AbstractGraph.GetNodeInfo(lastAbstractNodeId); result.Add(new ConcretePathNode(abstractNode.ConcreteNodeId)); } for (var currentPoint = 1; currentPoint < abstractPath.Count; currentPoint++) { var currentAbstractNodeId = abstractPath[currentPoint].Id; var lastNodeInfo = map.AbstractGraph.GetNodeInfo(lastAbstractNodeId); var currentNodeInfo = map.AbstractGraph.GetNodeInfo(currentAbstractNodeId); if (lastAbstractNodeId == currentAbstractNodeId) { continue; } // We cannot compute a low level path from a level which is higher than lvl 1 // (obvious...) therefore, ignore any non-refined path if (abstractPath[currentPoint].Level != 1) { result.Add(abstractPath[currentPoint]); continue; } var currentNodeClusterId = currentNodeInfo.ClusterId; var lastNodeClusterId = lastNodeInfo.ClusterId; if (currentNodeClusterId == lastNodeClusterId && calculatedPaths < maxPathsToCalculate) { var cluster = map.GetCluster(currentNodeClusterId); var localPath = cluster.GetPath(lastAbstractNodeId, currentAbstractNodeId); var concretePath = new List <IPathNode>(); for (int i = 1; i < localPath.Count; i++) { int concreteNodeId = LocalNodeId2ConcreteNodeId(localPath[i].IdValue, cluster, mapWidth); concretePath.Add(new ConcretePathNode(Id <ConcreteNode> .From(concreteNodeId))); } result.AddRange(concretePath); calculatedPaths++; } else { // Inter-cluster edge var lastConcreteNodeId = lastNodeInfo.ConcreteNodeId; var currentConcreteNodeId = currentNodeInfo.ConcreteNodeId; if (((ConcretePathNode)result[result.Count - 1]).Id != lastConcreteNodeId) { result.Add(new ConcretePathNode(lastConcreteNodeId)); } if (((ConcretePathNode)result[result.Count - 1]).Id != currentConcreteNodeId) { result.Add(new ConcretePathNode(currentConcreteNodeId)); } } lastAbstractNodeId = currentAbstractNodeId; } return(result); }
public List<PathNode> AbstractPathToLowLevelPath(HierarchicalMap map, List<PathNode> absPath, int width, int maxPathsToCalculate = int.MaxValue) { var result = new List<PathNode>(absPath.Count * 10); if (absPath.Count == 0) return result; var calculatedPaths = 0; var lastAbsNodeId = absPath[0].Id; for (var j = 1; j < absPath.Count; j++) { var currentAbsNodeId = absPath[j].Id; var currentNodeInfo = map.AbstractGraph.GetNodeInfo(currentAbsNodeId); var lastNodeInfo = map.AbstractGraph.GetNodeInfo(lastAbsNodeId); // We cannot compute a low level path from a level which is higher than lvl 1 // (obvious...) therefore, ignore any non-refined path if (absPath[j].Level > 1) { result.Add(absPath[j]); continue; } var eClusterId = currentNodeInfo.ClusterId; var leClusterId = lastNodeInfo.ClusterId; if (eClusterId == leClusterId && calculatedPaths < maxPathsToCalculate) { // insert the local solution into the global one // var cluster = map.GetCluster(eClusterId); //var localpos1 = cluster.GetLocalPosition(lastNodeInfo.LocalEntranceId); //var localpos2 = cluster.GetLocalPosition(currentNodeInfo.LocalEntranceId); if (lastNodeInfo.LocalEntranceId != currentNodeInfo.LocalEntranceId) { var cluster = map.GetCluster(eClusterId); var localPath = cluster.GetPath(lastNodeInfo.LocalEntranceId, currentNodeInfo.LocalEntranceId) .Select( localId => { int localPoint = LocalClusterId2GlobalId(localId, cluster, width); return new PathNode(localPoint, 0); }); result.AddRange(localPath); calculatedPaths++; } } else { var lastVal = lastNodeInfo.CenterId; var currentVal = currentNodeInfo.CenterId; if (result[result.Count - 1].Id != lastVal) result.Add(new PathNode(lastVal, 0)); result.Add(new PathNode(currentVal, 0)); } lastAbsNodeId = currentAbsNodeId; } return result; }
/// <summary> /// 计算出抽象路径对应的具体路径 /// </summary> private static List <PathNode> AbstractPathToConcretePath(HierarchicalMap map, List <PathNode> abstractPath, int maxRefineCount) { var result = new List <PathNode>(); if (abstractPath.Count == 0) { return(result); } int calculatedPaths = 0; var lastAbstractNodeId = abstractPath[0].Id; if (abstractPath[0].Level != 1) { result.Add(abstractPath[0]); } else { var abstractNode = map.AbstractGraph.GetNode(lastAbstractNodeId); result.Add(new PathNode(abstractNode.Pos)); } for (int curtIndex = 1; curtIndex < abstractPath.Count; curtIndex++) { var curtPathNode = abstractPath[curtIndex]; var lastAbsNode = map.AbstractGraph.GetNode(lastAbstractNodeId); var curtAbsNode = map.AbstractGraph.GetNode(curtPathNode.Id); if (lastAbstractNodeId == curtAbsNode.Id) { continue; } //TODO 对于没有Refine的点,需要找个方式处理,直接加进去不好 if (curtPathNode.Level != 1) { result.Add(curtPathNode); continue; } int curtClusterId = curtAbsNode.ClusterId; int lastClusterId = lastAbsNode.ClusterId; if (curtClusterId == lastClusterId && calculatedPaths < maxRefineCount) //查找Cluster内部的路径 { var cluster = map.GetCluster(curtClusterId); var localPath = cluster.GetPath(lastAbsNode.Id, curtAbsNode.Id); for (int i = 1; i < localPath.Count; i++) { result.Add(new PathNode(localPath[i].Pos)); } calculatedPaths++; } else //查找Cluster之间的路径(直接相连,所以把两个节点加起来即可) { if (result[result.Count - 1].Pos != lastAbsNode.Pos) { result.Add(new PathNode(lastAbsNode.Pos)); } if (result[result.Count - 1].Pos != curtAbsNode.Pos) { result.Add(new PathNode(curtAbsNode.Pos)); } } lastAbstractNodeId = curtAbsNode.Id; } return(result); }