76
Mincost Flow Problem Definition: min e c(e)f (e) s.t. e E : 0 f (e) u(e) v V : f(v) = b(v) æ G = (V,E) is a directed graph. æ u : E R + 0 ∪ {∞} is the capacity function. æ c : E R is the cost function (note that c(e) may be negative). æ b : V R, vV b(v) = 0 is a demand function. EADS © Ernst Mayr, Harald Räcke 522/609

Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

  • Upload
    ngocong

  • View
    232

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Mincost Flow

Problem Definition:

min∑e c(e)f (e)

s.t. ∀e ∈ E : 0 ≤ f(e) ≤ u(e)∀v ∈ V : f(v) = b(v)

ñ G = (V , E) is a directed graph.

ñ u : E → R+0 ∪ {∞} is the capacity function.

ñ c : E → R is the cost function

(note that c(e) may be negative).

ñ b : V → R,∑v∈V b(v) = 0 is a demand function.

EADS

© Ernst Mayr, Harald Räcke 522/609

Page 2: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Mincost Flow

Problem Definition:

min∑e c(e)f (e)

s.t. ∀e ∈ E : 0 ≤ f(e) ≤ u(e)∀v ∈ V : f(v) = b(v)

ñ G = (V , E) is a directed graph.

ñ u : E → R+0 ∪ {∞} is the capacity function.

ñ c : E → R is the cost function

(note that c(e) may be negative).

ñ b : V → R,∑v∈V b(v) = 0 is a demand function.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 522/609

Page 3: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Mincost Flow

Problem Definition:

min∑e c(e)f (e)

s.t. ∀e ∈ E : 0 ≤ f(e) ≤ u(e)∀v ∈ V : f(v) = b(v)

ñ G = (V , E) is a directed graph.

ñ u : E → R+0 ∪ {∞} is the capacity function.

ñ c : E → R is the cost function

(note that c(e) may be negative).

ñ b : V → R,∑v∈V b(v) = 0 is a demand function.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 522/609

Page 4: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Mincost Flow

Problem Definition:

min∑e c(e)f (e)

s.t. ∀e ∈ E : 0 ≤ f(e) ≤ u(e)∀v ∈ V : f(v) = b(v)

ñ G = (V , E) is a directed graph.

ñ u : E → R+0 ∪ {∞} is the capacity function.

ñ c : E → R is the cost function

(note that c(e) may be negative).

ñ b : V → R,∑v∈V b(v) = 0 is a demand function.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 522/609

Page 5: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Mincost Flow

Problem Definition:

min∑e c(e)f (e)

s.t. ∀e ∈ E : 0 ≤ f(e) ≤ u(e)∀v ∈ V : f(v) = b(v)

ñ G = (V , E) is a directed graph.

ñ u : E → R+0 ∪ {∞} is the capacity function.

ñ c : E → R is the cost function

(note that c(e) may be negative).

ñ b : V → R,∑v∈V b(v) = 0 is a demand function.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 522/609

Page 6: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Solve Maxflow Using Mincost Flow

s

2

3

4

5

6

7

t

10

5

15

4

9

15

4

8

30

6

15

15

10

10

10

ñ Given a flow network for a standard maxflow problem.ñ Set b(v) = 0 for every node. Keep the capacity function u

for all edges. Set the cost c(e) for every edge to 0.ñ Add an edge from t to s with infinite capacity and cost −1.ñ Then, val(f∗) = − cost(fmin), where f∗ is a maxflow, and

fmin is a mincost-flow.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 523/609

Page 7: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Solve Maxflow Using Mincost Flow

s

2

3

4

5

6

7

t

10

5

15

4

9

15

4

8

30

6

15

15

10

10

10

ñ Given a flow network for a standard maxflow problem.

ñ Set b(v) = 0 for every node. Keep the capacity function ufor all edges. Set the cost c(e) for every edge to 0.

ñ Add an edge from t to s with infinite capacity and cost −1.ñ Then, val(f∗) = − cost(fmin), where f∗ is a maxflow, and

fmin is a mincost-flow.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 523/609

Page 8: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Solve Maxflow Using Mincost Flow

s

2

3

4

5

6

7

t

10

5

15

4

9

15

4

8

30

6

15

15

10

10

10

