Announcements Assignment 4: • Due Monday, April 5 at Midnight (due to university regulations). • Submit solutions to any 2 of the 4 problems. • Responsible for understanding all 4 problems (related material may be on final exam). Tutorial: • Fri, Apr 2 A. Kolokolova 16:00-17:30 PSE 321 Special office hours (week prior to exam): MWF 2-3 The Maximum Network Flow Problem Example Flow(1) Residual(1) No more augmenting paths max flow attained. Flow(2) Residual(2) The Basic Ford-Fulkerson Algorithm Multiple Sources Network •We have several sources and several targets. •Want to maximize the total flow from all sources to all targets. •Reduce to max-flow by creating a supersource and a supersink: Maximum Bipartite Matching A bipartite graph is a graph G=(V,E) in which V can be divided into two parts L and R such that every edge in E is between a vertex in L and a vertex in R. e.g. vertices in L represent skilled workers and vertices in R represent jobs. An edge connects workers to jobs they can perform. A matching in a graph is a subset M of E, such that for all vertices v in V, at most one edge of M is incident on v. A maximum matching is a matching of maximum cardinality. not maximum maximum A Maximum Matching No matching of cardinality 4, because only one of v and u can be matched. In the workers-jobs example a maxmatching provides work for as many people as possible. v u Solving the Maximum Bipartite Matching Problem •Reduce an instance of the maximum bipartite matching problem on graph G to an instance of the max-flow problem on a corresponding flow network G’. •Solve using Ford-Fulkerson method. Corresponding Flow Network •To form the corresponding flow network G' of the bipartite graph G: • Add a source vertex s and edges from s to L. • Direct the edges in E from L to R. • Add a target vertex t and edges from R to t. • Assign a capacity of 1 to all edges. •Claim: max-flow in G’ corresponds to a maxbipartite-matching on G. Example min cut |M| = 3 max flow = 3 Lemma (CLRS 26.10) Let G (V , E ) be a bipartite graph with vertex partition V L R . Let G (V , E ) be its corresponding flow network. If M is a matching in G , then there is an integer-valued flow f in G with value | f || M | . Conversely, if f is an integer-valued flow in G , then there is a matching M in G with cardinality | M || f | . Why can’t we just say max |f| = max |M|? Problem: we haven’t shown that f(u,v) is necessarily integer-valued for all (u,v) when f is a max flow. It follows from the lemma that max |M| = max [ integral flow], but we also need max [integral flow] = max |f| Integrality Theorem (CLRS 26.11) If the capacity function c takes on only integral values, then: 1. The maximum flow f produced by the Ford-Fulkerson method has the property that |f| is integer-valued. 2. For all vertices u and v the value f(u,v) of the flow is an integer. So |M| = max [integral flow] = max |f| Conclusion Network flow algorithms allow us to find the maximum bipartite matching fairly easily. Similar techniques are applicable in other combinatorial design problems. 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. Two solutions using network flows Solution 1: convert the problem into a bipartite matching problem. Solution 2: convert the problem into a flow problem directly. A more complicated problem •There are m student groups on campus. •We would like to form a committee with a president, 3 vice-pres, and 10 members at large. •The committee is formed by representatives of the groups. •Can add conditions: • The first group can be represented by at most 2 members, any other group can be represented by at most one. • The representative of the third group cannot be the president. •Reduce to network flows! Reducibility and NP-Completeness Computational Complexity Theory Computational Complexity Theory is the study of how much of a given resource (such as time, space, parallelism, randomness, algebraic operations, communication, or quantum steps) is required to solve important problems. WORST-CASE TIME We say that a program takes worst-case time T(n), if some input of size n takes T(n) steps, and no input of size n takes longer. The input size is measured in bits, unless stated otherwise. Some Examples A Graph Named “Gadget” K-COLORING A k-coloring of a graph is an assignment of one color to each vertex such that: • No more than k colors are used • No two adjacent vertices receive the same color A graph is called k-colorable iff it has a k-coloring A CRAYOLA Question! Is Gadget 2-colorable? No: it contains a triangle! A CRAYOLA Question! Is Gadget 3-colorable? Yes! 2 CRAYOLAS Given a graph G, what is a fast algorithm to decide if it can be 2-colored? PERSPIRATION; BRUTE FORCE: Try out all 2n ways of 2 coloring G. 3 CRAYOLAS Given a graph G, what is a fast algorithm to decide if it can be 3-colored? ? ? ? ? ? ?? ? Let’s consider a completely different problem. K-CLIQUES A K-clique is a set of K nodes with all k(K-1)/2 possible edges between them. This graph contains a 4-clique Given an n-node graph G and a number k, how can you decide if G contains a k-clique? PERSPIRATION: Try out all n choose k possible locations for the k clique INSPIRATION: ? ? ? ? ? ?? ? OK, how about a slightly different problem? INDEPENDENT SET An independent set is a set of vertices with no edges between them. This graph contains an independent set of size 3. Given an n-node graph G and a number k, how can you decide if G contains an independent set of size k? PERSPIRATION: Try out all n-choose-k possible locations for independent set INSPIRATION: ? ? ? ? ? ?? ? One more completely different problem Combinational Circuits AND, OR, NOT, gates wired together with no feedback allowed (acyclic). Logic Gates Not And Or Example Circuit CIRCUIT-SATISFIABILITY (decision version) Given a circuit with n-inputs and one output, is there a way to assign 0-1 values to the input wires so that the output value is 1 (true)? CIRCUIT-SATISFIABILITY (search version) Given a circuit with n-inputs and one output, find an assignment of 0-1 values to the input wires so that the output value is 1 (true), or determine that no such assignment exists. Satisfiable Circuit Example Satisfiable? No! Given a circuit, is it satisfiable? PERSPIRATION: Try out all 2n assignments INSPIRATION: ? ? ? ? ? ?? ? We have seen 4 problems: coloring, clique, independent set, and circuit SAT. They all have a common story: A large space of possibilities only a tiny fraction of which satisfy the constraints. Brute force takes too long, and no feasible algorithm is known. CLIQUE / INDEPENDENT SET Two problems that are cosmetically different, but substantially the same Complement Of G Given a graph G, let G*, the complement of G, be the graph obtained by the rule that two nodes in G* are connected if and only if the corresponding nodes of G are not connected Reduction • Suppose you have a method for solving the k-clique problem. • How could it be used to solve the independent set problem? Or what if you have an Oracle? or·a·cle Pronunciation: 'or-&-k&l, 'ärFunction: noun Etymology: Middle English, from Middle French, from Latin oraculum, from orare to speak 1 a : a person (as a priestess of ancient Greece) through whom a deity is believed to speak 2 a : a person giving wise or authoritative decisions or opinions Let G be an n-node graph. <G,k> <G*, k> BUILD: Indep. Set Oracle GIVEN: Clique Oracle Let G be an n-node graph. <G,k> <G*, k> BUILD: Clique Oracle GIVEN: Indep. Set Oracle Thus, we can quickly reduce clique problem to an independent set problem and vice versa. There is a fast method for one if and only if there is a fast method for the other. Given an oracle for circuit SAT, how can you quickly solve 3-colorability? Vn(X,Y) Let Vn be a circuit that takes an n-node graph X and an assignment Y of colors to these nodes, and verifies that Y is a valid 3colouring of X. i.e., Vn(X,Y)=1 iff Y is a 3colouring of X. X is expressed as an n-choose-2 bit sequence. Y is expressed as a 2n bit sequence. Given n, we can construct Vn in time O(n2). Let G be an n-node graph. G Vn(G,Y) BUILD: 3color Oracle GIVEN: SAT Oracle Given an oracle for circuit SAT, how can you quickly solve k-clique? Vn,k(X,Y) Let Vn be a circuit that takes an n-node graph X and a subset of nodes Y, and verifies that Y is a k-clique X. I.e., Vn(X,Y)=1 iff Y is a kclique of X. X is expressed as an n choose 2 bit sequence. Y is expressed as an n bit sequence. Given n, we can construct Vn,k in time O(n2). Let G be an n-node graph. <G,k> Vn,k(G,Y) BUILD: Clique Oracle GIVEN: SAT Oracle Given an oracle for 3-colorability, how can you quickly solve circuit SAT? Reducing Circuit-SAT to 3-Colouring Goal: map circuit to graph that is 3colourable only if circuit is satisfiable. How do we represent a logic gate as a 3-colouring problem? Example Y X X and Y and Output are boolean variables in circuit. Without loss of generality, map truth values to colours, e.g. 0 red 1 green Output Add base colour for encoding purposes, e.g. yellow. Example Y X Note that in a valid 3colouring, this node cannot have the same colour as X, Y or Output. Thus, without loss of generality, we can assign it the base colour, yellow. Output Example Y X Now suppose we fix this node to represent false. Output Example F Y X Now suppose we fix this node to represent false. Output Example T F Y X Now build a truth table for (X, Y, Output). What if X=Y=0? Output Example T F Y X Now build a truth table for (X, Y, Output). What if X=Y=0? Output Example T F Y X Now build a truth table for (X, Y, Output). What if X=Y=0? Output Example T F Y X Now build a truth table for (X, Y, Output). What if X=Y=0? Output Example T F Y X Thus (X,Y)=0Output=0 Output Example T F Y X Conversely, what if Output=0? Output Example T F Y X Conversely, what if Output=0? Output Example T F Y X Conversely, what if Output=0? Output Example T F Y X Conversely, what if Output=0? Output Example T F Y X Thus Output=0X=Y=0. Output T F Example Y X What type of gate is this? An OR gate! Output X Y Output F F F F T T T F T T T T T X F What type of gate is this? A NOT gate! Output x y OR z x NOT OR y z x y OR z x NOT OR Satisfiability of this circuit = 3-colorability of this graph y z Let C be an n-input circuit. C Graph composed of gadgets that mimic the gates in C BUILD: SAT Oracle GIVEN: 3-color Oracle Formal Statement There is a polynomial-time function f such that: C is satisfiable <-> f(C) is 3 colorable 4 Problems All Equivalent If you can solve one quickly then you can solve them all quickly: Circuit-SAT Clique Independent Set 3 Colorability That’s All, Folks!
© Copyright 2024