Johnson 全源最短路公理库Johnson 全源最短路算法Johnson's algorithm · Johnson all-pairs shortest paths以 Bellman–Ford 势函数把无负环图重赋为非负边权,再重复 Dijkstra 求稀疏图全源最短路。用 Bellman–Ford 生成可行势并检测全图负圈,再在非负重赋权图上逐源运行 Dijkstra。Floyd–Warshall公理库Floyd–Warshall 算法Floyd–Warshall algorithm以允许的中间顶点集合为阶段计算全部顶点对最短路。则按允许的中间顶点做稠密矩阵动态规划;二者的输入表示和复杂度优势区间不同。
参考资料
Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein, Introduction to Algorithms, 4th ed., MIT Press, 2022,§22.1, Bellman–Ford and negative-weight cycles。
Jon Kleinberg and Éva Tardos, Algorithm Design, Pearson, 2005,§6.8, shortest paths with negative edge costs。
Richard Bellman, “On a Routing Problem,” Quarterly of Applied Mathematics 16(1), 1958, pp. 87–90。