documentationfor yFiles for HTML 3.0.0.3

KShortestPaths

Computes the k shortest paths connecting a pair of nodes in a directed graph with non-negative edge costs.

Inheritance Hierarchy
KShortestPaths

Remarks

This method computes the k shortest paths from the source node to the sink node in a directed graph. The paths are ranked by their total cost, with the first path being the shortest.

The graph must have non-negative edge costs, as provided by the costs mapper.

The results provide a collection of the found Paths.

Examples

Highlighting the k shortest path edges between a start and an end node
// configure the shortest path algorithm
const algorithm = new KShortestPaths()
algorithm.source = startNode
algorithm.sink = endNode
// add edge cost mapping which returns the actual length of the edge
algorithm.costs = (edge) =>
  edge.style.renderer
    .getPathGeometry(edge, edge.style)
    .getPath()!
    .getLength()

// run the algorithm
const result = algorithm.run(graph)

// highlight the edge paths
for (const path of result.paths) {
  for (const edge of path.edges) {
    graph.setStyle(edge, highlightPathStyle)
  }
}

Type Details

yFiles module
view-layout-bridge

Constructors

Properties

Methods