Represents a path between two nodes.
Inheritance Hierarchy

Remarks

The path is defined by an ordered list of edges. The nodes along the path are also provided, but may be ambiguous if there are multi-edges between certain nodes.

This class cannot be instantiated

See Also

Developer's Guide

Members

No filters for this type

Properties

Gets the distance or length of the path.
Some algorithms support edge weights (or costs), which makes the path's distance the sum of all edge weights along the path. If no explicit weights are provided, usually a uniform weight of 1 is assumed, which makes the path's distance merely the number of edges that comprise it.
readonlyfinal

Examples

Single-source single-sink
algorithm.source = startNode
algorithm.sink = endNode
const result = algorithm.run(graph)
console.log(result.distance) // the distance between startNode and endNode

See Also

Developer's Guide
Gets an ordered collection of edges defining this path.
readonlyfinal

Examples

// configure the shortest path algorithm
const algorithm = new SingleSourceShortestPaths({
  // single source
  source: startNode,
  // 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 each end node
for (const targetNode of targetNodes) {
  // set its distance to the startNode as label text
  graph.setLabelText(
    targetNode.labels.get(0),
    `${result.getPathTo(targetNode)!.distance}`,
  )
  // and mark the edge path from start to the end node
  for (const edge of result.getPathTo(targetNode)!.edges) {
    graph.setStyle(edge, highlightPathStyle)
  }
}

See Also

Developer's Guide
Gets the end node of the path.
readonlyfinal

See Also

Developer's Guide
Gets a collection of nodes along this path.
This starts with start and ends with end by following the edges of edges.
readonlyfinal

See Also

Developer's Guide
Gets the start node of the path.
readonlyfinal

See Also

Developer's Guide