/
CS4102 Algorithms  Fall 2021 – Horton and CS4102 Algorithms  Fall 2021 – Horton and

CS4102 Algorithms Fall 2021 – Horton and - PowerPoint Presentation

morton
morton . @morton
Follow
342 views
Uploaded On 2022-02-24

CS4102 Algorithms Fall 2021 – Horton and - PPT Presentation

Floryan These are Hortons version of the slides used in his lecture Network Flow FordFulkerson 1 In your textbook CLRS 261 and 262 Includes simple solutions to the following complications ID: 909832

residual flow graph path flow residual path graph ford fulkerson augmenting edge algorithm network edges add capacity unit weight

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "CS4102 Algorithms Fall 2021 – Horton ..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

CS4102 Algorithms Fall 2021 – Horton and Floryan

These are Horton’s version of the slides, used in his lecture.Network Flow, Ford-Fulkerson

1

Slide2

In your textbookCLRS 26.1 and 26.2Includes simple solutions to the following “complications”What if (u,v) and (

v,u) are in the flow graph?Called “Antiparallel” edges – easy to adjust for this, example laterWhat if we need >1 source? >1 sink?

2

Slide3

Flow networks3Consider a flow network, which is a specialized directed graph with:A single source node sA single terminus node tCapacities on each edge

That must be integer!What is the maximum flow you can send from s to t?

Slide4

Applications4Transportation networksHow many people can be routed?Computer networksElectrical distributionWater distribution

Note that all these applications have multiple sources and multiple sinks!Whereas the flow networks we study do not, yet

Slide5

Flow NetworkGraph

Source node

Sink node

Edge Capacities

Positive whole* numbers

If

then

(Note our example here violates this!)

Max flow intuition: If

is a faucet,

is a drain, and

connects to

through a network of pipes with given capacities, what is the maximum amount of water which can flow from the faucet to the drain?

 

5

3

3

3

2

 

 

2

1

3

2

2

3

Slide6

Flow Network: Antiparallel EdgesEasy adjustment to remove antiparallel edges and have equivalent flow graph: add intermediate node(Note: our later examples use graph on the left without this adjustment.)

6

3

3

3

2

 

 

2

1

3

2

2

3

3

3

3

2

 

 

2

1

3

2

2

3

2

Slide7

1/

3

1/

3

2/

3

 

 

2/

2

2/

2

1/

1

2/

3

1/

2

1/

2

2/

3

Flow

Assignment of values to edges

E.g.

units of water going through that pipe

Capacity constraint

Flow cannot exceed capacity

Flow constraint

,

Water going in must match water coming out

Flow of

:

Net outflow of

 

7

Flow/

Capacity

3 in example above

Slide8

Let’s Make Some Rules8Source node has NO incoming flowTerminal (sink) node has NO outgoing flow

Internal nodes has net zero flowall units of flow going in must be going out as wellNo edge is over capacityGOAL: Find the maximum flow that can be “pushed” through the networkI.e. maximize:

 

Slide9

How to Solve This? This Greedy doesn’t work9

30

20

 

 

10

20

10

Saturate Highest Capacity Path First

Slide10

Greedy doesn’t work10

30

20

 

 

10

20

10

Saturate Highest Capacity Path First

Slide11

Greedy doesn’t work11

20/

30

20/

20

 

 

0/

10

20/

20

0/

10

Saturate Highest Capacity Path First

Overall Flow:

 

Slide12

Greedy doesn’t work12

10/

30

20/

20

 

 

10/

10

20/

20

10/

10

Better Solution

Overall Flow:

 

Slide13

13

Slide14

Ford-Fulkerson: Algorithm overview14Iterative algorithm: push some flow along some path at each stepModel or record the

residual capacitieshow much capacity is left after taking into account how much flow is going through that edge at this timeFind a path from s to t such that the minimum residual capacity of an edge on that path is greater than zeroSince each value is an integer, it must be 1 or more

Update the residual capacities after taking into account this new flow

Repeat until no more such paths are found

Slide15

Algorithm notation15f(u,v): the flow on the edge from u to vf(v,u

): the backflow on the edge from v to uc(u,v): the capacity on the edge from u to vcf(u,v): the residual

capacity on the edge from u to v

G

f

is the graph where the edges weights are the residual capacities

THIS is usually the graph we actually use when running the algorithm we are about to see.

Slide16

Backflow16Each edge has forward flow and backflowThe two must always be “inverses” of each other!I.e. they sum to the total capacity for that edgeThis allows for modeling of flow “returning” along a given edge

One way to think about this:How much of the forward flow we could “un-do”

