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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

template <br />

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

node array& dist)<br />

as above, but pred is not computed.<br />

template <br />

NT DIJKSTRA T(const graph& G, node s, node t, const edge array& c,<br />

node array& pred)<br />

computes a shortest path from s to t and returns its length.<br />

<strong>The</strong> cost of all edges must be non-negative. <strong>The</strong> return value<br />

is unspecified if there is no path from s to t. <strong>The</strong> array pred<br />

records a shortest path from s to t in reverse order, i.e., pred[t]<br />

is the last edge on the path. If there is no path from s to t<br />

or if s = t then pred[t] = nil. <strong>The</strong> worst case running time is<br />

O(m + n log n), but frequently much better.<br />

template <br />

bool BELLMAN FORD B T(const graph& G, node s, const edge array& c,<br />

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

BELLMAN FORD B 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 />

BELLMAN FORD B returns false if there is a negative cycle<br />

in G that is reachable from s and returns true otherwise. <strong>The</strong><br />

algorithm ([10]) has running time O(min(D, n)m) where D<br />

is the maximal number of edges on any shortest path. <strong>The</strong><br />

algorithm is only included for pedagogical purposes.<br />

void BF GEN(GRAPH & G, int n, int m, bool non negative = true)<br />

generates a graph with at most n nodes and at most m edges.<br />

<strong>The</strong> edge costs are stored as edge data. <strong>The</strong> running time<br />

of BELLMAN FORD B on this graph is Ω(nm). <strong>The</strong> edge<br />

weights are non-negative if non negative is true and are arbitrary<br />

otherwise.<br />

Precondition: m ≥ 2n and m ≤ n 2 /2.<br />

template <br />

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

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

BELLMAN FORD T 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 />

BELLMAN FORD T returns false if there is a negative cycle<br />

in G that is reachable from s and returns true otherwise. <strong>The</strong><br />

algorithm ([10]) has running time O(min(D, n)m) where D is<br />

the maximal number of edges in any shortest path.<br />

<strong>The</strong> algorithm is never significantly slower than BELL-<br />

MAN FORD B and frequently much faster.

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

Saved successfully!

Ooh no, something went wrong!