Represents a path between two nodes.
Inheritance Hierarchy
Remarks
See Also
Developer's Guide
Members
No filters for this type
Properties
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
algorithm.source = startNode
algorithm.sink = endNode
const result = algorithm.run(graph)
console.log(result.distance) // the distance between startNode and endNodeSee Also
Developer's Guide
Gets an ordered collection of edges defining this path.
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.
Gets the end node of the path.
readonlyfinal
See Also
Developer's Guide
Gets a collection of nodes along this path.
Gets a collection of nodes along this path.
Gets the start node of the path.
Gets the start node of the path.
readonlyfinal
See Also
Developer's Guide