31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

template <br />

bool SHORTEST PATH T(const graph& G, node s, const edge array& c,<br />

node array& dist, node array& pred)<br />

SHORTEST PATH solves the single source shortest path<br />

problem in the graph G(V, E) with respect to the source node<br />

s and the cost-function given by the edge array c.<br />

<strong>The</strong> procedure returns false if there is a negative cycle in G<br />

that is reachable from s and returns true otherwise.<br />

It runs in linear time on acyclic graph, in time O(m +<br />

n log n) if all edge costs are non-negative, and runs in time<br />

O(min(D, n)m) otherwise. Here D is the maximal number of<br />

edges on any shortest path.<br />

list COMPUTE SHORTEST PATH(const graph& G, node s, node t,<br />

const node array& pred)<br />

computes a shortest path from s to t assuming that pred stores<br />

a valid shortest path tree with root s (as it can be computed<br />

with the previous function). <strong>The</strong> returned list contains the<br />

edges on a shortest path from s to t. <strong>The</strong> running time is<br />

linear in the length of the path.<br />

template <br />

node array CHECK SP T(const graph& G, node s, const edge array& c,<br />

const node array& dist,<br />

const node array& pred)<br />

checks whether the pair (dist, pred) is a correct solution to the<br />

shortest path problem (G, s, c) and returns a node array<br />

label with label[v] < 0 if v has distance −∞ (−2 for nodes<br />

lying on a negative cycle and −1 for a node reachable from<br />

a negative cycle), label[v] = 0 if v has finite distance, and<br />

label[v] > 0 if v has distance +∞. <strong>The</strong> program aborts if the<br />

check fails. <strong>The</strong> algorithm takes linear time.<br />

template <br />

void ACYCLIC SHORTEST PATH T(const graph& G, node s,<br />

const edge array& c,<br />

node array& dist, node array& pred)<br />

solves the single source shortest path problem with respect to<br />

source s. <strong>The</strong> algorithm takes linear time.<br />

Precondition: G must be acyclic.<br />

template <br />

void DIJKSTRA T(const graph& G, node s, const edge array& cost,<br />

node array& dist, node array& pred)<br />

solves the shortest path problem in a graph with non-negative<br />

edges weights.<br />

Precondition: <strong>The</strong> costs of all edges are non-negative.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!