In this part you must implement a Breadth First Search of a weighted (di)graph G which finds the minimum weight path between two vertices. Such an algorithm is given in the Algorithms Handout. This algorithm will have to be modified to deal with weighted edges.
The input will be a weighted digraph. (See the preamble for information on how the graph should be input and its format.)
The function read_graph actually reads two integers from the end of the input file, if they exist. These two integers are stored as the variables source and sink defined in graphio.h.
If there are no integers at the end of the input file, the default is the first vertex (0) for the source and the last vertex (n-1) for the sink. If only one integer is given it is assumed to be the source.
|
|
|
| ||||||||||||||||||||
source = 2, sink = 1 | source = 0, sink = 1 | source = 2, sink = 0 | source = 0, sink = 2 |
Your routine should find a minimum weight path from source to sink.
write_graph(path, file_out, n)
where path is the adjacency matrix of your minimum weight path from source to sink.
A return value of 0 indicates that there is no source sink path. In this case no output should be produced.
Maintained by: P. Danziger, March 2008