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.

12.2 Shortest Path Algorithms ( shortest path )<br />

Let G be a graph, s a node in G, and c a cost function on the edges of G. Edge costs<br />

may be positive or negative. For a node v let µ(v) be the length of a shortest path from<br />

s to v (more precisely, the infimum of the lengths of all paths from s to v). If v is not<br />

reachable from s then µ(v) = +∞ and if v is reachable from s through a cycle of negative<br />

cost then µ(v) = −∞. Let V + , V f , and V − be the set of nodes v with µ(v) = +∞,<br />

−∞ < µ(v) < +∞, and µ(v) = −∞, respectively.<br />

<strong>The</strong> solution to a single source shortest path problem (G, s, c) is a pair (dist, pred) where<br />

dist is a node array and pred is a node array with the following properties.<br />

Let P = {pred[v] ; v ∈ V and pred[v] ≠ nil }. A P -cycle is a cycle all of whose edges<br />

belong to P and a P -path is a path all of whose edges belong to P .<br />

• v ∈ V + iff v ≠ s and pred[v] = nil and v ∈ V f ∪ V − iff v = s or pred[v] ≠ nil.<br />

• s ∈ V f if pred[s] = nil and s ∈ V − otherwise.<br />

• v ∈ V f if v is reachable from s by a P -path and s ∈ V f . P restricted to V f forms<br />

a shortest path tree and dist[v] = µ(s, v) for v ∈ V f .<br />

• All P -cycles have negative cost and v ∈ V − iff v lies on a P -cycle or is reachable<br />

from a P -cycle by a P -path.<br />

Most functions in this section are template functions. <strong>The</strong> template parameter NT can be<br />

instantiated with any number type. In order to use the template version of the function<br />

the .h-file<br />

#include <br />

must be included. <strong>The</strong> functions are pre-instantiated with int and double. <strong>The</strong> function<br />

names of the pre-instantiated versions are without the suffix _T.<br />

Special care should be taken when using the functions with a number type NT that<br />

can incur rounding error, e.g., the type double. <strong>The</strong> functions perform correctly if all<br />

arithmetic performed is without rounding error. This is the case if all numerical values<br />

in the input are integers (albeit stored as a number of type NT ) and if none of the<br />

intermediate results exceeds the maximal integer representable by the number type (2 52<br />

in the case of doubles). All intermediate results are sums and differences of input values,<br />

in particular, the algorithms do not use divisions and multiplications. All intermediate<br />

values are bounded by nC where n is the number of nodes and C is the maximal absolute<br />

value of any edge cost.

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

Saved successfully!

Ooh no, something went wrong!