Assignment 13 -- Due Friday, December 16
CS 4521 Fall Semester, 2005
15 Points

Topics: The Floyd-Warshall algorithm

The assignment consists of implementing the Floyd-Warshall all-pairs shortest-paths algorithm.

The Floyd-Warshall algorithm

Implement a version of the Floyd-Warshall algorithm that also computes the predecessor matrix PI. This can be done by iteratively computing the PI(k) matrices along with the D(k) matrices. The intialization for PI(0) is given in Equation (25.6) on page 632; the general case is given in Equation (25.7).

As indicated by Exercise 25.2-4 on pages 634-635, you can simplify the algorithm by omitting all the dependencies on k when computing D. I am pretty sure that this also works for computing PI (please let me know if this is wrong). You can use the values 99 and 0 for "infinity" and "NIL" respectively.

Your program should read in n, the number of vertices, and then the n-by-n matrix of weights W (actually, you can read the weights directly into the matrix D).

Run your implementation of the Floyd-Warshall algorithm on each of the following graphs:

  1. The graph of Figure 24.2 on page 585. As in the previous assignment relabel the vertices as 1, 2, 3, 4, 5 instead of using the letters s, t, x, y, z respectively.
  2. The graph of Figure 24.6 on page 596. As in the previous test relabel the vertices as 1, 2, 3, 4, 5 instead of using the letters s, t, x, y, z respectively.
  3. The graph of Figure 25.2 on page 627 (which already has numbered vertices, and so doesn't need relabeling).

For each of the tests, have your program print out the matrices D and PI initially and at the end of each iteration of the outer k-loop, as is done in Figure 25.4 on page 631 for the graph of Figure 25.1 (this is actually the hardest part). The format can be as shown in Figure 25.4 with PI(k) printed to the right of D(k), or PI(k) can be printed below D(k) as:

D(0)
PI(0)
D(1)
PI(1)
D(2)
PI(2)
  .
  .
  .
D(n)
PI(n)
Also, at the end of each test run, use the values in PI(n) to draw the n shortest paths trees rooted at each of the vertices.

Page URL: http://www.d.umn.edu /~ddunham/cs4521f05/assignments/a13/assignment.html
Page Author: Doug Dunham
Last Modified: Tuesday, 03-Jan-2006 17:49:12 CST
Comments to: ddunham@d.umn.edu