=========================================================================== CSC 373 Lecture Summary for Week 9 Fall 2008 =========================================================================== Applications of network flows. - Maximum bipartite matching: Input: An undirected bipartite graph G=(V_1,V_2,E) -- one where every edge is between V_1 and V_2 (i.e., no edge has both endpoints in the same "side"). Output: A disjoint subset of edges of maximum size (i.e., no edge in a matching shares an endpoint with any other edge in the matching). Given input graph, create network by turning every original edge into a directed edge (from V_1 to V_2) with capacity 1; add source with edges of capacity 1 to each vertex in V_1, sink with edges of capacity 1 from each vertex in V_2. . Any matching in graph yields flow in network: set flow = 1 for graph edges in matching, 0 for graph edges out of matching; set flow = 1 for new edges to/from matched vertices, 0 for new edges to/from unmatched vertices. Since no two edges share an endpoint, conservation is satisfied. . Any integer flow in network yields matching in graph: pick graph edges with flow = 1 (leave out edges with flow = 0). Since every new edge out of source or into sink has capacity 1, no two picked edges can share an endpoint. From this correspondence, size of matching = value of flow. Hence, any max flow in network yields a maximum matching in graph (because a larger matching would give a larger flow). - Teaching assignment: Input: Set of profs p_1, ..., p_n and courses c_1, ..., c_m; each prof has teaching load L (number of courses that must be taught) and subset of courses that the prof is capable of teaching. Output: Assignment of profs to courses so that: . each prof assigned exactly L courses . each course assigned exactly 1 prof. Is it possible to assign profs to courses to satisfy all constraints? If so, how? Given input, create network with vertices p_1,...,p_n, c_1,...,c_m, source s, sink t, and edges (s,p_i) of capacity L for each p_i, edges (c_j,t) of capacity 1 for each c_j, edges (p_i,c_j) of capacity 1 for each p_i,c_j such that p_i can teach c_j. . Any assignment of profs to courses yields flow in network: set f(p_i,c_j) = 1 if p_i assigned c_j, 0 otherwise; set f(s,p_i) = number of courses assigned to p_i; set f(c_j,t) = number of profs assigned to c_j. . Any integer flow in network yields assignment of profs to courses: assign p_i to c_j if f(p_i,c_j) = 1 (no more than L courses are assigned to each prof and no more than 1 prof to each course). Find max flow f in network. If |f| = Ln = m, then it is possible to assign profs to courses to satisfy all constraints; otherwise it isn't. If it is not possible, max flow yields max assignment possible. This could be used for example to determine set of courses that can be offered, or maximum teaching load for profs. Note this can easily accomodate slightly more general problem where each prof p_i has teaching load L_i which can change from prof to prof, and/or where each course can be taught by more than one prof (e.g., in multiple sections). - Project selection: (section 7.11 in textbook) Input: Projects P each with revenue p_i (integer, can be positive or negative), prerequisites between projects (given as directed graph on vertices P with edges (i,j) meaning project i depends on j). Output: A "feasible" subset A of P with maximum total revenue (set A feasible means for each i (- A, A contains all i's prerequisites). Unlike other examples, this can be solved by network flow techniques where we are interested in minimum cuts (flow values are irrelevant). Construct network N from G as follows: - Add source s, sink t. - Add edges (s,i) with capacity p_i for each i such that p_i >= 0. - Add edges (i,t) with capacity -p_i for each i such that p_i < 0. - Set capacity of all other edges (i,j) to C+1, where C = \sum_{p_i >= 0} p_i. Find a minimum cut (V_s,V_t) in N. Then V_s-{s} is a feasible subset of projects with maximum profit! This requires proof... Claim 1: V_s - {s} is feasible for all cuts (V_s,V_t) with capacity at most C. Proof: c(V_s,V_t) <= C implies no edge (i,j) (with capacity C+1) crosses the cut forward, i.e., for all projects i (- V_s, V_s contains all of i's prerequisites. Claim 2: c(A u {s}, ~A u {t}) = C - \sum_{i (- A} p_i = C - profit(A) for all feasible sets of projects A (where ~A = P-A). Proof: Since A is feasible, no edge (i,j) with capacity C+1 crosses the cut forward (some may cross backward). Forward edges crossing the cut fall into two groups: . entering sink contribute \sum_{i (- A, p_i < 0} -p_i . leaving source contribute \sum_{i (- ~A, p_i >= 0} p_i = C - \sum_{i (- A, p_i >= 0} p_i (because C = \sum_{p_i >= 0} p_i = \sum_{i (- A, p_i >= 0} p_i + \sum_{i (- ~A, p_i >= 0} p_i) So total capacity of cut is \sum_{i (- A, p_i < 0} -p_i + C - \sum_{i (- A, p_i >= 0} p_i = C - \sum_{i (- A} p_i = C - profit(A). These two facts imply that feasible sets of projects and cuts with capacity at most C correspond to each other. Since for any such set, c(A u {s}, ~A u {t}) = C - profit(A), and C is constant, any minimum-capacity cut (V_s,V_t) yields a maximum-profit set V_s - {s}.