Satsuma
a delicious .NET graph library
|
Finds cheapest paths in a graph from a set of source nodes to all nodes, or a negative cycle reachable from the sources. More...
Public Member Functions | |
BellmanFord (IGraph graph, Func< Arc, double > cost, IEnumerable< Node > sources) | |
Runs the Bellman-Ford algorithm. More... | |
double | GetDistance (Node node) |
Gets the cost of the cheapest path from the source nodes to a given node. More... | |
Arc | GetParentArc (Node node) |
Gets the arc connecting a node with its parent in the forest of cheapest paths. More... | |
IPath | GetPath (Node node) |
Gets a cheapest path from the source nodes to a given node. More... | |
bool | Reached (Node node) |
Returns whether a node has been reached. More... | |
Properties | |
Func< Arc, double > | Cost [get, set] |
The arc cost function. More... | |
IGraph | Graph [get, set] |
The input graph. More... | |
IPath | NegativeCycle [get, set] |
A negative cycle reachable from the sources, or null if none exists. More... | |
IEnumerable< Node > | ReachedNodes [get] |
Returns the reached nodes. More... | |
Finds cheapest paths in a graph from a set of source nodes to all nodes, or a negative cycle reachable from the sources.
There is no restriction on the cost function (as opposed to AStar and Dijkstra), but if a negative cycle is reachable from the sources, the algorithm terminates and does not calculate the distances.
If the cost function is non-negative, use Dijkstra, as it runs faster.
Querying the results:
double.PositiveInfinity
, Arc.Invalid and null respectively.Definition at line 28 of file BellmanFord.cs.
Satsuma.BellmanFord.BellmanFord | ( | IGraph | graph, |
Func< Arc, double > | cost, | ||
IEnumerable< Node > | sources | ||
) |
Runs the Bellman-Ford algorithm.
Definition at line 47 of file BellmanFord.cs.
double Satsuma.BellmanFord.GetDistance | ( | Node | node | ) |
Gets the cost of the cheapest path from the source nodes to a given node.
double.PositiveInfinity
if the node is unreachable from the source nodes. InvalidOperationException | A reachable negative cycle has been found (i.e. NegativeCycle is not null). |
Definition at line 137 of file BellmanFord.cs.
Gets the arc connecting a node with its parent in the forest of cheapest paths.
InvalidOperationException | A reachable negative cycle has been found (i.e. NegativeCycle is not null). |
Definition at line 147 of file BellmanFord.cs.
Gets a cheapest path from the source nodes to a given node.
InvalidOperationException | A reachable negative cycle has been found (i.e. NegativeCycle is not null). |
Definition at line 157 of file BellmanFord.cs.
bool Satsuma.BellmanFord.Reached | ( | Node | node | ) |
Returns whether a node has been reached.
Definition at line 125 of file BellmanFord.cs.
|
getset |
The arc cost function.
Each value must be finite or positive infinity. double.PositiveInfinity
means that an arc is impassable.
Definition at line 34 of file BellmanFord.cs.
|
getset |
The input graph.
Definition at line 31 of file BellmanFord.cs.
|
getset |
A negative cycle reachable from the sources, or null if none exists.
Definition at line 37 of file BellmanFord.cs.
|
get |