dijkstra

fun dijkstra(startNode: T, target: T? = null)

Performs Dijkstra's algorithm, which finds the shortest path from the starting node to all other nodes. It stores results that can be retrieved with the following functions:

  • depth()

  • currentVisitedNodes()

  • visitedNodes()

  • finalPath()

  • foundTarget()

  • distanceTo(node: T)

  • maxDistance()

  • furthestNode()

If the graph is unweighted or has no weighted connections, a warning is issued, and BFS is executed instead.

Parameters

startNode

The starting node for Dijkstra's algorithm.

target

An optional target node. If specified, the algorithm will store the shortest path to the target node for use in visualization and flag the target as found so that foundTarget() returns true

Throws

IllegalStateException

If the starting node or the target node is not found in the graph.