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 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
provided in the MinPriorityQueue.jar
classes
(the heap you implemented in Assignment 1 lacks the Update operation
required by Dijkstra).
We have provided the JavaDoc documentation.
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:
NodeElement.java
Dijkstra.java
MinPriorityQueue.jar
(binary classes for your priority queue)
Since we are providing some starter code in the form of a .jar
file, you'll need either to add this file to your classpath (i.e.,
use a command like "javac -cp .:MinPriorityQueue.jar *.java
"
to compile and give the same option to java
to run)
or unpack the .jar using the
"jar xf MinPriorityQueue.jar
" command.
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.