首页 > 代码库 > Dijkstra链路状态选路算法

Dijkstra链路状态选路算法

 

步骤N1D(v),p(v)D(w),p(w)D(x),p(x)D(y),p(y)D(z),p(z)
0u2,u5,u1,u无穷大无穷大
1ux2,u4,x 2,x无穷大
2uxy2,u3,y  4,y
3uxyv 3,y  4,y
4uxyvw    4,y
5uxyvwz     

 

D(o):随着算法进行本次迭代,从源节点到目的节点o的最低费用路径的费用。

p(o):从源节点到目的节点o沿着当前最低费用路径的前一节点(o的邻居)。

N1:节点子集,如果从源节点到目的节点o的最低费用路径已确知,o在N1中。

LS算法:

Initialization:

  N1 = {u}

  for all node o

    if o is a neighbor of u

      then D(o) = c(u,o)

    else D(v) = 无穷大

Loop

  find w not in N1 such that D(w) is a minium

  add w to N1

  update D(o) for each neighbor o of w  and not in N1:

      D(o) = min(D(o), D(o) + c(w,o))

/* new cost to o is either old cost to o or known  least path cost to w plus cost from w to o*/

until N1 = N

 

Dijkstra链路状态选路算法