コンテンツにスキップ

ワーシャル–フロイド法

出典: フリー百科事典『ウィキペディア(Wikipedia)』
最短経路問題 > ワーシャル–フロイド法

: FloydWarshall Algorithm2

概要

[編集]

ワーシャル–フロイド法の概略は以下の通りである:

  • 入力:
    • (有向または無向)グラフ
    • の各辺の長さ
  • 出力:頂点 と頂点 を結ぶ最短経路を全ての に対して出力
  • 計算量:

アイデア

[編集]

  

            ( )                

 :  

 : 

      

     

       

   .

   

    

擬似コード

[編集]

    
グラフ  および各辺  の長さ length(e) を入力として受け取る。

// 初期化
for each i  {1,...,n}
    for each j  {1,...,n}
        di,j ← i と j を結ぶ辺 e があれば length(e) なければ 無限大

// 本計算
for each k  {1,...,n}
    for each i  {1,...,n}
        for each j  {1,...,n}
            if (di,j > di,k + dk,j)
                di,j ← di,k + dk,j

メモリ管理

[編集]

        ()      

              -    (     )

応用と一般化

[編集]

:

1

使(AND)使(OR)使



Gauss-Jordan elimination

2

実装例

[編集]

参考文献

[編集]
  • Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L. (1990年). Introduction to Algorithms (first edition ed.). MIT Press and McGraw-Hill. ISBN 0-262-03141-8 
    • Section 26.2, "The Floyd-Warshall algorithm", pp. 558–565;
    • Section 26.4, "A general framework for solving path problems in directed graphs", pp. 570–576.
  • Floyd, Robert W. (1962年6月). “Algorithm 97: Shortest Path”. Communications of the ACM 5 (6): 345. doi:10.1145/367766.368168. 
  • Kleene, S. C. (1956年). “Representation of events in nerve nets and finite automata”. In C. E. Shannon and J. McCarthy. Automata Studies. Princeton University Press. pp. pp. 3–42 
  • Warshall, Stephen (1962年1月). “A theorem on Boolean matrices”. Journal of the ACM 9 (1): 11–12. doi:10.1145/321105.321107. 

外部リンク

[編集]