Satsuma
a delicious .NET graph library
|
Uses Dijkstra's algorithm to find cheapest paths in a graph. More...
Public Member Functions | |
void | AddSource (Node node) |
Adds a new source node. More... | |
void | AddSource (Node node, double nodeCost) |
Adds a new source node and sets its initial distance to nodeCost. More... | |
Dijkstra (IGraph graph, Func< Arc, double > cost, DijkstraMode mode) | |
bool | Fixed (Node node) |
Returns whether a node has been fixed. More... | |
double | GetDistance (Node node) |
Gets the cost of the current cheapest path from the source nodes to a given node (that is, its distance from the sources). More... | |
Arc | GetParentArc (Node node) |
Gets the arc connecting a node with its parent in the current forest of cheapest paths. More... | |
IPath | GetPath (Node node) |
Gets the current cheapest path from the source nodes to a given node. More... | |
bool | Reached (Node node) |
Returns whether a node has been reached. More... | |
void | Run () |
Runs the algorithm until all possible nodes are fixed. More... | |
Node | RunUntilFixed (Node target) |
Runs the algorithm until a specific target node is fixed. More... | |
Node | RunUntilFixed (Func< Node, bool > isTarget) |
Runs the algorithm until a node satisfying the given condition is fixed. More... | |
Node | Step () |
Performs a step in the algorithm and fixes a node. More... | |
Properties | |
Func< Arc, double > | Cost [get, set] |
The arc cost function. More... | |
IEnumerable< Node > | FixedNodes [get] |
Returns the fixed nodes. More... | |
IGraph | Graph [get, set] |
The input graph. More... | |
DijkstraMode | Mode [get, set] |
The path cost calculation mode. More... | |
double | NullCost [get, set] |
The lowest possible cost value. More... | |
IEnumerable< Node > | ReachedNodes [get] |
Returns the reached nodes. More... | |
Uses Dijkstra's algorithm to find cheapest paths in a graph.
Usage:
The algorithm reaches and fixes nodes one after the other (see Reached and Fixed).
Querying the results:
double.PositiveInfinity
, Arc.Invalid and null respectively.Example (finding a shortest path between two nodes):
Definition at line 52 of file Dijsktra.cs.
Satsuma.Dijkstra.Dijkstra | ( | IGraph | graph, |
Func< Arc, double > | cost, | ||
DijkstraMode | mode | ||
) |
Definition at line 75 of file Dijsktra.cs.
void Satsuma.Dijkstra.AddSource | ( | Node | node | ) |
Adds a new source node.
InvalidOperationException | The node has already been reached. |
Definition at line 95 of file Dijsktra.cs.
void Satsuma.Dijkstra.AddSource | ( | Node | node, |
double | nodeCost | ||
) |
Adds a new source node and sets its initial distance to nodeCost.
Use this method only if you know what you are doing.
InvalidOperationException | The node has already been reached, or nodeCost is invalid as an arc cost. |
Definition at line 106 of file Dijsktra.cs.
bool Satsuma.Dijkstra.Fixed | ( | Node | node | ) |
Returns whether a node has been fixed.
Definition at line 204 of file Dijsktra.cs.
double Satsuma.Dijkstra.GetDistance | ( | Node | node | ) |
Gets the cost of the current cheapest path from the source nodes to a given node (that is, its distance from the sources).
double.PositiveInfinity
if the node has not been reached yet. Definition at line 216 of file Dijsktra.cs.
Gets the arc connecting a node with its parent in the current forest of cheapest paths.
Definition at line 224 of file Dijsktra.cs.
Gets the current cheapest path from the source nodes to a given node.
Definition at line 232 of file Dijsktra.cs.
bool Satsuma.Dijkstra.Reached | ( | Node | node | ) |
Returns whether a node has been reached.
See Fixed for more information.
Definition at line 187 of file Dijsktra.cs.
void Satsuma.Dijkstra.Run | ( | ) |
Runs the algorithm until all possible nodes are fixed.
Definition at line 154 of file Dijsktra.cs.
Runs the algorithm until a specific target node is fixed.
(see Fixed)
target | The node to fix. |
Definition at line 162 of file Dijsktra.cs.
Runs the algorithm until a node satisfying the given condition is fixed.
Definition at line 174 of file Dijsktra.cs.
Node Satsuma.Dijkstra.Step | ( | ) |
Performs a step in the algorithm and fixes a node.
Definition at line 118 of file Dijsktra.cs.
|
getset |
The arc cost function.
double.PositiveInfinity
means that an arc is impassable. See DijkstraMode for restrictions on cost functions.
Definition at line 59 of file Dijsktra.cs.
|
get |
|
getset |
The input graph.
Definition at line 55 of file Dijsktra.cs.
|
getset |
The path cost calculation mode.
Definition at line 62 of file Dijsktra.cs.
|
getset |
The lowest possible cost value.
Definition at line 66 of file Dijsktra.cs.
|
get |