Floyd-Warshall Algorithm

Author

Eric W. Weisstein
March 30, 2008

This notebook downloaded from http://mathworld.wolfram.com/notebooks/GraphTheory/Floyd-WarshallAlgorithm.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/Floyd-WarshallAlgorithm.html.

©2008 Wolfram Research, Inc. except for portions noted otherwise

Initialization

?AllPairsShortestPath*

?WeightingFunction

g2=DeleteEdges[SetEdgeWeights[MakeDirected[CompleteGraph[4]],WeightingFunction->(First[#1+#2]&)],{{1,3},{3,1},{2,1},{4,2},{3,2},{4,3}}]

Edges[g2]

Edges[g2,All]

g3=SetEdgeLabels[g2,GetEdgeWeights[g2]]

ShowLabeledGraph[g3,EdgeLabel->True]

AllPairsShortestPath[g3]//TraditionalForm

ShowGraph[Highlight[g3,{{{1,2},{2,3}}}]]

ShortestPath[g3,3,1]