Slide17

Residual Graph

 

Keep track of net available flow along each edge

Forward edges

”: weight is equal to

available flow

along that edge in the flow graph

Back edges

”: weight is equal to

backflow

along that edge in the flow graph

 

17

1/

3

1/

3

2/

3

 

a

b

 

2/

2

2/

2

1/

1

2/

3

1/

2

1/

2

2/

3

 

a

b

 

2

2

1

2

0

0

0

2

3

1

1

Flow Graph

 

1

2

2

1

2

1

Residual Graph

 

1

Flow I

could

add

Flow I

could

remove

Slide18

Residual Graphs Example

18

20/

30

20/

20

 

 

0/

10

20/

20

0/

10

Flow Graph

 

 

Residual Graph

10

0

0

10

10

20

0

20

0

20

10/

30

20/

20

 

 

10/

10

20/

20

10/

10

 

 

0

0

0

0

20

10

20

10

10

20

Slide19

Ford-Fulkerson Algorithm19

Define an augmenting path to be a path from

in the residual graph

(using edges of non-zero weight)

Overview: Repeatedly add the flow of any augmenting path

Ford-Fulkerson max-flow algorithm:

Initialize

for all

Construct the residual network

While there is an augmenting path

in

:

Let

Add

units of flow to

based on the augmenting path

Update the residual network

for the updated flow

 

Slide20

Define an augmenting path to be a path from

in the residual graph

(using edges of non-zero weight)

Overview: Repeatedly add the flow of any augmenting path

Ford-Fulkerson max-flow algorithm:

Initialize

for all

Construct the residual network

While there is an augmenting path

in

:

Let

Add

units of flow to

based on the augmenting path

Update the residual network

for the updated flow

 

Ford-Fulkerson Algorithm

20

Ford-Fulkerson approach:

take

any

augmenting path

(will revisit this later)

Slide21

Define an augmenting path to be a path from

in the residual graph

(using edges of non-zero weight)

Overview: Repeatedly add the flow of any augmenting path

Ford-Fulkerson max-flow algorithm:

Initialize

for all

Construct the residual network

While there is an augmenting path

in

:

Let

Add

units of flow to

based on the augmenting path

Update the residual network

for the updated flow

 

Ford-Fulkerson Algorithm

21

(

is the weight of edge

in the residual network

)

 

Ford-Fulkerson approach:

take

any

augmenting path

(will revisit this later)

Slide22

Ford-Fulkerson Algorithm:Updating Gf22

f(u,v) = 0 for all edges (u,v)While there is an “augmenting” path p from s to t in Gf such that

c

f

(

u,v

) > 0 for all edges (

u,v

)

p

Find

c

f

(p) = min{

cf(u,v) | (u,v)  p}For each edge (u,v)  pf(u,v) = f(u,v) + cf(p) send flow along the pathf(v,u) = f(v,u) - cf(p) send backflow the other way

Slide23

Ford-Fulkerson Example23

0

/

3

0

/

3

0

/

3

0

/

2

 

 

0

/

2

0

/

1

0

/

3

0

/

2

0

/

2

0

/

3

Initially:

for all

 

3

3

3

 

 

2

1

3

2

2

Residual graph

 

3

2

Slide24

Ford-Fulkerson Example24

0

/

3

0

/

3

0

/

3

0

/

2

 

 

0

/

2

0

/

1

0

/

3

0

/

2

0

/

2

0

/

3

3

3

 

 

2

1

3

2

2

Residual graph

 

Increase flow by 1 unit

3

3

2

Slide25

Ford-Fulkerson Example25

0

/

3

1

/

3

1

/

3

0

/

2

 

 

1

/

2

1

/

1

0

/

3

0

/

2

1

/

2

0

/

3

3

3

 

 

2

1

3

2

2

Residual graph

 

Increase flow by 1 unit

3

3

2

Slide26

Ford-Fulkerson Example26

0

/

3

1

/

3

1

/

3

0

/

2

 

 

1

/

2

1

/

1

0

/

3

0

/

2

1

/

2

0

/

3

2

2

 

 

1

3

2

1

1

1

1

1

1

Residual graph

 

3

3

2

Slide27

Ford-Fulkerson Example27

0

/

3

1

/

3

1

/

3

0

/

2

 

 

1

/

2

1

/

1

0

/

3

0

/

2

1

/

2

0

/

3

2

2

 

 

1

3

2

1

1

1

1

1

1

Residual graph

 

Increase flow by 1 unit

3

3

2

Slide28

Ford-Fulkerson Example28