ñ Given a flow network for a standard maxflow problem.ñ Set b(v) = 0 for every node. Keep the capacity function u

for all edges. Set the cost c(e) for every edge to 0.

ñ Add an edge from t to s with infinite capacity and cost −1.ñ Then, val(f∗) = − cost(fmin), where f∗ is a maxflow, and

fmin is a mincost-flow.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 523/609

Page 9: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Solve Maxflow Using Mincost Flow

s

2

3

4

5

6

7

t

10

5

15

4

9

15

4

8

30

6

15

15

10

10

10

ñ Given a flow network for a standard maxflow problem.ñ Set b(v) = 0 for every node. Keep the capacity function u

for all edges. Set the cost c(e) for every edge to 0.ñ Add an edge from t to s with infinite capacity and cost −1.

ñ Then, val(f∗) = − cost(fmin), where f∗ is a maxflow, and

fmin is a mincost-flow.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 523/609

Page 10: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Solve Maxflow Using Mincost Flow

s

2

3

4

5

6

7

t

10

5

15

4

9

15

4

8

30

6

15

15

10

10

10

ñ Given a flow network for a standard maxflow problem.ñ Set b(v) = 0 for every node. Keep the capacity function u

for all edges. Set the cost c(e) for every edge to 0.ñ Add an edge from t to s with infinite capacity and cost −1.ñ Then, val(f∗) = − cost(fmin), where f∗ is a maxflow, and

fmin is a mincost-flow.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 523/609

Page 11: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Solve Maxflow Using Mincost Flow

Solve decision version of maxflow:

ñ Given a flow network for a standard maxflow problem, and

a value k.

ñ Set b(v) = 0 for every node apart from s or t. Set b(s) = −kand b(t) = k.

ñ Set edge-costs to zero, and keep the capacities.

ñ There exists a maxflow of value k if and only if the

mincost-flow problem is feasible.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 524/609

Page 12: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Solve Maxflow Using Mincost Flow

Solve decision version of maxflow:

ñ Given a flow network for a standard maxflow problem, and

a value k.

ñ Set b(v) = 0 for every node apart from s or t. Set b(s) = −kand b(t) = k.

ñ Set edge-costs to zero, and keep the capacities.

ñ There exists a maxflow of value k if and only if the

mincost-flow problem is feasible.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 524/609

Page 13: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Solve Maxflow Using Mincost Flow

Solve decision version of maxflow:

ñ Given a flow network for a standard maxflow problem, and

a value k.

ñ Set b(v) = 0 for every node apart from s or t. Set b(s) = −kand b(t) = k.

ñ Set edge-costs to zero, and keep the capacities.

ñ There exists a maxflow of value k if and only if the

mincost-flow problem is feasible.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 524/609

Page 14: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Solve Maxflow Using Mincost Flow

Solve decision version of maxflow:

ñ Given a flow network for a standard maxflow problem, and

a value k.

ñ Set b(v) = 0 for every node apart from s or t. Set b(s) = −kand b(t) = k.

ñ Set edge-costs to zero, and keep the capacities.

ñ There exists a maxflow of value k if and only if the

mincost-flow problem is feasible.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 524/609

Page 15: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Generalization

Our model:

min∑e c(e)f (e)

s.t. ∀e ∈ E : 0 ≤ f(e) ≤ u(e)∀v ∈ V : f(v) = b(v)

where b : V → R,∑v b(v) = 0; u : E → R+0 ∪ {∞}; c : E → R;

A more general model?

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

where a : V → R, b : V → R; ` : E → R∪ {−∞}, u : E → R∪ {∞}c : E → R;

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 525/609

Page 16: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Generalization

Our model:

min∑e c(e)f (e)

s.t. ∀e ∈ E : 0 ≤ f(e) ≤ u(e)∀v ∈ V : f(v) = b(v)

where b : V → R,∑v b(v) = 0; u : E → R+0 ∪ {∞}; c : E → R;

A more general model?

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

where a : V → R, b : V → R; ` : E → R∪ {−∞}, u : E → R∪ {∞}c : E → R;

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 525/609

Page 17: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Generalization

Differences

