Home | Documentation | Download | Platforms | Projects | Mailing Lists | Version History
Public Member Functions | |
bellman_ford () | |
Constructor. | |
virtual | ~bellman_ford () |
Destructor. | |
int | check (graph &G) |
Checks whether the preconditions for Bellman Ford are satisfied. | |
int | run (graph &G) |
Applies algorithm to graph g. | |
void | reset () |
Resets the algorithm. | |
void | source (const node &n) |
Sets source. | |
node | source () const |
Returns source. | |
void | weights (const edge_map< double > &weight) |
Sets weights of the edges. | |
void | store_preds (bool set) |
Enables or disables the storing of predecessors. | |
bool | store_preds () const |
Returns whether the storing of predecessors is enabled. | |
bool | reached (const node &n) const |
Returns whether is reachable from source. | |
double | distance (const node &n) const |
Returns the distance from source to n. | |
edge | predecessor_edge (const node &n) const |
edge to predecessor of node n on the shortest path from source | |
node | predecessor_node (const node &n) const |
predecessor of node n on the shortest path from source | |
bool | negative_cycle () const |
Returns whether there is a cycle with negative weight. |
Implementation of the single source shortest path due to Bellman and Ford. Unlike Dijkstra's SSSP algorithm this one allows negative edge weights, as long as there are no cycles with negative weight. If there are negative cycles this implementation finds them.
int bellman_ford::check | ( | graph & | G | ) | [virtual] |
Checks whether the preconditions for Bellman Ford are satisfied.
The Precondition are that the weights of the edges have been set and that the graph has at least one node.
G | graph. |
algorithm::GTL_OK | if algorithm can be applied | |
algorithm::GTL_ERROR | otherwise. |
Implements algorithm.
int bellman_ford::run | ( | graph & | g | ) | [virtual] |
Applies algorithm to graph g.
g | graph |
algorithm::GTL_OK | on success | |
algorithm::GTL_ERROR | otherwise |
Implements algorithm.
void bellman_ford::reset | ( | ) | [virtual] |
void bellman_ford::source | ( | const node & | n | ) | [inline] |
Sets source.
The default source is the invalid node (node::node()), in this case an arbitrary node is chosen and stored when this algorithm is run.
n | source. |
node bellman_ford::source | ( | ) | const [inline] |
Returns source.
void bellman_ford::weights | ( | const edge_map< double > & | weight | ) | [inline] |
Sets weights of the edges.
This method must be called before run.
w | weights of the edges. |
void bellman_ford::store_preds | ( | bool | set | ) |
Enables or disables the storing of predecessors.
If enabled for every node the predecessor on the shortest path from will be stored.
set | if true predecessors will be stored. |
bool bellman_ford::store_preds | ( | ) | const [inline] |
Returns whether the storing of predecessors is enabled.
true | iff the storing of predecessors is enabled. |
bool bellman_ford::reached | ( | const node & | n | ) | const [inline] |
double bellman_ford::distance | ( | const node & | n | ) | const [inline] |
edge to predecessor of node n on the shortest path from source
If n is a root or wasn't reached the return value is the invalid edge edge::edge().
Please note that this requires that this option was enabled during last run.
n | node. |
predecessor of node n on the shortest path from source
If n is a root or wasn't reached the return value is the invalid node node::node().
Please note that this requires that this option was enabled during last run.
n | node. |
University of Passau - FMI - Theoretical Computer Science