bfs

fun bfs(startNodes: List<T>, target: T? = null, reset: Boolean = true, maxDistance: Double = Double.POSITIVE_INFINITY)

Performs a Breadth-First Search, which finds the shortest path from the starting node to all other nodes, assuming the graph is unweighted (all edges have a weight of 1.0) It stores results that can be retrieved with the following functions:

  • depth()

  • currentVisitedNodes()

  • visitedNodes()

  • finalPath()

  • foundTarget()

  • distanceTo(node: T)

  • maxDistance()

  • furthestNode()

Parameters

startNodes

A list of starting nodes for the BFS traversal.

target

An optional node that, if specified, the bfs will stop once it's found. Finding the target will make foundTarget() return true, and store the path to the found target node for use in visualizations.

reset

A boolean indicating whether to reset the previous search results. If set to false, previously visited nodes will not be visited again.

maxDistance

Nodes further away from the startNodes than maxDistance will not be traversed.

Throws

If any of the starting nodes is not found in the graph, or if the graph is sparse, and the target node is not defined beforehand.


fun bfs(startNode: T, target: T? = null, reset: Boolean = true, maxDistance: Double = Double.POSITIVE_INFINITY)

Overload of fun bfs(startNodes: List, target: T?, reset: Boolean, maxDistance: Double) that accepts a single starting node instead of a list of starting nodes