Download presentation
Presentation is loading. Please wait.
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 What is the smallest combined weight of edges we’d have to cut to separate the source from the sink? This is computed as 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 the reachable set to the non-reachable set. The cut weight will equal the max flow!
20
Results after Max Flow – reachable from source
1 Not Reachable 1 3 10 9 1 6 2 7 10 9 1 Reachable 9
21
Edges to cut are those from reachable to non-reachable – weight is same as max flow (19)
Not Reachable 4 10 10 2 8 6 10 10 9 Edges from Reachable to Not Reachable Reachable
22
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.