ñ Flow along an edge e may have non-zero lower bound `(e).ñ Flow along e may have negative upper bound u(e).ñ The demand at a node v may have lower bound a(v) and

upper bound b(v) instead of just lower bound = upper

bound = b(v).

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 526/609

Page 18: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction I

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

We can assume that a(v) = b(v):

Add new node r .

Add edge (r , v) for all v ∈ V .

Set `(e) = c(e) = 0 for theseedges.

Set u(e) = b(v)− a(v) foredge (r , v).

Set a(v) = b(v) for all v ∈ V .

Set b(r) = −∑v∈V b(v).−∑v b(v) is negative; hence r is only sending flow.

v

r

u(e)=b(v

)− a(v)

`(e) = 0

c(e) = 0

Page 19: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction I

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

We can assume that a(v) = b(v):

Add new node r .

Add edge (r , v) for all v ∈ V .

Set `(e) = c(e) = 0 for theseedges.

Set u(e) = b(v)− a(v) foredge (r , v).

Set a(v) = b(v) for all v ∈ V .

Set b(r) = −∑v∈V b(v).−∑v b(v) is negative; hence r is only sending flow.

v

r

u(e)=b(v

)− a(v)

`(e) = 0

c(e) = 0

Page 20: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction I

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

We can assume that a(v) = b(v):

Add new node r .

Add edge (r , v) for all v ∈ V .

Set `(e) = c(e) = 0 for theseedges.

Set u(e) = b(v)− a(v) foredge (r , v).

Set a(v) = b(v) for all v ∈ V .

Set b(r) = −∑v∈V b(v).−∑v b(v) is negative; hence r is only sending flow.

v

r

u(e)=b(v

)− a(v)

`(e) = 0

c(e) = 0

Page 21: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction I

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

We can assume that a(v) = b(v):

Add new node r .

Add edge (r , v) for all v ∈ V .

Set `(e) = c(e) = 0 for theseedges.

Set u(e) = b(v)− a(v) foredge (r , v).

Set a(v) = b(v) for all v ∈ V .

Set b(r) = −∑v∈V b(v).−∑v b(v) is negative; hence r is only sending flow.

v

r

u(e)=b(v

)− a(v)

`(e) = 0

c(e) = 0

Page 22: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction I

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

We can assume that a(v) = b(v):

Add new node r .

Add edge (r , v) for all v ∈ V .

Set `(e) = c(e) = 0 for theseedges.

Set u(e) = b(v)− a(v) foredge (r , v).

Set a(v) = b(v) for all v ∈ V .

Set b(r) = −∑v∈V b(v).−∑v b(v) is negative; hence r is only sending flow.

v

r

u(e)=b(v

)− a(v)

`(e) = 0

c(e) = 0

Page 23: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction I

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

We can assume that a(v) = b(v):

Add new node r .

Add edge (r , v) for all v ∈ V .

Set `(e) = c(e) = 0 for theseedges.

Set u(e) = b(v)− a(v) foredge (r , v).

Set a(v) = b(v) for all v ∈ V .

Set b(r) = −∑v∈V b(v).−∑v b(v) is negative; hence r is only sending flow.

v

r

u(e)=b(v

)− a(v)

`(e) = 0

c(e) = 0

Page 24: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction I

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

We can assume that a(v) = b(v):

Add new node r .

Add edge (r , v) for all v ∈ V .

Set `(e) = c(e) = 0 for theseedges.

Set u(e) = b(v)− a(v) foredge (r , v).

Set a(v) = b(v) for all v ∈ V .

Set b(r) = −∑v∈V b(v).−∑v b(v) is negative; hence r is only sending flow.

v

r

u(e)=b(v

)− a(v)

`(e) = 0

c(e) = 0

Page 25: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction I

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

We can assume that a(v) = b(v):

Add new node r .

Add edge (r , v) for all v ∈ V .

Set `(e) = c(e) = 0 for theseedges.

Set u(e) = b(v)− a(v) foredge (r , v).

Set a(v) = b(v) for all v ∈ V .

Set b(r) = −∑v∈V b(v).−∑v b(v) is negative; hence r is only sending flow.

v

r

u(e)=b(v

)− a(v)

`(e) = 0

c(e) = 0

Page 26: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction I

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

We can assume that a(v) = b(v):

Add new node r .

Add edge (r , v) for all v ∈ V .

Set `(e) = c(e) = 0 for theseedges.

