0

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:

https://i.stack.imgur.com/08zpC.png

Output:

enter image description here

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.

4

1 回答 1

0

我认为在您的情况下,路由矩阵可以用二维数组表示。Dijkstra 算法找到从一个源到任何目的地的最短路径。您可以根据需要先使用“A”作为源,然后使用“B”,依此类推,以获取从每个点到每个其他点的路由矩阵。您可以再次使用邻接列表或数组来表示图形信息,以便从每个源执行 dijkstra。

希望这可以帮助!

于 2018-06-18T20:23:45.097 回答