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.

12.3 Maximum Flow ( max flow )<br />

Let G = (V, E) be a directed graph, let s and t be distinct vertices in G and let cap :<br />

E −→ IR ≥0 be a non-negative function on the edges of G. For an edge e, we call cap(e)<br />

the capacity of e. An (s, t)-flow or simply flow is a function f : E −→ IR ≥0 satisfying the<br />

capacity constraints and the flow conservation constraints:<br />

(1) 0 ≤ f(e) ≤ cap(e) for every edge e ∈ E<br />

∑<br />

∑<br />

(2)<br />

f(e) = f(e) for every node v ∈ V \{s, t}<br />

e;source(e)=v<br />

e;target(e)=v<br />

<strong>The</strong> value of the flow is the net flow into t (equivalently, the net flow out of s). <strong>The</strong> net<br />

flow into t is the flow into t minus the flow out of t. A flow is maximum if its value is at<br />

least as large as the value of any other flow.<br />

All max flow implementations are template functions. <strong>The</strong> template parameter NT can<br />

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

the files<br />

#include <br />

#include <br />

must be included.<br />

<strong>The</strong>re are pre-instantiations for the number types int and double.<strong>The</strong> pre-instantiated<br />

versions have the same function names except for the suffix _T. In order to use them<br />

either<br />

#include <br />

or<br />

#include <br />

has to be included (the latter file includes the former). <strong>The</strong> connection between template<br />

functions and pre-instantiated functions is discussed in detail in the section “Templates<br />

for Network Algorithms” of the <strong>LEDA</strong> book.<br />

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

that can incur rounding error, e.g., the type double. <strong>The</strong> section “Algorithms on Weighted<br />

Graphs and Arithmetic Demand” of the <strong>LEDA</strong> book contains a general discussion of this<br />

issue. <strong>The</strong> template functions are only guaranteed to perform correctly if all arithmetic<br />

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

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

results exceeds the maximal integer representable by the number type (2 53 − 1 in the<br />

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

particular, the algorithms do not use divisions and multiplications.

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

Saved successfully!

Ooh no, something went wrong!