Set u(e) = b(v)− a(v) foredge (r , v).

Set a(v) = b(v) for all v ∈ V .

Set b(r) = −∑v∈V b(v).−∑v b(v) is negative; hence r is only sending flow.

v

r

u(e)=b(v

)− a(v)

`(e) = 0

c(e) = 0

Page 27: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction I

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

We can assume that a(v) = b(v):

Add new node r .

Add edge (r , v) for all v ∈ V .

Set `(e) = c(e) = 0 for theseedges.

Set u(e) = b(v)− a(v) foredge (r , v).

Set a(v) = b(v) for all v ∈ V .

Set b(r) = −∑v∈V b(v).−∑v b(v) is negative; hence r is only sending flow.

v

r

u(e)=b(v

)− a(v)

`(e) = 0

c(e) = 0

Page 28: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction II

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : f(v) = b(v)

We can assume that either `(e) ≠ −∞ or u(e) ≠ ∞:

u v

u(e)= ∞`(e) = −∞c(e) = 0

If c(e) = 0 we can contract the edge/identify nodes u and v.

If c(e) ≠ 0 we can transform the graph so that c(e) = 0.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 528/609

Page 29: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction II

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : f(v) = b(v)

We can assume that either `(e) ≠ −∞ or u(e) ≠ ∞:

u v

u(e)= ∞`(e) = −∞c(e) = 0

If c(e) = 0 we can contract the edge/identify nodes u and v.

If c(e) ≠ 0 we can transform the graph so that c(e) = 0.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 528/609

Page 30: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction II

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : f(v) = b(v)

We can assume that either `(e) ≠ −∞ or u(e) ≠ ∞:

u v

u(e)= ∞`(e) = −∞c(e) = 0

If c(e) = 0 we can contract the edge/identify nodes u and v.

If c(e) ≠ 0 we can transform the graph so that c(e) = 0.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 528/609

Page 31: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction II

We can transform any network so that a particular edge has

cost c(e) = 0:

x

b(x) = b(u)u v

+δ−δ

−δ−δ +δ

u(e)= ∞`(e) = −∞c(e) = δ ≠ 0

−δ

Additionally we set b(u) = 0.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 529/609

Page 32: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction II

We can transform any network so that a particular edge has

cost c(e) = 0:

x

b(x) = b(u)u v

+δ−δ

−δ−δ +δ

u(e)= ∞`(e) = −∞c(e) = δ ≠ 0

−δ

Additionally we set b(u) = 0.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 529/609

Page 33: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction II

We can transform any network so that a particular edge has

cost c(e) = 0:

x

b(x) = b(u)u v

+δ−δ

δ

−δ−δ +δ

u(e)= ∞`(e) = −∞c(e) = δ ≠ 0

−δ

Additionally we set b(u) = 0.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 529/609

Page 34: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction III

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : f(v) = b(v)

We can assume that `(e) ≠ −∞:

u v

u v

u(e)=d ≠∞`(e)=−∞c(e)=a

u(e)=∞`(e)=−dc(e)=−a

Replace the edge by an edge in opposite direction.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 530/609

Page 35: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Reduction IV

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : f(v) = b(v)

We can assume that `(e) = 0:

u v

u v

u(e)`(e)=d ≠ −∞c(e)

u(e)− d`(e) = 0c(e)

u vb(u) = d b(v) = −d

The added edges have infinite capacity and cost c(e)/2.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 531/609

Page 36: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Applications

Caterer Problem

ñ She needs to supply ri napkins on N successive days.

ñ She can buy new napkins at p cents each.

ñ She can launder them at a fast laundry that takes m days

and cost f cents a napkin.

ñ She can use a slow laundry that takes k > m days and costs

s cents each.

ñ At the end of each day she should determine how many to

send to each laundry and how many to buy in order to fulfill

demand.

ñ Minimize cost.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 532/609

Page 37: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Applications

Caterer Problem

ñ She needs to supply ri napkins on N successive days.

ñ She can buy new napkins at p cents each.

ñ She can launder them at a fast laundry that takes m days

and cost f cents a napkin.

ñ She can use a slow laundry that takes k > m days and costs

s cents each.

ñ At the end of each day she should determine how many to

send to each laundry and how many to buy in order to fulfill

