Presentation is loading. Please wait.

Presentation is loading. Please wait.

Network Flow.

Similar presentations


Presentation on theme: "Network Flow."— Presentation transcript:

1 Network Flow

2 Graph for Network Flow Source(s) – nodes with no incoming edge
Sink(s) – nodes with no outgoing edge Edges in graph – no parallel edges Indicate maximum capacity that can flow through that edge Could be directed or not Max Flow: what is the maximum amount that can flow from the source to the sink? Min Cut: what is a cut through edges to partition the graph into two, where the sum of cut edges is minimized?

3 Floyd Fulkerson Max Flow Algorithm
Basic idea: Find a path from source to sink Find minimum edge weight on that path Reduce all edges on path by that weight, add that amount to total flow BUT, this greedy strategy does not completely work! So, each time we reduce edge weights, we add (or increase weight of) a reverse edge showing “residual” capacity i.e. how much capacity could flow backward along that edge compared to best so far Now, can follow algorithm to completion

4 Max Flow: 19 4 10 10 2 8 6 10 10 9 Example from course found at algo.is

5 Greedy only (no new back edges)
Total Flow: 0 4 10 10 2 8 6 10 10 9

6 Greedy only (no new back edges)
Total Flow: 8 4 10 2 2 6 2 10 9

7 Greedy only (no new back edges)
Total Flow: 8 4 10 2 2 6 2 10 9

8 Greedy only (no new back edges)
Total Flow: 10 4 10 6 10 7

9 Greedy only (no new back edges)
Total Flow: 10 4 10 6 10 7

10 Greedy only (no new back edges)
Total Flow: 16 We are stuck, but max was 19! 4 4 4 1

11 Floyd Fulkerson Total Flow: 0 4 10 10 2 8 6 10 10 9

12 Floyd Fulkerson Total Flow: 8 4 10 2 8 2 6 8 8 2 10 9

13 Floyd Fulkerson Total Flow: 10 4 10 10 2 6 8 10 10 7 2

14 Floyd Fulkerson Total Flow: 16 4 4 10 6 2 6 8 10 6 4 1 8

15 Floyd Fulkerson Total Flow: 18 2 2 2 10 8 6 2 8 10 8 2 1 8

16 Floyd Fulkerson Total Flow: 19 1 1 3 10 9 1 6 2 7 10 9 1 9

17 Creating good implementations
Want to try to pick good paths, or it can take a while to solve Fewest number of edges (Floyd Fulkerson) Large bottleneck capacity For bottleneck (wanting “good” but not “best” route): Can keep a “scale” factor: eliminate all edges from the residual graph that have weight less than the scale factor. Ensures only paths that are “large enough” are found. Decrease scale factor (e.g. by factor of 2) if nothing found – eventually scale gets down to 1 (minimum edge capacity), so you are solving the whole thing.

18 Edmonds Karp: Improving Floyd Fulkerson
Idea is to use BFS to find the fewest edges needed to get from source to sink. Avoids problems where you follow the same link in opposite direction each time (and only increase flow by a small amount) will tend to get more flow more quickly Only needs to be run O(VE) times See book for an implementation Another improvement: Dinic’s Algorithm

19 Min Cut A byproduct of Max Flow
After computing max flow, the set of vertices reachable from source is one set, the remainder are the other set The min cut is all edges from one set to the other. It will equal the max flow!

20 Variations: Multi-source/multi-sink Vertex capacities
Create a “super source” and “super sink” that have edges going to all sources or from all sinks. Capacity of these is infinite Then, just run from super-source to super-sink Vertex capacities If limits at the vertices, split vertices in two, A and B A gets all incoming edges B gets all outgoing edges One edge from A to B with capacity equal to vertex capacity

21 Flow graph modeling Often, recognizing a task as network flow is biggest challenge. Example: Some number of users brings a set of applications (label ‘A’ to ‘Z’) to be run. There are 10 computers that can run applications (1 per day). Applications can only run on certain computers Create nodes for each application, each computer Create single source and single sink Create edge from source to each application node Set weight as the number of that application submitted by users Create edge from application node to computer nodes that can run it Weight can be 1, since only 1 program can run per computer Create edge from computer nodes to the sink Weight is 1, since each can run one program.

22 Another example (UVA problem 11380) – Titanic sinking
Grid of values: water (impassible) – ice with a person on it (will disappear once they leave), ice a person can move to (but will sink once they leave), iceberg (can hold people but not permanently), large wood (can hold people for safety, but only limited number) Create graph connecting adjacent nodes, high edge capacity Set node capacity for ice to 1 Create a source to all nodes with starting people (high edge weight) Create a sink from all wood nodes with weight equal to max. wood capacity.


Download ppt "Network Flow."

Similar presentations


Ads by Google