<< NL_R_BellmanFord NL_R: Routing NL_R_CongestionMap >>

NARVAL >> NL_R: Routing > NL_R_BellmanFordRT

NL_R_BellmanFordRT

Perform the routing table of a topology in respect with the Bellman-Ford algorithm.

Calling Sequence

[R] = NL_R_BellmanFordRT(G)

Arguments

G :

Graph.

R :

Routing table.

Description

NL_R_BellmanFordRT computes the shortest paths between all couples of distinct network nodes of the graph G in respect with the Bellman-Ford algorithm (WIKIPEDIA). The paths are stored in the routing table matrix R. Thus the route between the nodes i and j can be read at the line of index (i-1)*n+j. The first column of R provides each path length.

Pseudo-Code (Wikipedia)

procedure BellmanFord(list vertices, list edges, vertex source)
   // This implementation takes in a graph, represented as lists of vertices
   // and edges, and modifies the vertices so that their distance and
   // predecessor attributes store the shortest paths.

   // Step 1: Initialize graph
   for each vertex v in vertices:
       if v is source then v.distance := 0
       else v.distance := infinity
       v.predecessor := null
   
   // Step 2: relax edges repeatedly
   for i from 1 to size(vertices)-1:       
       for each edge uv in edges: // uv is the edge from u to v
       u := uv.source
       v := uv.destination             
       if u.distance + uv.weight is inferior to v.distance:
           v.distance := u.distance + uv.weight
           v.predecessor := u

   // Step 3: check for negative-weight cycles
   for each edge uv in edges:
       u := uv.source
       v := uv.destination
       if u.distance + uv.weight is inferior to v.distance:
       error "Graph contains a negative-weight cycle"

Examples

n=80;//network size
l=1000;//network squared area side
d=100;//Locality radius
[g]=NL_T_LocalityConnex(n,l,d);//generation of a topology
ind=1;//window index
f=NL_G_ShowGraphN(g,ind);//graph visualization
[rt]=NL_R_BellmanFordRT(g)//application of NARVAL_R_BellmanFordRT

Dependency

NL_R_BellmanFord, NL_R_PredecessorRoute, NL_F_ReverseVector

Report an issue
<< NL_R_BellmanFord NL_R: Routing NL_R_CongestionMap >>