demand.

ñ Minimize cost.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 532/609

Page 38: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Applications

Caterer Problem

ñ She needs to supply ri napkins on N successive days.

ñ She can buy new napkins at p cents each.

ñ She can launder them at a fast laundry that takes m days

and cost f cents a napkin.

ñ She can use a slow laundry that takes k > m days and costs

s cents each.

ñ At the end of each day she should determine how many to

send to each laundry and how many to buy in order to fulfill

demand.

ñ Minimize cost.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 532/609

Page 39: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Applications

Caterer Problem

ñ She needs to supply ri napkins on N successive days.

ñ She can buy new napkins at p cents each.

ñ She can launder them at a fast laundry that takes m days

and cost f cents a napkin.

ñ She can use a slow laundry that takes k > m days and costs

s cents each.

ñ At the end of each day she should determine how many to

send to each laundry and how many to buy in order to fulfill

demand.

ñ Minimize cost.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 532/609

Page 40: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Applications

Caterer Problem

ñ She needs to supply ri napkins on N successive days.

ñ She can buy new napkins at p cents each.

ñ She can launder them at a fast laundry that takes m days

and cost f cents a napkin.

ñ She can use a slow laundry that takes k > m days and costs

s cents each.

ñ At the end of each day she should determine how many to

send to each laundry and how many to buy in order to fulfill

demand.

ñ Minimize cost.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 532/609

Page 41: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Applications

Caterer Problem

ñ She needs to supply ri napkins on N successive days.

ñ She can buy new napkins at p cents each.

ñ She can launder them at a fast laundry that takes m days

and cost f cents a napkin.

ñ She can use a slow laundry that takes k > m days and costs

s cents each.

ñ At the end of each day she should determine how many to

send to each laundry and how many to buy in order to fulfill

demand.

ñ Minimize cost.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 532/609

Page 42: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

reservoir

trash

reservoir

trash

Page 43: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

reservoir

trash

10

10

10

10

9

9

9

9

8

8

8

8

7

7

7

7

6

6

6

6

5

5

5

5

4

4

4

4

3

3

3

3

2

2

2

2

1

1

1

1

0

0

0

0

reservoir

trash

day edges:upper bound: u(ei) = ∞;lower bound: `(ei) = ri;cost: c(e) = 0

Page 44: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

reservoir

trash

10

10

10

10

9

9

9

9

8

8

8

8

7

7

7

7

6

6

6

6

5

5

5

5

4

4

4

4

3

3

3

3

2

2

2

2

1

1

1

1

0

0

0

0

reservoir

trash

buy edges:upper bound: u(ei) = ∞;lower bound: `(ei) = 0;cost: c(e) = p

Page 45: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

reservoir

trash

10

10

10

10

9

9

9

9

8

8

8

8

7

7

7

7

6

6

6

6

5

5

5

5

4

4

4

4

3

3

3

3

2

2

2

2

1

1

1

1

0

0

0

0

reservoir

trash

forward edges:upper bound: u(ei) = ∞;lower bound: `(ei) = 0;cost: c(e) = 0

Page 46: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

reservoir

trash

10

10

10

10

9

9

9

9

8

8

8

8

7

7

7

7

6

6

6

6

5

5

5

5

4

4

4

4

3

3

3

3

2

2

2

2

1

1

1

1

0

0

0

0

reservoir

trash

slow edges:upper bound: u(ei) = ∞;lower bound: `(ei) = 0;cost: c(e) = s

Page 47: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

reservoir

trash

10

10

10

10

9

9

9

9

8

8

8

8

7

7

7

7

6

6

6

6

5

5

5

5

4

4

4

4

3

3

3

3

2

2

2

2

1

1

1

1

0

0

0

0

reservoir

trash

fast edges:upper bound: u(ei) = ∞;lower bound: `(ei) = 0;cost: c(e) = f

Page 48: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

reservoir

trash

10

10

10

10

9

9

9

9

8

8

8

8

7

7

7

7

6

6

6

6

5

5

5

5

4

4

4

4

3

3

3

3

2

2

2

2

1

1

1

1

0

0

0

0

reservoir

trash

trash edges:upper bound: u(ei) = ∞;lower bound: `(ei) = 0;cost: c(e) = 0

Page 49: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

reservoir

trash

