Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem you will implement Dijkstra's algorithm to find shortest paths between pairs of cities on a map. We are providing a GUI

 

In this problem you will implement Dijkstra's algorithm to find shortest paths between pairs of cities on a map. We are providing a GUI that lets you visualize the map and the path your algorithm finds between two cities. Before you start: Examine the Codio directory. You will find the file cityxy.txt which contains a list of cities and their (X,Y) coordinates on the map. These are the vertices in the graph. The file citypairs.txt lists direct, connections between pairs of cities. These links are bidirectional, if you can go from NewYork to Boston, you can go from Boston to NewYork. These are the edges of the graph. Compile all Java sources and run the program Display. At this point, click on the "Box URL" button along the Codio tool bar at the top of your screen. If you don't see "Box URL" along the toolbar. instead click on the little arrow next to "Project Index (static)" and from there you can select the "Box URL" option. From that point on you'll have the "Box URL" button on your tool bar. This should bring up a view of the computer's actual desktop screen. Inside, a window will have appeared with your running program that displays the map. You will notice that clicking on "Compute All Euclidean Distances does nothing and that "Draw Dijkstra's Path" will throw a null pointer exception on the terminal tab. You will have to implement these methods yourself. You can switch between this Virtual Desktop tab and any of your other tabs freely. Make sure you quit the Java program before running it again. You can do this by either clicking the small x at the top of the java application in the virtual desktop window or by ctri^cing the program from terminal. Carefully read through the classes Vertex.java and Edge.java, which represent the vertices and edges of a graph. You will not have to modify these classes for the assignment, but you need to understand how the graph is represented and what information is associated with each vertex and edge. You will only have to modify Dijkstra.java, which represents a graph and will contain your implementation of Dijkstra's algorithm. You will need to use the instance variable vertexNames, which contains a mapping from city names to Vertex objects after the graph is read from the data files. The main method of Dijkstra illustrates how the class is used by the GUI and might be useful for testing your implementation on the command line. Implement the method computeAllEuclideanDistances () which should compute the euclidean distance between all cities that have a direct link and set the weights for the corresponding edges in the graph. Once this works correctly, the correct distances should be displayed in the GUI when clicking on "Compute All Euclidean Distances". 11 In the method dobijkstra (String s), implement Dijkstra's algorithm starting at the city with name s. Use the distances associated with the edges. The method should update the distance and prev instance variables of the Vertex objects. You should not use a priority queue to store vertices that still need to be visited. Instead, keep these vertices on a List and scan through the entire list to find the minimum. We are making this simplification (at the expense of runtime) because java.util. PriorityQueue does not support the decreasekey operation. Implement the method getDijkstraPath(String s, String t), which uses the distance and prev instance variables of the Vertex objects to find the shortest path betweens and t. This method should be called only after dodijkstra (String s) has been called with the start city. The resulting path should be returned as a list of Edge objects. Once this works correctly. you should be able to compute and display paths in the GUI. Note: Your program must work for repeated runs of dijkstra's algorithms on different city pairs. To make sure that your program does this, be sure that you reinitialize the bookkeeping fields (known, prev, and distance ) in the vertices stored in vertexNames at the beginning of each run of doDijkstra.

Step by Step Solution

3.54 Rating (158 Votes )

There are 3 Steps involved in it

Step: 1

To implement Dijkstras algorithm to find shortest paths between pairs of cities on a map we can follow these steps 1 Compute all Euclidean distances b... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Networking A Top-Down Approach

Authors: James F. Kurose, Keith W. Ross

5th edition

136079679, 978-0136079675

More Books

Students also viewed these Programming questions