The goal of this lab is to do tasks related to the topological sorting. Use the files that you already modified for Dijkstra’s Algorithm lab.
In Graph.java
class, the acyclic method computes the shortest weighted paths using the topological ordering.
Before you start the lab use the Topological Sort(DFS) Visualization program from the University of San Francisco to confirm your understanding of the algorithm.
Read the acyclic
method so you understand the algorithm.
If you find errors, warnings, or identify places that could use improvements, fix the code.
The critical path between two vertices in a weighted directed acyclic graph is the path with the greatest sum of edge weights. In this graph, each vertex has a value equal to the sum of the edge weights of a path from a given start vertex to that vertex.
Graph.java
, define a method, called criticalPath
, to compute the longest paths from a start vertex to the other vertices on the acyclic graphs and will return the vertex name with the longest path.
Use the body of the acyclic
method to compute the longestPath
that will be used in criticalPath
. Create the longestPath
method then update the code as needed.
indegree
value of the vertices.processRequest
method by asking users to enter a name for the algorithm that you implement for criticalPath
. Note: Remember, when testing your program, it is not necessary to enter a destination node, criticalPath
method will return the destination node/vertex.criticalPath
by finding the longest paths for the following weighted directed graph. Assume that A is a start vertex. Confirm that the critical path from A to I is 19.For your lab write up, include:
Graph.java
and a screenshot of the outcome after running your program.Remember: Do not use magic numbers, write your code anticipating errors and print user-friendly error messages, all your public methods should be well documented (use Javadoc comments). Please include comments or organize your code and report in a way that will help the grader to find the answer to the exercises or posted questions.
(1 extra point) The topological sorting algorithm adds a vertex to a queue when there is not an incoming edge to the vertex. (That is, the vertex indegree is zero.) Now, suppose that the topological sorting adds a vertex to the queue when there is not an outgoing edge from that vertex (You may need to update Vertex
and Edge
to keep track of outgoing edges).
Write the method topologicalOrdering
that displays the topological ordering of vertices in a graph using outdegree instead of indegree of vertices.
Test your method for the graph shown above.
Graph.java
to test the topologicalOrdering
method and the console screenshot after running your program.Graph.java
file must include the topologicalOrdering
method.