FloydWarshall Class |
The FloydWarshall class represents a data type for solving the all-pairs shortest paths problem in edge-weighted digraphs with no negative cycles. The edge weights can be positive, negative, or zero. This class finds either a shortest path between every pair of vertices or a negative cycle.
This implementation uses the Floyd-Warshall algorithm. The constructor takes time proportional to V3 in the worst case, where V is the number of vertices. Afterwards, the Dist(), HasPath(), and HasNegativeCycle() methods take constant time; the Path() and GetNegativeCycle() method takes time proportional to the number of edges returned.
Namespace: Algs4Net
public class FloydWarshall
The FloydWarshall type exposes the following members.
Name | Description | |
---|---|---|
![]() | FloydWarshall | Computes a shortest paths tree from each vertex to to every
other vertex in the edge-weighted digraph G. If no such shortest
path exists for some pair of vertices, it computes a negative cycle.
|
Name | Description | |
---|---|---|
![]() | HasNegativeCycle |
Is there a negative cycle? |
Name | Description | |
---|---|---|
![]() | Dist |
Returns the length of a shortest path from vertex s to vertex t. |
![]() | HasPath |
Is there a path from the vertex s to vertex t? |
![]() ![]() | MainTest |
Demo test the FloydWarshall data type. |
![]() | NegativeCycle |
Returns a negative cycle, or null if there is no such cycle. |
![]() | Path |
Returns a shortest path from vertex s to vertex t. |
For additional documentation, see Section 4.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
This class is a C# port from the original Java class FloydWarshall implementation by the respective authors.