<< NL_R_FloodRT NL_R: Routing NL_R_FloydWarshallPath >>

NARVAL >> NL_R: Routing > NL_R_FloydWarshall

NL_R_FloydWarshall

Perform the shortest paths between all pairs of vertices of a graph in respect with the Floyd-Warshall algorithm.

Calling Sequence

[P,N] = NL_R_FloydWarshall(G)

Arguments

G :

Graph.

P :

Matrix of the path length between two network nodes.

N :

Matrix of successor nodes.

Description

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.

Pseudo-Code (Wikipedia)

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..k1).  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] );

Examples

[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)

Report an issue
<< NL_R_FloodRT NL_R: Routing NL_R_FloydWarshallPath >>