//startNodeIndex //stopNodeIndex //points //adjacencylist private PriorityQueue Dijkstra(String type) { double maxTime = 0; String whichType = ""; Stopwatch myWatch = new Stopwatch(); PriorityQueue pq = null; if (type == "array") { pq = new ArrayQueue(points.Count); } else if (type == "heap") { pq = new HeapQueue(points.Count); } pq.changeDistance(startNodeIndex, 0); pq.formerIndexes[startNodeIndex] = startNodeIndex; for (int i = 0; i < points.Count - 1; i++) { myWatch.Reset(); myWatch.Start(); int deletedIndex = pq.deleteMinimum(); myWatch.Stop(); //Console.WriteLine("deleteTime: " + myWatch.Elapsed.TotalSeconds.ToString()); if (myWatch.Elapsed.TotalSeconds > maxTime) { maxTime = myWatch.Elapsed.TotalSeconds; whichType = "deleteTime"; } foreach (int neighbor in adjacencyList[deletedIndex]) { double newDistance = distanceAtoB(points[deletedIndex], points[neighbor]) + pq.distances[deletedIndex]; if (newDistance < pq.distances[neighbor]) { myWatch.Reset(); myWatch.Start(); pq.changeDistance(neighbor, newDistance); myWatch.Stop(); //Console.WriteLine("changeDistanceTime: " + myWatch.Elapsed.TotalSeconds.ToString()); if (myWatch.Elapsed.TotalSeconds > maxTime) { maxTime = myWatch.Elapsed.TotalSeconds; whichType = "changeDistanceTime"; } pq.formerIndexes[neighbor] = deletedIndex; } } } //Console.WriteLine("MaxTime: " + whichType + " " + maxTime); return(pq); }
// Creates an HeapQueue and calls Dykstra's with the ArrayQueue Arrays from above. private void runHeapQueue() { HeapQueue queue = new HeapQueue(); Dykstra(queue, g_distanceHQ, g_previousHQ, g_arrayHQ); /* int currIndex = stopNodeIndex; * string path = "Path: "; * while (currIndex != startNodeIndex) * { * if (currIndex < 0) * { * MessageBox.Show(path); * break; * } * path += (currIndex + "-"); * currIndex = g_previousHQ[currIndex]; * if (currIndex == startNodeIndex) * { * path += startNodeIndex; * MessageBox.Show(path); * } * } */ }