public List <AbstractPathNode> RefineAbstractPath(HierarchicalMap map, List <AbstractPathNode> path, int level, int maxPathsToRefine = int.MaxValue) { var refinedAbstractPath = new List <AbstractPathNode>(); var calculatedPaths = 0; if (path.Count == 0) { return(refinedAbstractPath); } refinedAbstractPath.Add(new AbstractPathNode(path[0].Id, level - 1)); for (var i = 1; i < path.Count; i++) { if (path[i].Level == level && path[i].Level == path[i - 1].Level && map.BelongToSameCluster(path[i].Id, path[i - 1].Id, level) && calculatedPaths < maxPathsToRefine) { var interNodePath = GetPath(map, path[i - 1].Id, path[i].Id, level - 1, false); for (int j = 1; j < interNodePath.Count; j++) { refinedAbstractPath.Add(interNodePath[j]); } calculatedPaths++; } else { refinedAbstractPath.Add(new AbstractPathNode(path[i].Id, level - 1)); } } return(refinedAbstractPath); }
/// <summary> /// Refines all the nodes that belong to a certain level to a lower level /// </summary> public List<PathNode> RefineAbstractPath(HierarchicalMap map, List<PathNode> path, int level, int maxPathsToRefine = int.MaxValue) { var result = new List<PathNode>(); var calculatedPaths = 0; for (var i = 0; i < path.Count - 1; i++) { // if the two consecutive points belong to the same cluster, compute the path between them and // add the resulting nodes of that path to the list if (path[i].Level == path[i + 1].Level && path[i].Level == level && map.BelongToSameCluster(path[i].Id, path[i + 1].Id, level) && calculatedPaths < maxPathsToRefine) { var tmp = this.PerformSearch(map, path[i].Id, path[i + 1].Id, level - 1, false) .Select(n => new PathNode(n, level - 1)) .ToList(); result.AddRange(tmp); calculatedPaths++; // When we have calculated a path between 2 nodes, the next path in the search // will be an interEdge node. We can safely skip it i++; } else result.Add(path[i]); } // make sure last elem is added if (result[result.Count - 1].Id != path[path.Count - 1].Id) result.Add(path[path.Count - 1]); return result; }
private static List <PathNode> RefineAbstractPath(HierarchicalMap map, List <PathNode> path, int level, ref int maxRefineCount) { var result = new List <PathNode>(); if (path.Count == 0) { return(result); } int calculatedPaths = 0; result.Add(new PathNode(path[0].Id, path[0].Pos, path[0].Level - 1)); for (int i = 1; i < path.Count; i++) { if (path[i].Level == level && path[i].Level == path[i - 1].Level && map.BelongToSameCluster(path[i].Pos, path[i - 1].Pos, level) && calculatedPaths < maxRefineCount) { var interPath = GetPath(map, path[i - 1].Id, path[i].Id, level - 1, false); result.AddRange(interPath); calculatedPaths++; } else { result.Add(new PathNode(path[i].Id, path[i].Pos, path[i].Level - 1)); } } maxRefineCount -= calculatedPaths; return(result); }