Question: use only java file Setting up -Create a class called ConnectedCitiesGraph. Add a method static Graph getRandomCities(int n) which creates a randomly weighted undirected graph
use only java file
Setting up -Create a class called ConnectedCitiesGraph. Add a method static Graph getRandomCities(int n) which creates a randomly weighted undirected graph with n vertices (minimum 5, maximum 20). The graph should contain every possible edge, and each edge should have a randomly chosen double weight between 1 and 10 inclusive. You can create 20 cities but not all cities need to be in the Graph (based on the chosen n). add Total edge weight - Add a method double getTotalEdgeWeight (Graph g) which returns the total weight of the edges in g. The method should work correctly for both directed and undirected graphs.
add Connectivity - Write a method static boolean pathExists (int source, int destination) which determines whether the given source city can reach a destination city. Use breadth-first search mark the vertices that have been visited and, at the end of the search, display the vertices that have been visited in the BFS order. You should avoid adding any vertex to the queue more than once. add Shortest Path - Write a method static void getShortestPath (int source, int destination, int numEdges)which will find the shortest path from source to destination in at most numEdges. If there is such a path, list the path and show the cost of traveling. If the no path exists, print there is no such path.
finally a test code 1 - Compute the total weight of the graph, using the s u p p l i e d class GraphOfUOE. 2 - Create 20 random graphs with 10 to 20 vertices each, created with getRandomCities(). Compute the shortest distance from source to destination (source being the 1st city and destination being the last city. Eg. If there are 10 cities generated, then the source is the 1st city and the destination is the 10th city)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
