I have been researching Graph theory and Dijsktra's only to find myself with too many ways to go about this, and I'm not sure which to apply to this specific problem. Here are the requirements:
In centralized routing, all the routing information is generated and maintained in a centralized location. A common way of maintaining routing information centrally is via a routing matrix. A routing matrix has a row and a column for each node in the network, where a row corresponds to the source node and a column corresponds to the destination node. The entry in row i column j is a pair (x , y), where x is the first node on the shortest path from i to j, and y is the cost of the shortest path from i to j.
Write a program that reads a weighted graph representing a network, and finds and outputs the corresponding routing matrix. The routing matrix will be written both to the screen and to an output file. Use Dijkstra’s algorithm to find the shortest cost and path between nodes. The program runs from the command line with two optional command line arguments. Use the following command line options to indicate the presence of a command line argument: -i (for input file name) and –o (for output file name). If no command line arguments are present, the program uses “xy_input.txt” and “xy_output.txt” as default input and output file names respectively. See examples below:
- java xy_rmatrix
- java xy_rmatrix –i xy_rmatrixi.txt –o xy-rmatrixo.txt
Sample Input/Output: The input file contains zero or more lines representing a graph of a network. Each line represents a bi-directional edge that is made up of two vertices (routers) and the cost associated with the link (communication line) between them. One or more whitespaces (blank, tab, etc.) will separate data on each line and the node names might be a string rather than a single character. Note that the routing matrix rows and columns are listed in alphabetical order.
Input:
Output:
My main question is, for this particular problem is it necessary to store the contents of the input file in its own data structure such as a graph or adjacency list, and how would I go about implementing these in Java with vertices/nodes and edges in a way that I can perform Dijsktra's Algorithm?
Am I also correct to assume that the routing matrix specified is synonymous with an adjacency matrix?
Note: I am not fishing for code, just a step in the right direction.
I think in your case, the routing matrix could be represented by a two-dimensional array. Dijkstra's algorithm finds the shortest path from one source to any destination. You can use 'A' as the source first, and then 'B', and so on to get the routing matrix from each point to every other point, as required. You could use adjacency-lists or arrays again to represent the graph information in order to perform dijkstra from each source.
Hope this helps!