0

/

3

2

/

3

1

/

3

0

/

2

 

 

2

/

2

1

/

1

0

/

3

0

/

2

1

/

2

1

/

3

2

2

 

 

1

3

2

1

1

1

1

1

1

Residual graph

 

Increase flow by 1 unit

3

3

2

Slide29

Ford-Fulkerson Example29

0

/

3

2

/

3

1

/

3

0

/

2

 

 

2

/

2

1

/

1

0

/

3

0

/

2

1

/

2

1

/

3

1

2

 

 

3

2

1

2

2

1

1

1

2

1

Residual graph

 

Increase flow by 1 unit

3

2

Slide30

Ford-Fulkerson Example30

0

/

3

2

/

3

1

/

3

0

/

2

 

 

2

/

2

1

/

1

0

/

3

0

/

2

1

/

2

1

/

3

Residual graph

 

1

2

 

 

3

2

1

2

2

1

1

1

2

1

3

2

Slide31

Ford-Fulkerson Example31

0

/

3

2

/

3

1

/

3

1

/

2

 

 

2

/

2

0

/

1

0

/

3

0

/

2

1

/

2

2

/

3

Residual graph

 

1

2

 

 

3

2

1

2

2

1

1

1

2

1

Increase flow by 1 unit

3

2

Slide32

Ford-Fulkerson Example32

0

/

3

2

/

3

1

/

3

1

/

2

 

 

2

/

2

0

/

1

0

/

3

0

/

2

1

/

2

2

/

3

Residual graph

 

1

2

 

 

3

2

1

1

2

1

1

1

2

2

Increase flow by 1 unit

3

1

1

Slide33

Ford-Fulkerson Example33

0

/

3

2

/

3

1

/

3

1

/

2

 

 

2

/

2

0

/

1

0

/

3

0

/

2

1

/

2

2

/

3

Residual graph

 

1

2

 

 

3

2

1

1

2

1

1

1

2

2

3

1

1

Slide34

Ford-Fulkerson Example34

0

/

3

2

/

3

2

/

3

2

/

2

 

 

2

/

2

0

/

1

0

/

3

0

/

2

2

/

2

2

/

3

Residual graph

 

1

2

 

 

3

2

1

1

2

1

1

1

2

2

Increase flow by 1 unit

3

1

1

Slide35

Ford-Fulkerson Example35

0

/

3

2

/

3

2

/

3

2

/

2

 

 

2

/

2

0

/

1

0

/

3

0

/

2

2

/

2

2

/

3

Residual graph

 

1

1

 

 

3

2

1

2

1

2

2

2

2

3

2

Slide36

Ford-Fulkerson Example36

0

/

3

2

/

3

2

/

3

2

/

2

 

 

2

/

2

0

/

1

0

/

3

0

/

2

2

/

2

2

/

3

Residual graph

 

No more augmenting paths

1

1

 

 

3

2

1

2

1

2

2

2

2

3

2

Maximum flow:

4

Slide37

Our example37

30

20

 

 

10

20

10

Slide38

Define an augmenting path to be a path from

in the residual graph

(using edges of non-zero weight)

Overview: Repeatedly add the flow of any augmenting path

Ford-Fulkerson max-flow algorithm:

Initialize

for all

Construct the residual network

While there is an augmenting path

in

:

Let

Add

units of flow to

based on the augmenting path

Update the residual network

for the updated flow

 

Ford-Fulkerson Algorithm - Runtime

38

Time to find an augmenting path:

Number of iterations of While loop:

Slide39

Define an augmenting path to be a path from

in the residual graph

(using edges of non-zero weight)

Overview: Repeatedly add the flow of any augmenting path

Ford-Fulkerson max-flow algorithm:

Initialize

for all

Construct the residual network

While there is an augmenting path

in

:

Let

Add

units of flow to

based on the augmenting path

Update the residual network

for the updated flow

 

Ford-Fulkerson Algorithm - Runtime

39

Time to find an augmenting path:

 

Number of iterations of While loop:

 

 

Slide40

What type of search?40“While there is an augmenting path

in ”

Using a depth-first search is the Ford-Fulkerson algorithm

Each augmenting path can be found in O(E) time

And there can be

|𝑓|

paths

So the running time is O

(𝐸⋅|𝑓|)

Will not terminate with irrational edge values

Using a breadth-first search is the Edmonds-Karp algorithm

Runs in O(V

E

2

)Total number of augmentations is O(V⋅E)And finding each augmentation takes O(E)Guaranteed termination with irrational edge valuesRun-time is independent of the maximum flow of the graph