Satsuma
a delicious .NET graph library
|
Performs a breadth-first search (BFS) to find shortest paths from a set of source nodes to all nodes. More...
Public Member Functions | |
void | AddSource (Node node) |
Adds a new source node. More... | |
Bfs (IGraph graph) | |
int | GetLevel (Node node) |
Gets the current distance from the set of source nodes (that is, its level in the Bfs forest). More... | |
Arc | GetParentArc (Node node) |
Gets the arc connecting a node with its parent in the Bfs forest. More... | |
IPath | GetPath (Node node) |
Gets a shortest path from the sources to a node. More... | |
bool | Reached (Node x) |
Returns whether a node has been reached. More... | |
void | Run () |
Runs the algorithm until finished. More... | |
Node | RunUntilReached (Node target) |
Runs the algorithm until a specific target node is reached. More... | |
Node | RunUntilReached (Func< Node, bool > isTarget) |
Runs the algorithm until a node satisfying the given condition is reached. More... | |
bool | Step (Func< Node, bool > isTarget, out Node reachedTargetNode) |
Performs an iteration which involves dequeueing a node. More... | |
Properties | |
IGraph | Graph [get, set] |
The input graph. More... | |
IEnumerable< Node > | ReachedNodes [get] |
Returns the reached nodes. More... | |
Performs a breadth-first search (BFS) to find shortest paths from a set of source nodes to all nodes.
In other words, Bfs finds cheapest paths for the constant 1 cost function. The advantage of Bfs over Dijkstra is its faster execution.
Usage:
The algorithm reaches nodes one after the other (see Reached for definition).
Querying the results:
void Satsuma.Bfs.AddSource | ( | Node | node | ) |
int Satsuma.Bfs.GetLevel | ( | Node | node | ) |
Gets the arc connecting a node with its parent in the Bfs forest.
bool Satsuma.Bfs.Reached | ( | Node | x | ) |
Returns whether a node has been reached.
Runs the algorithm until a specific target node is reached.
target | The node to reach. |
Runs the algorithm until a node satisfying the given condition is reached.
Performs an iteration which involves dequeueing a node.
The unreached neighbors of the dequeued node are enqueued, and isTarget (which can be null) is called for each of them to find out if they belong to the target node set. If a target node is found among them, then the function returns immediately.
isTarget | Returns true for target nodes. Can be null. |
reachedTargetNode | The target node that has been newly reached, or Node.Invalid. |
true
if no target node has been reached in this step, and there is at least one yet unreached node.
|
get |