documentationfor yFiles for HTML 2.6

AllPairsShortestPaths

Finds shortest paths between pairs of multiple sources and sinks.

Inheritance Hierarchy
AllPairsShortestPaths

Remarks

The shortest paths will be determined by invoking a single-source shortest path search for each node in sources. For n sources and m sinks the result thus may contain up to nm distinct paths.

Other Shortest Path Algorithms

yFiles for HTML supports a number of other algorithms that compute shortest paths in a graph:

Other Path-Related Algorithms

yFiles for HTML also supports a number of other algorithms related to paths in a graph:

  • Paths – finds all paths between a set of source and a set of target nodes
  • Chains – finds all chains, that is, sequences of nodes that are each connected with just an edge without branches
  • Cycle – finds a cycle if one exists
  • LongestPath – finds the longest path in the graph

Examples

Highlighting the shortest path edges between multiple start and end nodes
// configure the shortest path algorithm
const algorithm = new AllPairsShortestPaths({
  // multiple source and sink nodes
  sources: sourceNodes,
  sinks: targetNodes,
  // add edge cost mapping which returns the actual length of the edge
  costs: (edge) =>
    edge.style.renderer
      .getPathGeometry(edge, edge.style)
      .getPath()
      .getLength()
})
// run the algorithm:
// calculate paths from startNode to all nodes in the graph
const result = algorithm.run(graph)
for (const sourceNode of sourceNodes) {
  for (const targetNode of targetNodes) {
    // and mark the edge path from start to the end node
    for (const edge of result.getPathBetween(sourceNode, targetNode)
      .edges) {
      graph.setStyle(edge, highlightPathStyle)
    }
  }
}// configure the shortest path algorithm
const algorithm = new AllPairsShortestPaths({
  // multiple source and sink nodes
  sources: sourceNodes,
  sinks: targetNodes,
  // add edge cost mapping which returns the actual length of the edge
  costs: (edge) =>
    edge.style.renderer
      .getPathGeometry(edge, edge.style)
      .getPath()!
      .getLength()
})
// run the algorithm:
// calculate paths from startNode to all nodes in the graph
const result = algorithm.run(graph)
for (const sourceNode of sourceNodes) {
  for (const targetNode of targetNodes) {
    // and mark the edge path from start to the end node
    for (const edge of result.getPathBetween(sourceNode, targetNode)!
      .edges) {
      graph.setStyle(edge, highlightPathStyle)
    }
  }
}

Type Details

yfiles module
view-layout-bridge
yfiles-umd modules
view-layout-bridge
Legacy UMD name
yfiles.analysis.AllPairsShortestPaths

See Also

Constructors

Properties

Methods