You are on page 1of 37

Network Flow &

Linear Programming

Network Flow
Jeff Edmonds Linear Programming
Lecture 3 York University COSC 6111
Optimization Problems
•Ingredients:
•Instances: The possible inputs to the problem.
•Solutions for Instance: Each instance has an
exponentially large set of solutions.
•Cost of Solution: Each solution has an easy to
compute cost or value.
•Specification
•Preconditions: The input is one instance.
•Postconditions: An valid solution with optimal cost.
(minimum or maximum)
•Instance:
Network Flow
•A Network is a directed graph G
•Edges represent pipes that carry flow
•Each edge <u,v> has a maximum capacity c<u,v>
•A source node s out of which flow leaves
•A sink node t into which flow arrives

Goal:
Max Flow
•Instance:
Network Flow
•A Network is a directed graph G
•Edges represent pipes that carry flow
•Each edge <u,v> has a maximum capacity c<u,v>
•A source node s out of which flow leaves
•A sink node t into which flow arrives
Network Flow

For some edges/pipes,


it is not clear which direction the flow should go
in order to maximize the flow from s to t.
Hence we allow flow in both directions.
•Solution:
Network Flow
•The amount of flow F<u,v> through each edge.
•Flow F<u,v> can't exceed capacity c<u,v>.
•No leaks, no extra flow.
For each node v: flow in = flow out
u F<u,v> = w F<v,w>
•Value of Solution:
Network Flow
•Flow from s into the network
minus flow from the network back into s.
rate(F) = u F<s,u> - v F<v,s>

Goal:
Max Flow
Min Cut
•Value Solution C=<U,V>:
cap(C) = how much can flow from U to V
= uU,vV c<u,v>

Goal:
Min Cut U
s V

u
v

t
•Theorem:
Max Flow = Min Cut
•For all Networks MaxF rate(F) = MinC cap(C)
•Prove:  F,C rate(F)  cap(C)
•Prove:  flow F, alg either
•finds a better flow F
•or finds cut C such that rate(F) = cap(C)
•Alg stops with an F and C for which rate(F) = cap(C)
•F witnesses that the optimal flow can't be less
•C witnesses that it can't be more.
U
V
u
v
Network Flow

Walking
c<v,u> F<u,v> c<u,v>

Flow Graph
f<u,v>+w f /c Augmentation Graph
<u,v> <u,v> c<u,v>-F<u,v>
u v u v
w
0/c<v,u> F<u,v>+c<v,u>
Network Flow

Walking
c<u,v> F<u,v> c<u,v>

Flow Graph
F<u,v>-w F /c Augmentation Graph
<u,v> <u,v> c<u,v>-F<u,v>
u v u v
w
0/c<v.u> F<u,v>+c<v,u>
Max Flow = Min Cut
+w +w
-w
+w

•Given Flow F
•Construct Augmenting Graph GF
•Find path P
•Let w be the max amount flow
can increase along path P.
•Increase flow along path P by w.
i.e newF = oldF + w × P
Max Flow = Min Cut
+w +w
-w
+w

•Given Flow F
•Construct Augmenting Graph GF
•Find path P
•Let w be the max amount flow
can increase along path P.
•Increase flow along path P by w.
i.e newF = oldF + w × P
Max Flow = Min Cut

•Given Flow F
•Construct Augmenting Graph GF
•Find path P using BFS, DFS,
or generic search algorithm
•No path
Max Flow = Min Cut

•Let Falg be this final flow.


•Let cut Calg=<U,V>,
•where U are the nodes reachable from s
in the augmented graph
•and V not.
•Claim: rate(Falg) = cap(Calg)
An Application: Matching
Sam Mary

Bob Beth 3 matches


Can we do better?
John Sue 4 matches
Fred Ann
Who loves whom.
Who should be matched with whom
so as many as possible matched
and nobody matched twice?
An Application: Matching

s t

1 1
u v
c<s,u> = 1
•Total flow out of u  flow into u  1
•Boy u matched to at most one girl.
c<v,t> = 1
•Total flow into v = flow out of v  1
•Girl v matched to at most one boy.
An Application: Matching
Flow New Flow

s t s t

Augmentation Graph Augmentation Path


Alternates
•adding edge
s t •removing edge
•adding edge
•removing edge
•adding edge
Extra edge added
An Application: Matching
Sam Mary

Bob Beth 3 matches


Can we do better?
John Sue 4 matches
Fred Ann
Who loves whom.
Who should be matched with whom
so as many as possible matched
and nobody matched twice?
Hill Climbing
Problems:
Can our Network Flow
Algorithm get stuck
in a local maximum? Global Max
No!

Local Max
Hill Climbing
Problems:
Running time?
If you take small step,
could be exponential time.
Network Flow
Network Flow

Add flow 1
Network Flow

Add flow 1
Hill Climbing
Problems:
Running time?
•If each iteration you take
the biggest step possible,
•Alg is poly time
• in number of nodes
• and number of bits in capacities.
• If each iteration you take
path with the fewest edges
•Alg is poly time
•in number of nodes
Taking the biggest step possible
R_t = MaxFlow - F_t F_{t+1} = F_t + increase

m * increase > R_{t+1} = R_t – increase


sum_cut augment < R_t - [R_t / m]
= sum_{e \in cut} C_e - F_e < (1-1/m)^t R_t
= value(cut_t) - F_t < (1-1/m)^t F_0
> min cut - F_t < (1-1/m)^t MaxFlow
> M_t < (1-1/m)^t sum_e C_e
Linear Programming
A Hotdog

A combination of pork,
grain, and sawdust, …

Constraints:
•Amount of moisture
•Amount of protein,
•…
The Hotdog Problem

Given today’s prices,


what is a fast algorithm

to find the cheapest


hotdog?
Abstraction
There are deep ideas within the simplicity.

=
Goal: Understand and think about complex
things in simple ways.

There are deep ideas within the simplicity.


Rudich www.discretemath.com
Abstract Out Essential Details

t
us
r
ain

wd
te
rk
gr
wa
sa
po
Amount to add: x 1 , x 2, x 3 , x 4
Cost: 29, 8, 1, 2
Cost of Hotdog: 29x1 + 8x2 + 1x3 + 2x4

Constraints: 3x1 + 4x2 – 7x3 + 8x4  12


•moisture 2x1 - 8x2 + 4x3 - 3x4  24
•protean, -8x1 + 2x2 – 3x3 - 9x4  8
•… x1 + 2x2 + 9x3 - 3x4  31
Abstract Out Essential Details

Minimize: 29x1 + 8x2 + 1x3 + 2x4

Subject to: 3x1 + 4x2 – 7x3 + 8x4  12


2x1 - 8x2 + 4x3 - 3x4  24
-8x1 + 2x2 – 3x3 - 9x4  8
x1 + 2x2 + 9x3 - 3x4  31
A Fast Algorithm

For decades people thought


that there was no fast
algorithm.

Minimize:

29x1 + 8x2 + 1x3 + 2x4
Then one was found!

Subject to: 3x1 + 4x2 – 7x3 + 8x4  12 Theoretical Computer Science


finds new algorithms every day.
2x1 - 8x2 + 4x3 - 3x4  24
-8x1 + 2x2 – 3x3 - 9x4  8
x1 + 2x2 + 9x3 - 3x4  31
Dual

Primal
End

You might also like