Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds...

22
Minimum Cost Flow Algorithms and Networks

Transcript of Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds...

Page 1: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Minimum Cost Flow

Algorithms and Networks

Page 2: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 2

This lecture

• The minimum cost flow problem: statement and applications

• The cycle cancelling algorithm • A polynomial time variant of cycle

cancelling • The successive shortest paths algorithm

Page 3: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 3

Minimum Cost Flow I

• Edges have – Capacity c(u,v): bound on amount of flow that

can go through the edge – Cost: cost(u,v): cost that must be paid per unit

of flow that goes through the edge. • Cost of flow f:

– Sum over all (u,v) of: f (u,v) * cost(u,v).

Page 4: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 4

Minimum cost flow problem

• Given: Network G, c, cost, s, t, and a target flow value r.

• Question: Find a flow from s to t with value r, with minimum cost.

Page 5: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 5

Unbounded capacities

• Some edges may have unbounded capacities – If there is a cycle of negative cost with only

edges with unbounded capacity: • Arbitrary small cost (degenerate case)

– Otherwise: simple transformation to bounded capacities

• E.g., set each unbounded capacity to sum of all bounded capacities

Page 6: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 6

Separate demands

• Similar to max-flow with multiple sources and multiple sinks

• Or: work with “demand”, which can be positive or negative

G

s1

sk

t1

tr

t s

Page 7: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 7

Nonnegative arc costs

• We may assume all costs are nonnegative. • In case of negative costs: assume bounded

capacity. Modify network to equivalent one with nonnegative costs:

b a

s b a t

Cost -r

Cost r

Capacity c

Capacity c Capacity c Capacity c

Or work with separate

demands Cost 0 Cost 0

Page 8: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 8

Applications

• Transport problems • Minimum cost matchings • Reconstruction of Left Ventricle from X-ray

projections – Image: 2d bit array; known are sums of columns, rows;

probabilities for each bit – Look for image with correct row and column sums of

maximum probability – Can be modelled as minimum cost flow problem

Page 9: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 9

Application: Optimal loading of hopping airplane

1 2 n

bij weight units (or passengers) can be transported from i to j Each gives a profit of fij

Plane can never carry more than p units How much units do we transport of each type for maximum profit?

1 2 3 4

12 23 34 13

14 24 Capacity i → j: p Node ij has supply bij Cost from ij to i: - fij Node i has demand

sum over all bji

All other arcs infinite cap.

All other costs 0

Page 10: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Cycles and circulations; paths and flows

• We can view: – Cycles as a special type of circulations – Paths as a special type of flows – If we have a directed cycle c, then we can see it as

a circulation: • c(e) = 1 when e is on c • c(e) = 0 otherwise

– If we have a path p from s to t, we can see it as a flow with value 1:

• p(e) = 1 when e is on p • p(e) = 0 otherwise

Algorithms and Networks: Minimum Cost Flow 10

Page 11: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

A&N: Maximum flow 11

First: useful theorems on flows and circulations

Theorem Let f be a circulation. Then f is a nonnegative linear combination of cycles in G. Proof. • Ignore lower bounds. • If f(v,w) = 0 everywhere, then it clearly holds. • Otherwise, there is a directed cycle c in G with each edge e on c:

f(e)>0 • Let r be the minimum flow of an edge on c, i.e., r = min {f(e) | e

on c} • Use induction: the theorem also holds for f – cr

– f-cr(e) = f(e) when e is not on c – f-cr(e) = f(e) – r when e is on c

• …

Page 12: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

More on these linear combinations

• If circulation f is integer, then f can be written as an`integer scalared’ linear combination of cycles in G

• Corollary: a flow is the linear combination of cycles and paths from s to t. – Look at the circulation by adding an edge from t to s

and giving it flow value(f). • And, a flow f with each f(e) an integer is the

integer scalared linear combination of cycles and paths from s to t

Algorithms and Networks: Minimum Cost Flow 12

Page 13: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 13

Residual network

• Define the residual network Gf of a flow in the setting of costs:

• Capacities as for maximum flow algorithms.

• If f (u,v)>0, then costf (u,v) = cost(u,v), and costf (v,u) = – cost(u,v).

Page 14: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 14

Example

a b

Capacity 5, cost 3

Capacity 2, cost 6

Suppose we send 1 flow from a to b

a

Capacity 4, cost 3

Capacity 2, cost 6

Capacity 1, cost -3

b

In Gf:

Page 15: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 15

Cycle cancelling algorithm

• Make a feasible flow f in the network • while Gf has a negative cycle do

– Find a negative cycle C in Gf – Let D be the minimum residual capacity cf of an

edge on C – Add D units of flow to each edge on C: this is a

new feasible flow of smaller cost • Output f.

Page 16: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 16

Cycle cancelling algorithm is correct

• Theorem: a flow f has minimum costs, if and only if Gf has no negative cycle. – If Gf has negative cycle, then we can improve f to one

with smaller cost. – Suppose f is a flow, and f’ is an optimal flow. f’ – f is a

circulation in Gf, hence a linear combination of cycles, and if f is not optimal, then the total cost of these cycles is negative, so there is a negative cycle in this set: it is a cycle in Gf.

Page 17: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 17

More on the cycle cancelling algorithm

• No guarantee that it uses polynomial time. • Corollary: if all costs, capacities, and target flow

value are integral, then there is an optimal integer minimum cost flow. – The cycle cancelling algorithm finds an integer flow in

this case. • Variant: using always the minimum mean cost

cycle gives a polynomial time algorithm!

Page 18: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 18

Minimum mean-cost circulation algorithm

• Cycle cancelling algorithm but find always the minimum mean cost cycle and use that. – O(nm) time to find the cycle. – A theorem shows that O(nm2 log2 n) iterations

are sufficient. – O(n2m3 log2 n) algorithm.

Presenter
Presentation Notes
Uses algorithm from exercise set.
Page 19: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 19

Successive shortest paths

• Start with flow f with f(u,v)=0 for all u,v. • repeat until value(f ) = r

– Find the shortest path P in Gf from s to t – Let q be the minimum residual capacity of an

edge on P. – Send min(q,r – value(f)) additional units of

flow across P.

Page 20: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Time and correctness

• Time: possibly exponential time … • Correctness: only if G has no cycle with

negative cost • Example where it goes wrong with negative

cost: consider target flow r=0 • Proof of correctness: next

Algorithms and Networks: Minimum Cost Flow 20

Page 21: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 21

On the successive shortest paths algorithm

• If G has no negative cycle, then the algorithm gives the optimal answer. – Invariant: f has

minimum cost among all flows with value value(f).

• Suppose we obtain f’ from f by sending across P.

• Let f’’ be a minimum cost flow with same value as f’.

• Write f’’ – f as weighted sum of paths from s to t in Gf and circuits in Gf. Argue that cost(f’ – f) ≤ cost(f’’ – f), using that: – P is shortest path – Circuits have non-negative

costs, by optimality of f.

Page 22: Minimum Cost Flow - Universiteit Utrechtminimum cost flow. – The cycle cancelling algorithm finds an integer flow in this case. • Variant: using always the minimum mean cost cycle

Algorithms and Networks: Minimum Cost Flow 22

Finally

• More efficient algorithms exist – Some use scaling techniques:

• Scaling on capacities • Scaling on costs