10

10

10

10

9

9

9

9

8

8

8

8

7

7

7

7

6

6

6

6

5

5

5

5

4

4

4

4

3

3

3

3

2

2

2

2

1

1

1

1

0

0

0

0

reservoir

trash

Page 50: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

reservoir

trash

10

10

10

10

9

9

9

9

8

8

8

8

7

7

7

7

6

6

6

6

5

5

5

5

4

4

4

4

3

3

3

3

2

2

2

2

1

1

1

1

0

0

0

0

reservoir

trash

Page 51: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Residual Graph

The residual graph for a mincost flow is exactly defined as the

residual graph for standard flows, with the only exception that

one needs to define a cost for the residual edge.

For a flow of z from u to v the residual edge (v,u) has capacity

z and a cost of −c((u,v)).

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 534/609

Page 52: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Residual Graph

The residual graph for a mincost flow is exactly defined as the

residual graph for standard flows, with the only exception that

one needs to define a cost for the residual edge.

For a flow of z from u to v the residual edge (v,u) has capacity

z and a cost of −c((u,v)).

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 534/609

Page 53: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

A circulation in a graph G = (V , E) is a function f : E → R+ that

has an excess flow f(v) = 0 for every node v ∈ V .

A circulation is feasible if it fulfills capacity constraints, i.e.,

f(e) ≤ u(e) for every edge of G.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 535/609

Page 54: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

A circulation in a graph G = (V , E) is a function f : E → R+ that

has an excess flow f(v) = 0 for every node v ∈ V .

A circulation is feasible if it fulfills capacity constraints, i.e.,

f(e) ≤ u(e) for every edge of G.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 535/609

Page 55: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Lemma 1

A given flow is a mincost-flow if and only if the corresponding

residual graph Gf does not have a feasible circulation of

negative cost.

⇒ Suppose that g is a feasible circulation of negative cost in

the residual graph.

Then f + g is a feasible flow with cost

cost(f )+ cost(g) < cost(f ). Hence, f is not minimum cost.

⇐ Let f be a non-mincost flow, and let f∗ be a min-cost flow.

We need to show that the residual graph has a feasible

circulation with negative cost.

Clearly f∗ − f is a circulation of negative cost. One can also

easily see that it is feasible for the residual graph. (after

sending −f in the residual graph (pushing all flow back) we

arrive at the original graph; for this f∗ is clearly feasible)

Page 56: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Lemma 1

A given flow is a mincost-flow if and only if the corresponding

residual graph Gf does not have a feasible circulation of

negative cost.

⇒ Suppose that g is a feasible circulation of negative cost in

the residual graph.

Then f + g is a feasible flow with cost

cost(f )+ cost(g) < cost(f ). Hence, f is not minimum cost.

⇐ Let f be a non-mincost flow, and let f∗ be a min-cost flow.

We need to show that the residual graph has a feasible

circulation with negative cost.

Clearly f∗ − f is a circulation of negative cost. One can also

easily see that it is feasible for the residual graph. (after

sending −f in the residual graph (pushing all flow back) we

arrive at the original graph; for this f∗ is clearly feasible)

Page 57: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Lemma 1

A given flow is a mincost-flow if and only if the corresponding

residual graph Gf does not have a feasible circulation of

negative cost.

⇒ Suppose that g is a feasible circulation of negative cost in

the residual graph.

Then f + g is a feasible flow with cost

cost(f )+ cost(g) < cost(f ). Hence, f is not minimum cost.

⇐ Let f be a non-mincost flow, and let f∗ be a min-cost flow.

We need to show that the residual graph has a feasible

circulation with negative cost.

Clearly f∗ − f is a circulation of negative cost. One can also

easily see that it is feasible for the residual graph. (after

sending −f in the residual graph (pushing all flow back) we

arrive at the original graph; for this f∗ is clearly feasible)

Page 58: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Lemma 1

A given flow is a mincost-flow if and only if the corresponding

residual graph Gf does not have a feasible circulation of

negative cost.

⇒ Suppose that g is a feasible circulation of negative cost in

the residual graph.

Then f + g is a feasible flow with cost

cost(f )+ cost(g) < cost(f ). Hence, f is not minimum cost.

⇐ Let f be a non-mincost flow, and let f∗ be a min-cost flow.

