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.
As with the previous project, you'll
need Heap
and HeapPriorityQueue
from the heap project,
and OptimizedHeapPriorityQueue
is provided again.
Make sure you
verify the tests test.HeapTest
,
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
.
Note that the test tooBigForBF
will timeout if you write an implementation that isn't
as efficient as Dijkstra should be.
Since running time differs per machine, make sure that if you're doing
this project on your own computer that you also test this on the lab
machines, since the given time limit is based on running times in
the cs lab.
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
,
and OptimizedDijkstraSSSP
to your turn-in folder
/cslab/class/cs345/(your id)/sssp
.
To keep up with the course, this should be finished by Feb 19.