31 Intro Flows

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

Maximum Flows

Dr. Shahbaz Khan


Department of Computer Science and Engineering,
Indian Institute of Technology Roorkee
shahbaz.khan@cs.iitr.ac.in
Incremental Improvements Paradigm

● Divide and conquer

● Dynamic Programming

● Greedy Algorithms

● Incremental improvements

2
Network Flows

Recall Kirchoff’s law


For any node total incoming current is equal to outgoing current.

Flow is defined similarly: img src: wiki

Each edge (u,v) carries a flow f(u,v)


For any node x incoming flow is equal to outgoing flow
Sum of flow f( - , x) = Sum of flow f(x, - )
[Conservation of Flow]

Except sources (no incoming flow) and sinks (no outgoing flow)
4
Network Flows

Flow:
Each edge (u,v) carries a flow f(u,v)
For any node x incoming flow is equal to outgoing flow
Sum of flow f( - , x) = Sum of flow f(x, - )
[Conservation of Flow]

Except sources (no incoming flow) and sinks (no outgoing flow)

s t

[INTERPRETATION]
Sum of flow f(s, - ) ? Sum of flow f( - , t)
5
Network Flows

Flow is defined similarly:


Each edge (u,v) carries a flow f(u,v)
For any node x incoming flow is equal to outgoing flow
Sum of flow f( - , x) = Sum of flow f(x, - )
Except sources and sinks [Conservation Constraint]

Constrained Flow:
Each edge has a capacity c(x,y),
such that f(x,y) <= c(x,y) [Capacity Constraint]

6
Maximum Flow Graph

Given a graph G(V,E) with capacity c(u,v) on each edge (u,v).


Find maximum flow from s to t such that:

● For any node x!=s,t incoming flow is equal to outgoing flow


Sum of flow f( - , x) = Sum of flow f(x, - ) [Conservation C.]
● For any edge f(x,y) <= c(x,y) [Capacity C.]

img src: geeksforgeeks

7
Maximum Flow Graph

Given a graph G(V,E) with capacity c(u,v) on each edge (u,v).


Find maximum flow from s to t such that:

● For any node x!=s,t incoming flow is equal to outgoing flow


Sum of flow f( - , x) = Sum of flow f(x, - ) [Conservation C.]
● For any edge f(x,y) <= c(x,y) [Capacity C.]

img src: geeksforgeeks


UNIT CAPACITY MAXIMUM FLOW???
8
Maximum Flow Simple Algorithm

If there exist a s-t path, push maximum possible flow through it.

img src: geeksforgeeks

9
Maximum Flow Simple Algorithm

If there exist a s-t path, push maximum possible flow through it.

img src: geeksforgeeks

10
Ford Fulkerson Algorithm

Algorithm:
● Initialize all f(u,v) to zero
● While (s-t path P exist in residual graph) // Augmenting Path
○ Push bottle neck capacity flow f along the path P
○ Update Residual Graph by adding reverse edges with
bottle-neck capacity.

Residual Graph: For every (u,v) add a (v,u) with c(v,u)=f(u,v).


If flow f is passed along a path:
For all forward edges (u,v) => f(u,v)= f(u,v)+f
c(v,u)=c(u,v)+f
For all reverse edges (v,u) => f(u,v) = f(u,v)-f
c(v,u) = c(u,v)-f

Examples? Complexity?
img src: geeksforgeeks

12
Ford Fulkerson Algorithm (Examples)

Algorithm:
● Initialize all f(u,v) to zero
● While (s-t path P exist in residual graph) // Augmenting Path
○ Push bottle neck capacity flow f along the path P
○ Update Residual Graph by adding reverse edges with
bottle-neck capacity.
For all forward edges (u,v) => f(u,v)= f(u,v)+f
c(v,u)=c(u,v)+f
For all reverse edges (v,u) => f(u,v) = f(u,v)-f
c(v,u) = c(u,v)-f

img src: geeksforgeeks

14
Ford Fulkerson Algorithm

Algorithm:
● Initialize all f(u,v) to zero
● While (s-t path P exist in residual graph) // Augmenting Path
○ Push bottle neck capacity flow f along the path P
○ Update Residual Graph by adding reverse edges with
bottle-neck capacity.

Residual Graph: For every (u,v) add a (v,u) with c(v,u)=f(u,v).


If flow f is passed along a path:
For all forward edges (u,v) => f(u,v)= f(u,v)+f
c(v,u)=c(u,v)+f
For all reverse edges (v,u) => f(u,v) = f(u,v)-f
c(v,u) = c(u,v)-f

Complexity?

15
Ford Fulkerson Algorithm

Algorithm:
● Initialize all f(u,v) to zero
● While (s-t path P exist in residual graph) // Augmenting Path
○ Push bottle neck capacity flow f along the path P
○ Update Residual Graph by adding reverse edges with
bottle-neck capacity.

Complexity?

Unit Capacity:

Integral Case:

General Case:
img src: geeksforgeeks

16
Ford Fulkerson Algorithm

INTEGRALITY:
Integer Capacities=>Integer Bottle-neck capacity=>Integer capacities

Worst Case on Integers:

1000 1000

1000 1000

img src: wiki

17
Ford Fulkerson Algorithm

Problem with Real Numbers:

https://cs.stackexchange.com/questions/92875/does-minimum-cost-flow-problem-work-
for-real-valued-edge-weights-costs
18
Ford Fulkerson Algorithm

Algorithm:
● Initialize all f(u,v) to zero​
● While (s-t path P exist in residual graph) // Augmenting Path
○ Push bottle neck capacity flow along the path P
○ Update Residual Graph by adding reverse edges with
bottle-neck capacity.

Correctness?

Does it always work?

Polynomial Time?

Can we have polynomial time algorithm?

img src: geeksforgeeks

19

You might also like