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.
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.
Finish the method alg.BellmanFordSSSP.sssp()
.
The code for setting up the data structures is given to you.
Specifically,
distanceBounds
contains vertex satellite data
on the least known upper bound on a vertex's distance from the source.
parents
contains vertex satellite data
on the vertex's parent in the path having the currently least known
upper bound.
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
.
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 double
s
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
.
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
.
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.
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.