Minimum Cost Flow
Algorithms and Networks
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
2 Algorithms and Networks: Minimum Cost Flow
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).
3 Algorithms and Networks: Minimum Cost Flow
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.
4 Algorithms and Networks: Minimum Cost Flow
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
5 Algorithms and Networks: Minimum Cost Flow
Separate demands
• Similar to
max-flow with
multiple
sources and s1 t1
multiple sinks
• Or: work with s G t
“demand”,
which can be sk
tr
positive or
negative
6 Algorithms and Networks: Minimum Cost Flow
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:
Cost -r Or work
b a with separate
Capacity c demands
Cost 0 Cost r Cost 0
s b a t
Capacity c Capacity c Capacity c
7 Algorithms and Networks: Minimum Cost Flow
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
8 Algorithms and Networks: Minimum Cost Flow
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?
14 Capacity i j: p
24
Node ij has supply bij
13 All other arcs
Cost from ij to i: - fij
12 23 34 infinite cap.
Node i has demand All other costs 0
1 2 3 4 sum over all bji
9 Algorithms and Networks: Minimum Cost Flow
Residual network
• 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).
10 Algorithms and Networks: Minimum Cost Flow
Example
Capacity 5, cost 3
Suppose we send 1
a b flow from a to b
Capacity 2, cost 6 Capacity 4, cost 3
a b
In Gf: Capacity 2, cost 6
Capacity 1, cost -3
11 Algorithms and Networks: Minimum Cost Flow
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.
12 Algorithms and Networks: Minimum Cost Flow
Cycle cancelling algorithm is
correct
• Theorem: a flow f has minimum costs, if and only
if Gf has no negative cycle.
– If G 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.
13 Algorithms and Networks: Minimum Cost Flow
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!
14 Algorithms and Networks: Minimum Cost Flow
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.
15 Algorithms and Networks: Minimum Cost Flow
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.
16 Algorithms and Networks: Minimum Cost Flow
On the successive shortest paths
algorithm
• May use exponential • Suppose we obtain f’ from
f by sending across P.
running time • Let f’’ be a minimum cost
• Assume G has no flow with same value as f’.
negative edge costs. • Write f’’ – f as weighted
sum of paths from s to t in
• Gives optimal answer. Gf and circuits in Gf. Argue
– Invariant: f has that cost(f’ – f) cost(f’’ –
minimum cost among f), using that:
– P is shortest path
all flows with value
– Circuits have non-negative
value(f). costs, by optimality of f.
17 Algorithms and Networks: Minimum Cost Flow
Finally
• More efficient algorithms exist
– Some use scaling techniques:
• Scaling on capacities
• Scaling on costs
18 Algorithms and Networks: Minimum Cost Flow