faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/datastructures/max… · web vieweach edge...

15
Flow Networks and Simple Max Flow Flow Network Suppose you have a directed graph G starting with vertex “s” (called the source) and ending with vertex “t” (called the sink) Each edge has its own capacity, or how much it can carry/transport at one time, and a flow, the amount currently flowing through it o non-negative Flow cannot exceed capacity At every vertex (excluding your source s and your sink t), the flow coming in must equal the flow going out Theory and Problem How much can you send from source s to sink t? o this is known as maximum flow bottlenecks are important You can’t send more into a vertex than can come out, and vice-versa o maximum-flow on each path is determined by the edge with the lowest capacity Sample Directed Graph with Flow 1

Upload: others

Post on 16-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

Flow Networks and Simple Max FlowFlow Network

Suppose you have a directed graph G starting with vertex “s” (called the source) and ending with vertex “t” (called the sink)

Each edge has its own capacity, or how much it can carry/transport at one time, and a flow, the amount currently flowing through ito non-negative

Flow cannot exceed capacity At every vertex (excluding your source s and your sink t), the flow coming in

must equal the flow going out

Theory and Problem How much can you send from source s to sink t?

o this is known as maximum flow bottlenecks are important You can’t send more into a vertex than can come out, and vice-versa

o maximum-flow on each path is determined by the edge with the lowest capacity

Sample Directed Graph with Flow

1

Page 2: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

The Ford-Fulkerson Algorithm in General Flow starts equal to 0 While there exists an “augmenting path” (just a path from s to t)

o Find an augmenting patho Compute the bottleneck capacityo Increase flow on that path by bottleneck capacity

Runtime is O(E * F)o E is the number of edges on the grapho F is the maximum flow

Flow/Capacity for each edge. Remember, Flow CANNOT EXCEED Capacity

Sample Problem

2

Page 3: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

Bottleneck of 10, flow along this path is 10.Current flow: 0 + 10 = 10

Bottleneck of 5, flow along this path is 5.Current flow: 10 + 5 = 15

Edge from B to T is filled to capacity.This path has 0 flow (left).There are no more paths to search so we are finished.Our final maximum flow for this graph is 15.

3

Page 4: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

Ford-Fulkerson Algorithm in detail basic algorithm to determine maximum flow in a flow network

o Find (list) all path from “s” to “t” (called augmented paths)o max allowed = 0 (go over why in a moment)o For each path found

find max allowed capacity in entire path look for the smallest capacity in the entire path

total sums of max allowed update flow on graph with max capacity for all edges in this

specific path watch for capacity limit, cannot go over limit

Ford-Fulkerson Max Flow Step by Step

Determine all (augmented) paths from source (s) to sink (t)

s a ts c ts a b ts c b ts a b c ts c b a t

4

Page 5: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

Foreach path, find max capacity, update graph

path max cap. notes a t 7

path max cap. notes a t 7s c t 25

5

Page 6: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

path max cap. notes a t 7s c t 25s a b t 4 BUT only 3 left in capacity (s a)

path max cap. notes a t 7s c t 25s a b t 4 BUT only 3 left in capacity (s a)s a b c t 4 s a maxed out!!

6

Page 7: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

path max cap. notes a t 7s c t 25s a b t 4 BUT only 3 left in capacity (s a)s a b c t 4 s a maxed out!!s c b t 4

7

Page 8: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

path max cap. notes a t 7s c t 25s a b t 4 BUT only 3 left in capacity (s a)s a b c t 4 s a maxed out!!s c b t 4s c b a t 4 c b maxed out!!

Done with every path (or paths connected directly to source/sink maxed)

Max allowed = 7 + 25 + 3 + 4 = 39

8

Page 9: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

Try the flow graphs below: Answersb:

#1

#2

9

Page 10: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

Maximum Flow Algorithm Application Airline Scheduling

o National airline carriers every day need to worry about calculating routes for the most efficient flying

o These include maximizing efficiency of Equipment usage crew allocation

speed customer satisfaction (whatevs)

o Plan for unpredictable circumstances such as equipment failure or weather

Running time is determined byo O(k) nodes and O(k^2)edges

K = number of flightso At most k crews neededo Solve k max flow problemso Arc capacities between 0 and ko At most k augmentations per max flow computationo Overall time = O(k^4)

10

Page 11: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

The solution is a useful technique for efficient re-use of limited resources but trivializes real airline scheduling problems.

Flow techniques are great for solving airline scheduling problems. It is typically a complex and difficult problem to solve for airline efficiency.

11

Page 12: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

AnswerMax Flow Exercises

Exercise #1

path max cap. notes a b t 3s c d t 10s a b c d t 5 BUT only 2 left in capacity (a b)

Maximum flow is = 3 + 10 + 2 = 15.

Exercise #2

Maximum flow is 31.

12

Page 13: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/DataStructures/Max… · Web viewEach edge has its own capacity, or how much it can carry/transport at one time, and a flow,

Sources Chang Chen & Jonathan Malar Presentation https://www.youtube.com/watch?v=hmIrJCGPPG4 https://www.youtube.com/watch?v=LfbKwot9sZA “The Standard Maximum Flow Problem” topCoder. n.d. Web. 6 May 2014.

<http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=maxFlow>

13