Home | Documentation | Download | Platforms | Projects | Mailing Lists | Version History
Public Types | |
typedef list< node > ::const_iterator | shortest_path_node_iterator |
Iterator type for traversing nodes on one shortest path. | |
typedef list< edge > ::const_iterator | shortest_path_edge_iterator |
Iterator type for traversing edges on one shortest path. | |
Public Member Functions | |
dijkstra () | |
Default constructor. | |
virtual | ~dijkstra () |
Destructor. | |
void | source (const node &n) |
Sets source node. | |
void | target (const node &n) |
Sets target node. | |
void | weights (const edge_map< double > &weight) |
Sets weights of the edges. | |
void | store_preds (bool set) |
Enables or disables the storing of predecessors. | |
virtual int | check (graph &G) |
Checks whether the preconditions for Dijkstra are satisfied. | |
int | run (graph &G) |
Runs shortest path algorithm on G . | |
node | source () const |
Returns source node. | |
node | target () const |
Returns target node if set, node::node() else. | |
bool | store_preds () const |
Returns whether the storing of predecessors is enabled. | |
bool | reached (const node &n) const |
Returns whether n is reachable from source node. | |
double | distance (const node &n) const |
Returns the distance from source node to node n . | |
node | predecessor_node (const node &n) const |
Predecessor node of node n on the shortest path from the source node. | |
edge | predecessor_edge (const node &n) const |
Predecessor edge of node n on the shortest path from the source node. | |
shortest_path_node_iterator | shortest_path_nodes_begin (const node &dest) |
Returns an iterator to the beginning (to the source node) of a shortest node path to node dest . | |
shortest_path_node_iterator | shortest_path_nodes_end (const node &dest) |
Returns an iterator one after the end (one after node dest ) of a shortest node path to node dest . | |
shortest_path_edge_iterator | shortest_path_edges_begin (const node &dest) |
Returns an iterator to the beginning edge of a shortest edge path to node dest . | |
shortest_path_edge_iterator | shortest_path_edges_end (const node &dest) |
Returns an iterator one after the end of a shortest edge path to node dest . | |
virtual void | reset () |
Resets Dijkstra's algorithm. |
This class implements Dijkstra's algorithm for computing single source shortest path in worst case.
dijkstra::dijkstra | ( | ) |
virtual dijkstra::~dijkstra | ( | ) | [virtual] |
void dijkstra::source | ( | const node & | n | ) |
Sets source node.
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 |
void dijkstra::target | ( | const node & | n | ) |
Sets target node.
If a target is set with this method the algorithm stops if a shortest distance to n
is found. Ohterwise shortest paths are computed from source to any node in the graph.
n | target node |
void dijkstra::weights | ( | const edge_map< double > & | weight | ) |
Sets weights of the edges.
This method must be called before check run.
weight | weights of the edges |
void dijkstra::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 | true if predecessors should be stored |
virtual int dijkstra::check | ( | graph & | G | ) | [virtual] |
Checks whether the preconditions for Dijkstra are satisfied.
Necessary preconditions are:
G
has at least one nodeG
G | graph |
algorithm::GTL_OK | if algorithm can be applied | |
algorithm::GTL_ERROR | otherwise |
Implements algorithm.
int dijkstra::run | ( | graph & | G | ) | [virtual] |
Runs shortest path algorithm on G
.
This should return always algorithm::GTL_OK. The return value only tracks errors that might occur. Afterwards the result of the test can be accessed via access methods.
G | graph |
algorithm::GTL_OK | on success | |
algorithm::GTL_ERROR | otherwise |
Implements algorithm.
node dijkstra::source | ( | ) | const |
Returns source node.
node dijkstra::target | ( | ) | const |
bool dijkstra::store_preds | ( | ) | const |
Returns whether the storing of predecessors is enabled.
true
iff the storing of predecessors is enabledbool dijkstra::reached | ( | const node & | n | ) | const |
Returns whether n
is reachable from source node.
n | node |
true
iff n
was reached from source double dijkstra::distance | ( | const node & | n | ) | const |
Returns the distance from source node to node n
.
n | node |
n
is dijkstra::reached, -1.0
else
Predecessor node of node n
on the shortest path from the source node.
If n
is a root or wasn't reached the return value is the invalid node node::node().
n | node |
n
Predecessor edge of node n
on the shortest path from the source node.
If n
is a root or wasn't reached the return value is the invalid edge edge::edge().
n | node |
n
shortest_path_node_iterator dijkstra::shortest_path_nodes_begin | ( | const node & | dest | ) |
Returns an iterator to the beginning (to the source node) of a shortest node path to node dest
.
dest | target node |
dest
for the first time (before dijkstra::shortest_path_nodes_end) it needs shortest_path_node_iterator dijkstra::shortest_path_nodes_end | ( | const node & | dest | ) |
Returns an iterator one after the end (one after node dest
) of a shortest node path to node dest
.
dest | target node |
dest
for the first time (before dijkstra::shortest_path_nodes_begin) it needs shortest_path_edge_iterator dijkstra::shortest_path_edges_begin | ( | const node & | dest | ) |
Returns an iterator to the beginning edge of a shortest edge path to node dest
.
dest | target node |
dest
for the first time (before dijkstra::shortest_path_edges_end) it needs shortest_path_edge_iterator dijkstra::shortest_path_edges_end | ( | const node & | dest | ) |
Returns an iterator one after the end of a shortest edge path to node dest
.
dest | target node |
dest
for the first time (before dijkstra::shortest_path_edges_begin) it needs virtual void dijkstra::reset | ( | ) | [virtual] |
Resets Dijkstra's algorithm.
It prepares the algorithm to be applied again, possibly to another graph.
Implements algorithm.
University of Passau - FMI - Theoretical Computer Science