(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:
- Always send me e-mail as plain text in the main message body.
Never send me attachments.
- Always use the exact subject line I specify for each
message. (I often get hundreds of e-mail messages in a week. The
subject line allows me to find, filter and sort messages.) You will lose
a significant number of points on the assignment if you use the wrong
subject line.
- Be very careful when you send the e-mail. You may use the
instructions in your
Hello World! lab excercise
for guidance. Of course, you will need to make the obvious changes to
those directions -- you have to use the correct subject line and
filename.
- Always send yourself a copy of each e-mail message you send to me,
and check immediately to see if you receive the message intact.
You are responsible for sending
e-mail correctly.
Here is the list of things you have to turn in:
- At the start of class on the
due date,
place the following item on the "counter" in front of me:
- a hardcopy of your final
level program (all the source code). Make
sure all the code is properly formatted and that it all
shows on the paper.
- Using the subject line: CS3100,prog5.f send the following item
to me by e-mail before midnight on the
due date:
One
shell archive file
(only one) containing items 1-4.
- All source files for your final level
program (everything I will need to compile and run it:
all *.cpp files and *.h files)
- Your test script showing adequate testing of your final level program.
- A file named 'README' containing the compilation command one should
use to compile your program.
- A copy of your 'makefile' if you used one.
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.