Perform the shortest paths between all pairs of vertices of a graph in respect with the Floyd-Warshall algorithm.
[P,N] = NL_R_FloydWarshall(G)
Graph.
Matrix of the path length between two network nodes.
Matrix of successor nodes.
NL_R_FloydWarshall finds the shortest paths between all pairs of vertices of the graph G composed by n nodes in a single execution (WIKIPEDIA). Routes can be retrieved according to the two matrices of size nxn. P(i,j) provides the total length of the shortest path between the nodes i and j. N(i,j) provides the intermediate node that should be crossed in order to reach the node j from the node i in respect with the shortest path.
1 /* Assume a function edgeCost(i, j) which returns the cost of the edge from i to j 2 (infinity if there is none). 3 Also assume that n is the number of vertices and edgeCost(i,i) = 0 4 */ 5 6 int path[][]; 7 /* A 2-dimensional matrix. At each step in the algorithm, path[i][j] is the shortest path 8 from i to j using intermediate vertices (1..k−1). Each path[i][j] is initialized to 9 edgeCost(i,j) or infinity if there is no edge between i and j. 10 */ 11 12 procedure FloydWarshall () 13 for k := 1 to n 14 for i := 1 to n 15 for j := 1 to n 16 path[i][j] = min ( path[i][j], path[i][k]+path[k][j] ); | ![]() | ![]() |
[path]=NL_F_NLPath();//path to NARVAL module path=path+'/demos/';//folder path load(path+'topo_100.graph');//loading of the network graph load(path+'RoutingTables_topo_100.dat','pt','rt1','rt2','rt3','rt4','rt5');//loading of the network routing tables [Path,Next]=NL_R_FloydWarshall(g);//application of NL_R_FloydWarshall Path(1:10,1:10) Next(1:10,1:10) | ![]() | ![]() |