Project: Single-source shortest paths

1. Introduction

The goal of this project is to implement the two major algorithms to compute a set of single-source shortest paths for weighted graphs: the Bellman-Ford Algorithm and Dijkstra's Algorithm. You will also compare them using a simple experiment.

This is a companion project to the MST project and is very similar in structure and goals. Accordingly, the project description will be spare: The given code will be familiar from the previous project, and all you'll need to do is implement the core parts of the two algorithms.

2. Setup

Copy the give code from ~tvandrun/Public/cs345/sssp and make an Eclipse project for it. As with the MST project, you will find five packages: in addition to adt, impl, and test, which have their usual purpose, we also have alg for (externally implemented) algorithms over graphs and exper for an experiment.

Re-familiarize yourself with the structure of the various classes and interfaces and packages as necessary. Specifically understand how the two SSSP algorithms are encapsulated in classes that implement the SSSP interface.

We'll need Heap, HeapPriorityQueue, and OptimizedHeapPriorityQueue from the previous project. I have provided the same given code for those classes as in the previous project. You should be safe copying over the whole files from your (completed) previous project, but make sure you verify the tests test.HeapifyTest, HPQTest, and OptimizedHeapPriorityQueueTest pass as a sanity check.

3. The Bellman-Ford algorithm

Finish the method alg.BellmanFordSSSP.sssp(). The code for setting up the data structures is given to you. Specifically,

Note also that the sssp() method is to return its result as a set of edges. The code you write, however, will represent that information in the parents array---that is, the information about nodes' parents indicates the structure of the tree. I have provided the code that builds the equivalent set of edges from the parents array.

Test this using BFSSSPTest.

4. Dijkstra's algorithm

Now consider Dijkstra's algorithm in alg.DijkstraSSSP.sssp(). Finish this code. There are two differences in the given code between this and Bellman-Ford. First, the distance bounds are no longer represented by doubles but with instances of the class VertexRecord. This is so they can be put in a priority queue, which I also have provided. Similarly to the given code for Bellman-Ford, I have provided code to convert the information in the parents array to a set of edges.

Test this using DSSSPTest.

5. Optimizing Dijkstra's algorithm

But just as in Prim's algorithm in the previous project, the heap-based priority queue incurs linear expense for the increaseKey() method, since that requires searching the heap for the key that has changed. Let's optimize Dijkstra by using heap-position-aware vertex records and OptimizedHeapPriorityQueue. Finish OptimizedDijkstraSSSP.sssp() and test using ODSSSPTest.

6. Experiments

Now read expr.SSSPExperiment and consider the experiment it performs. Run it---and feel free to improve or otherwise modify it---and observe its results.

7. Turn in

Copy the files you modified (Heap, HeapPriorityQueue, BellmanFordSSSP, DijkstraSSSP, OptimizedHeapPriorityQueue, and OptimizedDijkstraSSSP to your turn-in folder /cslab.all/linux/class/cs345/(your id)/sssp .

To keep up with the course, this should be finished by Feb 17.


Thomas VanDrunen
Last modified: Fri Feb 12 10:31:03 CST 2016