function floydWarshall(g, weightFunc, incidentFunc) {
  var results = {},
      nodes = g.nodes();

  weightFunc = weightFunc || function() { return 1; };
  incidentFunc = incidentFunc || (g.isDirected()
      ? function(u) { return g.outEdges(u); }
      : function(u) { return g.incidentEdges(u); });

  nodes.forEach(function(u) {
    results[u] = {};
    results[u][u] = { distance: 0 };
    nodes.forEach(function(v) {
      if (u !== v) {
        results[u][v] = { distance: Number.POSITIVE_INFINITY };
      }
    });
    incidentFunc(u).forEach(function(e) {
      var incidentNodes = g.incidentNodes(e),
          v = incidentNodes[0] !== u ? incidentNodes[0] : incidentNodes[1],
          d = weightFunc(e);
      if (d < results[u][v].distance) {
        results[u][v] = { distance: d, predecessor: u };
      }
    });
  });

  nodes.forEach(function(k) {
    var rowK = results[k];
    nodes.forEach(function(i) {
      var rowI = results[i];
      nodes.forEach(function(j) {
        var ik = rowI[k];
        var kj = rowK[j];
        var ij = rowI[j];
        var altDistance = ik.distance + kj.distance;
        if (altDistance < ij.distance) {
          ij.distance = altDistance;
          ij.predecessor = kj.predecessor;
        }
      });
    });
  });

  return results;
}
This function is an implementation of the [Floyd-Warshall algorithm][],
which finds the shortest path from each node to every other reachable node
in the graph. It is similar to [alg.dijkstraAll][], but it handles negative
edge weights and is more efficient for some types of graphs. This function
returns a map of `source -> { target -> { distance, predecessor }`. The
distance property holds the sum of the weights from `source` to `target`
along the shortest path of `Number.POSITIVE_INFINITY` if there is no path
from `source`. The predecessor property can be used to walk the individual
elements of the path from `source` to `target` in reverse order.

This function takes an optional `weightFunc(e)` which returns the
weight of the edge `e`. If no weightFunc is supplied then each edge is
assumed to have a weight of 1.

This function takes an optional `incidentFunc(u)` which returns the ids of
all edges incident to the node `u` for the purposes of shortest path
traversal. By default this function uses the `outEdges` function on the
supplied graph.

This algorithm takes O(|V|^3) time.

[Floyd-Warshall algorithm]: https://en.wikipedia.org/wiki/Floyd-Warshall_algorithm
[alg.dijkstraAll]: dijkstraAll.js.html#dijkstraAll

@param {Graph} g the graph to search for shortest paths from **source**
@param {Function} [weightFunc] optional weight function
@param {Function} [incidentFunc] optional incident function