public List <Edge> CalculateOnePath() { pq = new PQ(points.Count); populateOnePath(startIndex); int currentIndex = pq.PopMin(); currentIndex = CalculateResults(currentIndex); return(CompileResults(currentIndex)); }
public List<Edge> CalculateOnePath() { pq = new PQ(points.Count); populateOnePath(startIndex); int currentIndex = pq.PopMin(); currentIndex = CalculateResults(currentIndex); return CompileResults(currentIndex); }
private int CalculateResults(int currentIndex) { while (!pq.IsEmpty()) { if (currentIndex == endIndex) { break; } foreach (int lookupIndex in adjacencyList[currentIndex]) { double newPathCost = pq.GetPathCost(currentIndex) + GetDistance(points[currentIndex], points[lookupIndex]); double oldPathCost = pq.GetPathCost(lookupIndex); if (oldPathCost == -1) { pq.Add(lookupIndex, newPathCost, currentIndex); } else if (oldPathCost > newPathCost && !pq.NodeIsVisited(lookupIndex)) { pq.DecreaseKey(lookupIndex, newPathCost, currentIndex); } } if (pq.AllPathsIsFinished()) { break; } currentIndex = pq.PopMin(); if (currentIndex == startIndex) { currentIndex = pq.PopMin(); } } return(currentIndex); }