public Path GetPath(MapLoc origin, MapLoc destination) { PathOD p = new PathOD(origin, destination); bool pathFound = false; if (!PathDict.ContainsKey(p)) { pathFound = AStarSearch(origin, destination); } return(PathDict[p]); }
private void AddPath(MapLoc origin, MapLoc destination, bool addBetweenPaths = false) { float dP = 0f; List <Node> shortestPath = new List <Node>(); Node thisNode = nodeDict[destination]; shortestPath.Add(thisNode); while (!thisNode.loc.Equals(origin)) { dP += thisNode.neighborWeights[thisNode.NearestTo[origin]]; thisNode = thisNode.NearestTo[origin]; shortestPath.Add(thisNode); } shortestPath.Reverse(); float dE = MapUtil.Distance(origin, destination); Path p = new Path(origin, destination, shortestPath, dP, dE); PathDict[new PathOD(origin, destination)] = p; if (addBetweenPaths) { List <PathOD> betweenPaths = new List <PathOD>(); int iWindow = shortestPath.Count - 2; while (iWindow > 0) { for (int i = 0; i < (shortestPath.Count - iWindow); i++) { PathOD betweenPath = new PathOD(shortestPath[i].loc, shortestPath[i + iWindow].loc); betweenPaths.Add(betweenPath); } iWindow--; } foreach (PathOD pOD in betweenPaths) { AddPath(pOD.origin, pOD.destination, false); } } }