@dagrejs/graphlib
Version:
A directed and undirected multi-graph library
23 lines • 1.51 kB
TypeScript
import { Graph } from '../graph';
import type { EdgeFunction, Path, WeightFunction } from '../types';
/**
* 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.
* Complexity: O(|V|^3).
*
* @param graph - graph where to search paths.
* @param weightFn - function which takes edge e and returns the weight of it. If no weightFn
* is supplied then each edge is assumed to have a weight of 1. This function throws an
* Error if any of the traversed edges have a negative edge weight.
* @param edgeFn - function which takes a node v and returns the ids of all edges incident to it
* for the purposes of shortest path traversal. By default this function uses the graph.outEdges.
* @returns shortest paths map.
*/
export declare function floydWarshall(graph: Graph, weightFn?: WeightFunction, edgeFn?: EdgeFunction): Record<string, Record<string, Path>>;
//# sourceMappingURL=floyd-warshall.d.ts.map