(Latest Revision: 05/05/2003)

Pathways of the West: A Program That Computes Shortest Paths


PRELIMINARIES:

Before working on this problem you need to know how 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 all the 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 then next comes a list of 65 city names. (Note that SanFranciscoCA is one of the 65. The node list contains the name 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 names of the cities and edges appear in alphabetical order. That is just coincidental. There is no requirement that the list of nodes or edges be in alphabetical 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:

You will turn in your assignment by e-mail. With regard to the e-mail please follow these rules: Send the following items to me by e-mail before midnight on the due date:

A final version of the source code and a script showing your test runs. Include all the source files (*.h files and *.cpp files) that are required to compile the program into an executable image -- everything I need so that I can compile and test your program. Combine all the source files and the script into one shell archive file and e-mail me the archive file with the subject line: CS3100,prog5.f.

Note that there are no spaces in the subject line 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.