@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
30 lines • 1.66 kB
TypeScript
/**
* Produce a distance matrix from an input graph, tracing distances from each
* node to every node specified in the target vector.
*
* Traversal is BFS and each neighbour is only visited once. As a consequence
* this implementation gives correct shortest-path distances only when every
* edge has the same weight (typically `edge.weight === 1`). On graphs with
* heterogeneous weights the returned distances are the weight sum along the
* BFS tree, which is not the shortest-path distance in general — use
* Dijkstra or Floyd–Warshall for those cases instead.
*
* Edge costs are read from `edge.weight`, so uniform non-1 weights still
* produce distances scaled by the common weight, but this remains correct
* only because every path of the same hop count has the same total weight.
*
* Output layout: `m[row, col]` is the distance from the node at index `row`
* to the target node at index `col`. Columns whose index is not in `targets`
* are left at `POSITIVE_INFINITY` (except the diagonal, which is 0).
*
* @see "A Fast Algorithm to Find All-Pairs Shortest Paths in Complex Networks" by Wei Peng et Al. 2012
* @template T
* @param {Graph<T>} graph
* @param {T[]} node_array graph nodes as an array
* @param {number[]} targets node indices, distances to which need to be calculated
* @param {Map<T, number>} node_index_map
* @returns {SquareMatrix}
*/
export function graph_compute_distance_matrix<T>(graph: Graph<T>, node_array: T[], targets: number[], node_index_map: Map<T, number>): SquareMatrix;
import { SquareMatrix } from "../math/matrix/SquareMatrix.js";
//# sourceMappingURL=graph_compute_distance_matrix.d.ts.map