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 interresting 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);
    }

Last edited Dec 4, 2008 at 8:10 AM by pelikhan, version 3

Comments

ido_ran Sep 4, 2012 at 10:30 AM 
I think it's bad to use var on examples because it makes it hard to understand what the actual types are.