Download presentation
Presentation is loading. Please wait.
Published byCameron May Modified over 8 years ago
1
Announcements Finish up Network Flow today Then Review for Final on Monday ◦ HW#5 is due on Monday, let me or the TA’s know if you have trouble starting. The Final is one week from Monday 12/13 at 4pm – 6:50pm in this room. Review Material has been posted ◦ Topics, Questions and Answers (some of the answers are unfinished – I will try to finish these up and re-post soon) ◦ Remo’s Review Notes – very detailed, very good resource.
2
Network Flow The Maximum Flow Problem and The Ford-Fulkerson Algorithm
3
Network Flow The network flow problem is as follows: ◦ Given a connected directed graph G with non-negative integer weights, (where each edge stands for the capacity of that edge), ◦ 2 different vertices, s and t, called the source and the sink, such that the source only has out- edges and the sink only has in- edges, ◦ Find the maximum amount of some commodity that can flow through the network from source to sink. a s c b d t Each edge stands for the capacity of that edge. 12 16 9 4 10 14 7 20 4
4
Network Flow One way to imagine the situation is imagining each edge as a pipe that allows a certain flow of a liquid per second. ◦ The source is where the liquid is pouring from, and the sink is where it ends up. ◦ Each edge weight specifies the maximal amount of liquid that can flow through that pipe per second. ◦ Given that information, what is the most liquid that can flow from source to sink per second, in the steady state? a s c b d t Each edge stands for the capacity of that edge. 12 16 9 4 10 14 7 20 4
5
Network Flow ◦ Residual capacity – is simply an edge’s unused capacity. ◦ Augmenting path – defined as one where you have a path from the source to the sink where every edge has a non-zero residual capacity. a s c b d t 0/12 0/16 0/9 0/4 0/10 0/14 0/7 0/20 0/4 0/13 Using the notation: used / capacity. Residual Capacity: capacity - used.
6
Network Flow ◦ Find the Maximum Flow if the Network: a s c b d t 12 16 9 4 10 14 7 20 43
7
Ford-Fulkerson Algorithm While there exists an augmenting path Add the appropriate flow to that augmenting path So we’re going to arbitrarily choose an the augmenting path s,c,d,t in the graph below: ◦ And add the flow to that path. a s c b d t 0/12 0/16 0/9 0/4 0/10 0/14 0/7 0/20 0/4 0/13 ◦ Residual capacity of a path – the minimum of the residual capacities of the edges on that path. ◦ 4 in this case, which is the limiting factor for this path’s flow. 4/14 4/4 4/13
8
Ford-Fulkerson Algorithm We can represent the flow taken with back-edges in a Residual Graph. ◦ This will allow us to “undo” or redistribute the flow we have already taken. ◦ So flow taken is a back edge, and any residual flow is a forward edge. a s c b d t 12 16 9 10 7 20 4 9 4 4 Residual Graph: Next choice for augmenting path: s, a, b, t
9
Ford-Fulkerson Algorithm While there exists an augmenting path Add the appropriate flow to that augmenting path Choose another augmenting path ( one where you have a path from the source to the sink where every edge has a non-zero residual capacity.) ◦ s,a,b,t a s c b d t 12 9 10 7 12 4 9 4 4 Residual Graph: 8 4 4 Next choice for augmenting path: s, c, d, b, t
10
Ford-Fulkerson Algorithm While there exists an augmenting path Add the appropriate flow to that augmenting path Choose another augmenting path ( one where you have a path from the source to the sink where every edge has a non-zero residual capacity.) ◦ s,c, d, b, t Residual Graph: a s c b d t 12 9 10 3 7 19 4 2 11 1 4 4 Are there any more augmenting paths? No! We’re done The maximum flow = 19 + 4 = 23
11
Examples on the Board…
12
Example In a department there are n courses and m instructors. Every instructor has a list of courses he or she can teach. Every instructor can teach at most 3 courses during a year. The goal: find an allocation of courses to the instructors subject to these constraints.
13
Network Flow – Optional Homework Problem An orchestra is trying to fill all of its positions. For different instruments, it needs a different number of players. ◦ For example, it might need 20 violinists but only 3 trumpet players. Each potential candidate for the orchestra can play some set of instruments. ◦ For example, one player might be able to play either a violin or a viola, while another might be able to play a trumpet, trombone or tuba. Given the following information: a)A list of how many of each position the orchestra needs. b)A list of each candidate and which instruments they can play. Determine whether or not the orchestra can fill all its positions. Describe how to solve this problem using network flow.
14
Ford-Fulkerson Algorithm - Runtime While there exists an augmenting path Add the appropriate flow to that augmenting path We can check the existence of an augmenting path by doing a graph traversal on the network (with all full capacity edges removed.) ◦ This graph, a subgraph with all edges of full capacity removed is called a residual graph. It is difficult to analyze the true running time of this algorithm because it is unclear exactly how many augmenting paths can be found in an arbitrary flow network. ◦ In the worst case, each augmenting path adds 1 to the flow of a network, and each search for an augmenting path takes O(E) time, where E is the number of edges in the graph. ◦ Thus, at worst-case, the algorithm takes O(|f|E) time, where |f| is the maximal flow of the network.
15
Edmonds-Karp Algorithm This algorithm is a variation on the Ford- Fulkerson method which is intended to increase the speed of the first algorithm. The idea is to try to choose good augmenting paths. ◦ In this algorithm, the augmenting path suggested is the augmenting path with the minimal number of edges. (We can find this using BFS, since this finds all paths of a certain length before moving on to longer paths.) ◦ The total number of iterations of the algorithm using this strategy is O(VE). Thus, its total running time is O(VE 2 ).
16
Maximum Bipartite Matching A bipartite graph – one whose vertices can be split in two sets such that there is no edge connecting vertices in the same set. A matching in a graph is a set of edges such that no vertex is touched by more than one edge. A maximum matching is a matching with max cardinality (the most edges). Rob Joe Bob Mark Tom A B C D E
17
Maximum Bipartite Matching A bipartite graph – one whose vertices can be split in two sets such that there is no edge connecting vertices in the same set. A matching in a graph is a set of edges such that no vertex is touched by more than one edge. A maximum matching is a matching with max cardinality (the most edges). Rob Joe Bob Mark Tom A B C D E
18
Maximum Bipartite Matching A bipartite graph can be built with one set of vertices for employees and the other for jobs to be done. Then the problem of matching employees to jobs can be solved by assigning a source and sink, and determining the max flow. Rob Joe Bob Mark Tom A B C D E s t
19
Rob Joe Bob Mark Tom A B C D E s t 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Each employee can do 1 job: Each employee is able to do only certain jobs: Each job can only be filled by at most 1 employee:
20
Network Flow Consider a network flow problem where the goal was to figure out how to change the capacities to increase the maximum flow in the network. ◦ This might be applicable if you wanted to get a greater throughput of data in a network and you wanted to figure out where in the network you needed to add a router that could handle more data per unit of time.
21
Network Flow How to increase the maximum flow of a network. ◦ Let’s say you restrict your search in your network (that is already at max flow) to paths that have at most one edge that is being used to capacity. ◦ For example, s v 1 v 2 … v n t, where each edge has extra capacity EXCEPT for the edge v i v i+1. What is a simple fix to add extra capacity to one of the edges that will add maximum flow to the network? How much will this simple fix add?
22
Network Flow Take a look at the extra capacity available through each of the other edges ◦ s → v 1, v 1 → v 2, …, v i-1 → v i, v i+1 → v i+2, …, v n → t. ◦ Take the minimum of these values. ◦ Then, add this much capacity to the edge v i → v i+1. ◦ Adding more than this would do no good, because then some other edge would become the bottleneck. This just adds enough capacity so that the original edge is no more of a bottleneck than the “second worst” edge in this particular path.
23
References Slides adapted from Arup Guha’s Computer Science II Lecture notes: http://www.cs.ucf.edu/~dmarino/ucf/cop3503/le ctures/ http://www.cs.ucf.edu/~dmarino/ucf/cop3503/le ctures/ Additional material from the textbook: Data Structures and Algorithm Analysis in Java (Second Edition) by Mark Allen Weiss J Elder’s Network Flow slides, York University
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.