(Latest Revision: 04/11/2004)

Pathways of the West: A Program That Computes Shortest Paths


PRELIMINARIES:

Before working on this problem you need to understand the basics of programming graph algorithms. Read chapter thirteen of "Walls and Mirrors" by Carranao and Prichard. You also need to be familiar with the directions and examples here: http://www.cs.csustan.edu/~john/Classes/General_Info/progAsgRules/


THE ASSIGNMENT:

Write a program that inputs a source node, a list of nodes, and a list of edges and outputs a table showing the shortest path from the source to every other node.


INPUT:

The program reads from standard input. Inputs have a form like this sample. The first item of input tells how many nodes there are. The second item tells you the name of the source node. Then comes the list of names of all the nodes of a connected graph. The number of names of nodes agrees with the first item in the input. For example, the sample starts with "65" and "SanFranciscoCA" and next comes a list of 65 city names. (Note that SanFranciscoCA is one of the 65. The node list contains the names of all the nodes.) The last part of the output is a list of the weighted edges of the graph. Each edge is represented by two names and a weight. The edge represents a highway route between two destinations. The names given are the destinations and the weight represents the mileage between the destinations.

(In the sample input, the cities and edges appear in alphabetical order. That is just coincidental. There is no requirement that the list of nodes or the list of edges be in any particular order.)


OUTPUT:

The program writes to standard output. First it writes a table heading and then a table that contains in its columns: the name of each destination city (all cities are destinations except the source city), the length of the shortest path in the graph from the source to the destination, and the name of the starting point of the last edge in the shortest path.

For example, this sample output contains the line:

AstoriaOR                         742                NewportOR
which means that the shortest path in the graph from SanFranciscoCA to AstoriaOR has length 742, and that shortest path goes to NewportOR just before ending up in AstoriaOR.


DISCUSSION OF PROCESSING:

You can use Dijkstra's algorithm to compute the shortest paths and "back pointers." There is a description of the algorithm here.


TESTING:

You can test with the large sample I gave you, but you should also generate a small sample input to test with as you develop the program. I think this will make it easier to debug.


WHAT TO TURN IN:

I am not going to ask you to turn in any preliminary levels of this program.

You will turn in one printer output (hardcopy) and you will send me one e-mail message. Please follow these rules: Here is the list of things you have to turn in: Note that there are no spaces in the subject lines given. It is important that you do not insert any spaces. My e-mail address is: john@ishi.csustan.edu.


DUE DATES:

For the due dates, see the class schedule.


Historical Note: The algorithm for computing "single source, all nodes, shortest paths" that we discussed was invented by Edsger Dijkstra. Dijkstra did much of the important pioneering work in the field of computer science. He passed away during the summer of 2002.