Skip to content

Floyd Warshall All Path Shortest Path

Andrey Vernigora edited this page Feb 4, 2019 · 4 revisions

Floyd Warshall All Path Shortest Path

The Floyd Warshall All Path Shortest Path finds all the shortest path in a weighted, directed path. It can also be used to detect negative cycles.

var g = ... ; // some graph of TVertex, TEdge
var weights = ... ; // a function that maps TEdge -> double
var fw = new FloydWarshallAllShortestPathAlgorithm<TVertex, TEdge>(g, weights);

// compute
fw.Compute();

// get interesting paths,
foreach(var source in g.Vertices)
    foreach(var target in g.Vertices)
    {
        IEnumerable<TEdge> path;
        if(fw.TryGetPath(source, target, out path)
            foreach(var edge in path)
                Console.WriteLine(edge);
    }
Clone this wiki locally