コンテンツにスキップ

ベルマン–フォード法

出典: フリー百科事典『ウィキペディア(Wikipedia)』
最短経路問題 > ベルマン–フォード法

 (: BellmanFord algorithm) [1]使E Lester Ford, Jr. 

(negative cycle) -

[2]G NPG 

アルゴリズム

[編集]

 |V||V|  1 relaxing=1

 O(|V|·|E|) |V||E|
procedure BellmanFord(list vertices, list edges, vertex source)
   // この実装では、グラフを頂点のリストと辺のリストで表す。
   // そして、各頂点の distancepredecessor 属性が
   // 最短経路を格納するよう変更していく。

   // Step 1: グラフの初期化
   for each vertex v in vertices:
       if v is source then v.distance := 0
       else v.distance := infinity
       v.predecessor := null
   
   // Step 2: 辺の緩和を反復
   for i from 1 to size(vertices) - 1:       
       for each edge uv in edges: // uv は u から v に向かう辺
           u := uv.source
           v := uv.destination             
           if v.distance > u.distance + uv.weight:
               v.distance := u.distance + uv.weight
               v.predecessor := u

   // Step 3: 負の重みの閉路がないかチェック
   for each edge uv in edges:
       u := uv.source
       v := uv.destination
       if u.distance + uv.weight < v.distance:
           error "Graph contains a negative-weight cycle"

正しさの証明

[編集]



: for  i:

Distance(u)  s u

 i s uDistance(u)  i s u

: i=0  for  source.distance = 0  u u.distance = infinity 0 u

1 v.distance := u.distance + uv.weight u.distance  u u.distance + uv.weight  u v v

2 i uv   u v i-1  vi-1  v.distance uv.weight + v.distance  s ui-u.distance  uv.weight + v.distance uv.weight + v.distance i u.distance  u i

1 step 3  v[0],..,v[k-1] 

v[i].distance <= v[i-1 (mod k)].distance + v[i-1 (mod k)]v[i].weight

v[i].distance  v[i-1 (mod k)].distance 

 0 <= v[i-1 (mod k)]v[i].weight 1k


応用

[編集]

-Routing Information Protocol (RIP) 使ISPIP (AS) 

(一)AS

(二)

(三)

-






Yenによる改良

[編集]

1970Yen-[3]Yen21Ef  i <j (vi, vj) 2Eb  i >j (vi, vj) v1, v2,...,v|V| Ef v|V|, v|V|-1,...,v1 Eb Yen調

脚注・出典

[編集]
  1. ^ Dimitri P. Bertsekas (1992年3月). “A Simple and Fast Label Correcting Algorithm for Shortest Paths” (PDF). Networks, Vol. 23, pp. 703–709, 1993. 2008年10月1日閲覧。
  2. ^ Robert Sedgewick. Algorithms in Java. Third Edition. ISBN 0-201-36121-3. Section 21.7: Negative Edge Weights. http://safari.oreilly.com/0201361213/ch21lev1sec7
  3. ^ Jin Y. Yen. "An algorithm for Finding Shortest Routes from all Source Nodes to a Given Destination in General Network", Quart. Appl. Math., 27, 1970, 526–530.

参考文献

[編集]
  • Richard Bellman: On a Routing Problem, in Quarterly of Applied Mathematics, 16(1), pp.87-90, 1958.
  • L. R. Ford, Jr., D. R. Fulkerson: Flows in Networks, Princeton University Press, 1962.
  • Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Section 24.1: The Bellman-Ford algorithm, pp.588–592. Problem 24-1, pp.614–615.

外部リンク

[編集]