We need to show that the residual graph has a feasible

circulation with negative cost.

Clearly f∗ − f is a circulation of negative cost. One can also

easily see that it is feasible for the residual graph. (after

sending −f in the residual graph (pushing all flow back) we

arrive at the original graph; for this f∗ is clearly feasible)

Page 59: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

Lemma 1

A given flow is a mincost-flow if and only if the corresponding

residual graph Gf does not have a feasible circulation of

negative cost.

⇒ Suppose that g is a feasible circulation of negative cost in

the residual graph.

Then f + g is a feasible flow with cost

cost(f )+ cost(g) < cost(f ). Hence, f is not minimum cost.

⇐ Let f be a non-mincost flow, and let f∗ be a min-cost flow.

We need to show that the residual graph has a feasible

circulation with negative cost.

Clearly f∗ − f is a circulation of negative cost. One can also

easily see that it is feasible for the residual graph. (after

sending −f in the residual graph (pushing all flow back) we

arrive at the original graph; for this f∗ is clearly feasible)

Page 60: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

Lemma 2

A graph (without zero-capacity edges) has a feasible circulation

of negative cost if and only if it has a negative cycle w.r.t.

edge-weights c : E → R.

Proof.

ñ Suppose that we have a negative cost circulation.

ñ Find directed path only using edges that have non-zero flow.

ñ If this path has negative cost you are done.

ñ Otherwise send flow in opposite direction along the cycle

until the bottleneck edge(s) does not carry any flow.

ñ You still have a circulation with negative cost.

ñ Repeat.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 538/609

Page 61: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

Lemma 2

A graph (without zero-capacity edges) has a feasible circulation

of negative cost if and only if it has a negative cycle w.r.t.

edge-weights c : E → R.

Proof.

ñ Suppose that we have a negative cost circulation.

ñ Find directed path only using edges that have non-zero flow.

ñ If this path has negative cost you are done.

ñ Otherwise send flow in opposite direction along the cycle

until the bottleneck edge(s) does not carry any flow.

ñ You still have a circulation with negative cost.

ñ Repeat.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 538/609

Page 62: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

Lemma 2

A graph (without zero-capacity edges) has a feasible circulation

of negative cost if and only if it has a negative cycle w.r.t.

edge-weights c : E → R.

Proof.

ñ Suppose that we have a negative cost circulation.

ñ Find directed path only using edges that have non-zero flow.

ñ If this path has negative cost you are done.

ñ Otherwise send flow in opposite direction along the cycle

until the bottleneck edge(s) does not carry any flow.

ñ You still have a circulation with negative cost.

ñ Repeat.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 538/609

Page 63: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

Lemma 2

A graph (without zero-capacity edges) has a feasible circulation

of negative cost if and only if it has a negative cycle w.r.t.

edge-weights c : E → R.

Proof.

ñ Suppose that we have a negative cost circulation.

ñ Find directed path only using edges that have non-zero flow.

ñ If this path has negative cost you are done.

ñ Otherwise send flow in opposite direction along the cycle

until the bottleneck edge(s) does not carry any flow.

ñ You still have a circulation with negative cost.

ñ Repeat.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 538/609

Page 64: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

Lemma 2

A graph (without zero-capacity edges) has a feasible circulation

of negative cost if and only if it has a negative cycle w.r.t.

edge-weights c : E → R.

Proof.

ñ Suppose that we have a negative cost circulation.

ñ Find directed path only using edges that have non-zero flow.

ñ If this path has negative cost you are done.

ñ Otherwise send flow in opposite direction along the cycle

until the bottleneck edge(s) does not carry any flow.

ñ You still have a circulation with negative cost.

ñ Repeat.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 538/609

Page 65: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

Lemma 2

A graph (without zero-capacity edges) has a feasible circulation

of negative cost if and only if it has a negative cycle w.r.t.

edge-weights c : E → R.

Proof.

ñ Suppose that we have a negative cost circulation.

ñ Find directed path only using edges that have non-zero flow.

ñ If this path has negative cost you are done.

ñ Otherwise send flow in opposite direction along the cycle

until the bottleneck edge(s) does not carry any flow.

ñ You still have a circulation with negative cost.

ñ Repeat.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 538/609

Page 66: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

Lemma 2

