Applications of Network Flows

Applications of Network Flows
Image Segmentation
Image Segmentation
Image Segmentation
http://compression.ru/video/segmentation/index_en.html
Problem Statement I
Foreground/background determination:
• Image with n pixels.
• Foreground “belief” ai , background “belief” bi for each pixel
Assign pixels as foreground/background to align with belief.
Continuity
F
B
F
B
F
B
F
B
F
Problem Statement II
Foreground/background determination:
• Image with n pixels.
• Foreground “belief” ai , background “belief” bi for each pixel
• Neighborhood relationship pij ≥ 0 for pixels i and j
Assign pixels as foreground/background to align with belief while
preserving continuity as far as possible
Formalization
• Let P be set of pixels
• Let the solution A ⊆ P be set of “foreground pixels”, B = P \ A
We want to:
• Maximize belief for foreground: ∑i∈A ai
Formalization
• Let P be set of pixels
• Let the solution A ⊆ P be set of “foreground pixels”, B = P \ A
We want to:
• Maximize belief for foreground: ∑i∈A ai
• Maximize belief for background: ∑j∈B bj
Formalization
• Let P be set of pixels
• Let the solution A ⊆ P be set of “foreground pixels”, B = P \ A
We want to:
• Maximize belief for foreground: ∑i∈A ai
• Maximize belief for background: ∑j∈B bj
• Minimize discontinuties: ∑A∩{i,j}=1 pij
Formalization
• Let P be set of pixels
• Let the solution A ⊆ P be set of “foreground pixels”, B = P \ A
We want to:
• Maximize belief for foreground: ∑i∈A ai
• Maximize belief for background: ∑j∈B bj
• Minimize discontinuties: ∑A∩{i,j}=1 pij
Maximize F(A) = ∑i∈A ai + ∑j∈B bj − ∑A∩{i,j}=1 pij
Flow Formulation ?
, We want a set, so maybe it’s a cut
Flow Formulation ?
, We want a set, so maybe it’s a cut
/ But we’re maximizing, not minimizing
Flow Formulation ?
, We want a set, so maybe it’s a cut
/ But we’re maximizing, not minimizing
/ Our graph is undirected, not directed
Flow Formulation ?
,
/
/
/
We want a set, so maybe it’s a cut
But we’re maximizing, not minimizing
Our graph is undirected, not directed
We have no edge capacities
Flow Formulation ?
,
/
/
/
/
We want a set, so maybe it’s a cut
But we’re maximizing, not minimizing
Our graph is undirected, not directed
We have no edge capacities
We have no source or sink
Max vs Min
Let Q = ∑i (ai + bi ) Then
F(A) =
∑ ai + ∑ bj −
i∈A
=
∑
j∈B
i∈A∪B
ai − ∑ ai +
i∈B
= Q − ∑ ai −
i∈B
= Q − G(A)
∑
∑
i∈A∪B
∑ bi −
i∈A
pij
A∩{i,j}=1
bi −
∑
∑ bi −
i∈A
A∩{i,j}=1
pij
∑
A∩{i,j}=1
pij
Max vs Min
Let Q = ∑i (ai + bi ) Then
F(A) =
∑ ai + ∑ bj −
i∈A
=
∑
j∈B
i∈A∪B
ai − ∑ ai +
i∈B
= Q − ∑ ai −
i∈B
∑
∑
i∈A∪B
∑ bi −
i∈A
pij
A∩{i,j}=1
bi −
∑
∑ bi −
i∈A
∑
A∩{i,j}=1
pij
A∩{i,j}=1
= Q − G(A)
Maximizing F(A) ≡ minimizing G(A)
pij
Flow Formulation ?
,
,
/
/
/
We want a set, so maybe it’s a cut
We can now minimize...
Our graph is undirected, not directed
We have no edge capacities
We have no source or sink
Other Problems
• Replace each undirected edge by two directed edges
pij
Other Problems
• Replace each undirected edge by two directed edges
pij
pij
• Assign all edge capacities as pij
Other Problems
• Replace each undirected edge by two directed edges
pij
pij
• Assign all edge capacities as pij
• Connect source and sink to all vertices
Flow Formulation ?
,
,
,
,
,
We want a set, so maybe it’s a cut
We can now minimize...
Our graph is now directed
We have edge capacities
We have source and sink
Flow Formulation ?
,
,
,
,
,
We want a set, so maybe it’s a cut
We can now minimize...
Our graph is now directed
We have edge capacities
We have source and sink
But what about capacities from source, and to sink ?
Capacities
We want to minimize Q(A) = ∑i∈B ai + ∑i∈A bi + ∑A∩{i,j}=1 pij
s
A
t
B
Capacities
We want to minimize Q(A) = ∑i∈B ai + ∑i∈A bi + ∑A∩{i,j}=1 pij
s
A
t
B
P
A∩{i,j}=1 pij
Capacities
We want to minimize Q(A) = ∑i∈B ai + ∑i∈A bi + ∑A∩{i,j}=1 pij
s
A
t
B
P
A∩{i,j}=1 pij
P
+ i∈B ai
Capacities
We want to minimize Q(A) = ∑i∈B ai + ∑i∈A bi + ∑A∩{i,j}=1 pij
s
A
t
B
P
A∩{i,j}=1 pij
P
+ i∈B ai
P
+ i∈A bi = Q
Review
1
One node for each pixel
Review
1
One node for each pixel
2
Two directed edges for each edge, capacity pij
Review
1
One node for each pixel
2
Two directed edges for each edge, capacity pij
3
Edges from source to each pixel (capacity ai )
Review
1
One node for each pixel
2
Two directed edges for each edge, capacity pij
3
Edges from source to each pixel (capacity ai )
4
Edges from each pixel to sink (capacity bi )
Min Cut = Foreground
s
A
t
B
Interval Scheduling
Time
Greedy algorithm yields optimal solution.
Weighted Interval Scheduling
Time
Dynamic programming yields optimal solution.
Airline Scheduling
Given:
• Collection of lucrative routes (orig,dest,start-time,duration)
• k planes
• Additional routes
Rules:
• All flights must be serviced
• A plane can be used for flights i and j if
• it’s in the right place, and there’s enough gap in time between flights OR
• it can get from dest (i) to orig(j) in time (maybe using an additional route)
Question:
Are k planes sufficient to traverse all routes ?
Example
LAS 5 SEA 6
BOS 6 DCA 7
DCA 8
LAX 11
SF0 2:15
PHL 7
PIT 8
PHL 11
SFO 2
SEA 3:15
Example
LAS 5 SEA 6
BOS 6 DCA 7
DCA 8
LAX 11
SF0 2:15
PHL 7
PIT 8
PHL 11
SFO 2
SEA 3:15
Example
LAS 5 SEA 6
BOS 6 DCA 7
DCA 8
LAX 11
SF0 2:15
PHL 7
PIT 8
PHL 11
SFO 2
SEA 3:15
Example
LAX 12
BOS 6 DCA 7
DCA 8
LAS 1
LAS 5 SEA 6
LAX 11
SF0 2:15
PHL 7
PIT 8
PHL 11
SFO 2
SEA 3:15
Example
LAX 12
BOS 6 DCA 7
DCA 8
LAS 1
LAS 5 SEA 6
LAX 11
SF0 2:15
PHL 7
PIT 8
PHL 11
SFO 2
SEA 3:15
Example
LAX 12
BOS 6 DCA 7
DCA 8
LAS 1
LAS 5 SEA 6
LAX 11
SF0 2:15
PHL 7
PIT 8
PHL 11
SFO 2
SEA 3:15
Example
LAX 12
BOS 6 DCA 7
DCA 8
LAS 1
LAS 5 SEA 6
LAX 11
SF0 2:15
PHL 7
PIT 8
PHL 11
SFO 2
SEA 3:15
Flow Formulation ?
• The problem is of feasibilty - maybe we need a circulation
Flow Formulation ?
• The problem is of feasibilty - maybe we need a circulation
• Planes “flow” from route to route: route = edge, plane = flow
Flow Formulation ?
• The problem is of feasibilty - maybe we need a circulation
• Planes “flow” from route to route: route = edge, plane = flow
• Route must be traversed = lower bound on flow
Flow Formulation ?
• The problem is of feasibilty - maybe we need a circulation
• Planes “flow” from route to route: route = edge, plane = flow
• Route must be traversed = lower bound on flow
• Only one plane per route = unit capacity on edge
Flow Formulation ?
• The problem is of feasibilty - maybe we need a circulation
• Planes “flow” from route to route: route = edge, plane = flow
• Route must be traversed = lower bound on flow
• Only one plane per route = unit capacity on edge
• Planes (flow) starts in morning, ends at night =⇒ source = morning,
sink = night
Flow Formulation ?
• The problem is of feasibilty - maybe we need a circulation
• Planes “flow” from route to route: route = edge, plane = flow
• Route must be traversed = lower bound on flow
• Only one plane per route = unit capacity on edge
• Planes (flow) starts in morning, ends at night =⇒ source = morning,
sink = night
• Two routes are connected if we can get to one from the other
Getting The Schedule
LAS 5 SEA 6
BOS 6 DCA 7
DCA 8
LAX 11
SF0 2:15
s
PHL 7
PIT 8
PHL 11
SFO 2
SEA 3:15