Design and implement Java classes for representing and manipulating directed multigraphs. A (multi)graph is determined by whether it is directed or undirected, by the number of its nodes/vertices, and by the (multi)set of its (possibly weighted) edges. For this assignment, we only consider directed multigraphs and the number of nodes are determined when the graph is instantiated, and do not change during the lifetime of the graph. The nodes of the graph are labeled by integers 0,1,..,(n-1), where n is the number of nodes. The set of edges of a graph is not fixed. Initially, a graph contains no edges at all. A graph implementation should support methods for inserting and removing (weighted) edges. Multiple edges from the same source to the same target node are allowed.
You should implement (parts of) two different representations: one that uses an adjacency matrix to store edges, and one that uses adjacency lists.
Implement a Java method that implements
Dijkstra's single-source shortest path algorithm
of a given directed multigraph using a priority queue.
Your algorithm should be very similar to that described
on page 595 of your CLRS textbook.
The priority queue data structure you should use is the one
you implemented in Assignment 1,
namely your TernaryHeap
class.
We are providing you a binary (i.e. class file) of a working
implementation of the TernaryHeap
class
in case there were problems with your solution. Remember
that this class needs the PriorityComparator
interface,
so put a copy of PriorityComparator.class
in your working
directory (this is just the file
PriorityComparator.java
compiled from Assignment 1).
To mark your assignment, we will test your code using
our own secret tester routine.
Successfully running the GraphTester
class we provide does not guarantee that your code is
correct or will pass our marking tester routine.
You are encouraged to derive your own test cases.
Your code may be tested with an auto-marker routine and/or by TA
inspection to check that your routines are implemented correctly.
Note that you will be extending your solution for this assignment for Assignment 4, so it will be beneficial to follow good programming practices.
For more details, including exact specifications of the
methods that you should implement, see the starter code. All of your
work must be done inside the AdjMatrixGraph
,
AdjListsGraph
and Dijkstra
classes,
where indicated by comments that start with: "// TODO:
".
You may also add appropriate private instance variables or helper
methods.
Starter code:
Node.java
Dijkstra.java
TernaryHeap.class
(binary class for your priority queue)
GraphTester.java
Submission Instructions
AdjMatrixGraph.java
,
AdjListsGraph.java
and Dijkstra.java
(after you have implemented the missing parts) to the directory called
PGM3.
All the code that you implement should be inside these files.