A graph (without zero-capacity edges) has a feasible circulation

of negative cost if and only if it has a negative cycle w.r.t.

edge-weights c : E → R.

Proof.

ñ Suppose that we have a negative cost circulation.

ñ Find directed path only using edges that have non-zero flow.

ñ If this path has negative cost you are done.

ñ Otherwise send flow in opposite direction along the cycle

until the bottleneck edge(s) does not carry any flow.

ñ You still have a circulation with negative cost.

ñ Repeat.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 538/609

Page 67: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

Algorithm 51 CycleCanceling(G = (V , E), c,u, b)1: establish a feasible flow f in G2: while Gf contains negative cycle do

3: use Bellman-Ford to find a negative circuit Z4: δ←min{uf (e) | e ∈ Z}5: augment δ units along Z and update Gf

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 539/609

Page 68: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

How do we find the initial feasible flow?

x1

x2

x3

x4

x5

x6

x7

ts −b(x1)−b(x1)−b(x2)−b(x2)

−b(x3)−b(x3)

b(x4)b(x4)

b(x5)b(x5)

b(x6)b(x6)

b(x7)b(x7)

ñ Connect new node s to all nodes with negative b(v)-value.

ñ Connect nodes with positive b(v)-value to a new node t.ñ There exist a feasible flow in the original graph iff in the

resulting graph there exists an s-t flow of value∑v :b(v)<0

(−b(v)) =∑

v :b(v)>0

b(v) .

Page 69: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

1

2

3

4

(2, 4)

3

(1, 2)0

1(2, 2)1

(1, 5)

(3, 3)3

0

-4 4

0

demand

cost

capacity

flow

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 541/609

Page 70: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

1

2

3

4

(2, 1)

(-2, 3) (-3, 3)

(3, 2)

(1, 2)(-1, 2)(2, 1)(-2, 1)

(1, 4)

(-1, 1)

0

-4 4

0

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 542/609

Page 71: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

1

2

3

4

(2, 1)

(-2, 3) (-3, 3)

(3, 2)

(1, 2)(-1, 2)(2, 1)(-2, 1)

(1, 4)

(-1, 1)

0

-4 4

0

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 542/609

Page 72: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

1

2

3

4

(2, 1)

(-2, 3) (-3, 1)

(3, 2)

(1, 2)(-1, 2)(2, 1)(-2, 1)

(1, 2)

(-1, 3)

0

-4 4

0

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 542/609

Page 73: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

1

2

3

4

(2, 1)

(-2, 3) (-3, 1)

(3, 2)

(1, 2)(-1, 2)(2, 1)(-2, 1)

(1, 2)

(-1, 3)

0

-4 4

0

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 542/609

Page 74: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

1

2

3

4

(2, 2)

(-2, 2) (-3, 1)

(3, 3)

(1, 2)(-1, 2)(2, 1)(-2, 2)

(1, 1)

(-1, 4)

0

-4 4

0

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 542/609

Page 75: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

Lemma 3

The improving cycle algorithm runs in time O(n2m2CU), for

integer capacities and costs, when for all edges e, |c(e)| ≤ C and

|u(e)| ≤ U .

ñ Running time of Bellman-Ford is O(mn).ñ Pushing flow along the cycle can be done in time O(n).ñ Each iteration decreases the total cost by at least 1.

ñ The true optimum cost must lie in the interval

[−mCU, . . . ,+mCU].

Note that this lemma is weak since it does not allow for edges

with infinite capacity.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 543/609

Page 76: Mincost Flow - Technische Universität Mü · PDF fileMincost Flow Problem Definition: min P ec—e–f—e– s.t. 8e2E: 0 f—e– u—e– 8v2V: f—v–b—v– æ G—V;E–is

15 Mincost Flow

A general mincost flow problem is of the following form:

min∑e c(e)f (e)

s.t. ∀e ∈ E : `(e) ≤ f(e) ≤ u(e)∀v ∈ V : a(v) ≤ f(v) ≤ b(v)

where a : V → R, b : V → R; ` : E → R∪ {−∞}, u : E → R∪ {∞}c : E → R;

Lemma 4 (without proof)

A general mincost flow problem can be solved in polynomial

time.

EADS 15 Mincost Flow

© Ernst Mayr, Harald Räcke 544/609