NP-Completeness: 3D Matching

Slides:



Advertisements
Similar presentations
NP-Hard Nattee Niparnan.
Advertisements

1 NP-completeness Lecture 2: Jan P The class of problems that can be solved in polynomial time. e.g. gcd, shortest path, prime, etc. There are many.
Approximation Algorithms for TSP
NP-Completeness: Reductions
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
Combinatorial Algorithms
Complexity 11-1 Complexity Andrei Bulatov NP-Completeness.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Approximation Algorithms: Combinatorial Approaches Lecture 13: March 2.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
1 Optimization problems such as MAXSAT, MIN NODE COVER, MAX INDEPENDENT SET, MAX CLIQUE, MIN SET COVER, TSP, KNAPSACK, BINPACKING do not have a polynomial.
Approximation Algorithms Lecture for CS 302. What is a NP problem? Given an instance of the problem, V, and a ‘certificate’, C, we can verify V is in.
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
Computability and Complexity 16-1 Computability and Complexity Andrei Bulatov NP-Completeness.
The Theory of NP-Completeness
NP-Complete Problems Problems in Computer Science are classified into
Analysis of Algorithms CS 477/677
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
Approximation Algorithms Motivation and Definitions TSP Vertex Cover Scheduling.
CPSC 411 Design and Analysis of Algorithms Set 11: NP-Completeness Prof. Jennifer Welch Spring 2011 CPSC 411, Spring 2011: Set 11 1.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
The Traveling Salesman Problem Approximation
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.
APPROXIMATION ALGORITHMS VERTEX COVER – MAX CUT PROBLEMS
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
Advanced Algorithm Design and Analysis (Lecture 13) SW5 fall 2004 Simonas Šaltenis E1-215b
Lecture 22 More NPC problems
Approximation Algorithms
1 NP-Completeness Andreas Klappenecker [based on slides by Prof. Welch]
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
EMIS 8373: Integer Programming NP-Complete Problems updated 21 April 2009.
1 NP-Completeness Andreas Klappenecker [based on slides by Prof. Welch]
1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Unit 9: Coping with NP-Completeness
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
Lecture 6 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
NP-Complete problems.
1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
NP Completeness Piyush Kumar. Today Reductions Proving Lower Bounds revisited Decision and Optimization Problems SAT and 3-SAT P Vs NP Dealing with NP-Complete.
CSC 413/513: Intro to Algorithms
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Introduction to NP Instructor: Neelima Gupta 1.
Approximation Algorithms by bounding the OPT Instructor Neelima Gupta
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
TU/e Algorithms (2IL15) – Lecture 11 1 Approximation Algorithms.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
The Theory of NP-Completeness
More NP-Complete and NP-hard Problems
CSCE 411 Design and Analysis of Algorithms
Richard Anderson Lecture 26 NP-Completeness
Richard Anderson Lecture 26 NP-Completeness
P and NP CISC4080, Computer Algorithms CIS, Fordham Univ.
Approximation Algorithms for TSP
ICS 353: Design and Analysis of Algorithms
Richard Anderson Lecture 25 NP-Completeness
Andreas Klappenecker [based on slides by Prof. Welch]
Approximation Algorithms
P and NP CISC5835, Algorithms for Big Data CIS, Fordham Univ.
The Theory of NP-Completeness
Lecture 24 Vertex Cover and Hamiltonian Cycle
Presentation transcript:

NP-Completeness: 3D Matching Andreas Klappenecker

Bipartite Matching Let G be a bipartite graph with 2n nodes, with n nodes on each side. The bipartite matching problem is to decide whether there exist a perfect matching, that is, whether there exist n edges that are incident with all 2n nodes. Example: n boys and n girls, edges represent `like each other’. A perfect matching would find n couples.

Bipartite Matching A bipartite matching can be found in polynomial time. For example, a network flow algorithm can be used. [Add a source node and edges from source to all boy nodes. Add a sink node and edges from all girl nodes to the sink.]

Hypergraph A hypergraph G is a pair (V,E), where V is a set E is a subset of P(V)\{} . The elements in V are called vertices. The elements in E are called hyperedges or links.

Uniform Hypergraphs A hypergraph is called k-uniform if and only if all its links have cardinality k. For example, an undirected graph is a 2-uniform hypergraph. The links of a 3-uniform hypergraph consist of unordered triples.

3-Dimensional Matching Let G=(V,E) be a 3-uniform hypergraph, where V is a union of 3 disjoints sets, V = AB C, |A|=|B|=|C|=n such that each link in E contains precisely one element from each set A, B, and C. A perfect matching in G consists of n links such that their union yields V. The 3D matching problem is to decide whether a perfect matching exists in G.

Example Let A be a set of n boys, B a set of n girls, and C a set of n pets. We would like to form n harmonious households {a, b, c} such that a in A, b in B, c in C. The edges of the hypergraph list compatibilities. All n households together contain all boys, girls, and pets.

3D Matching Theorem: 3D matching is NP-complete Proof: Obviously, 3D matching is contained in NP. We will show that 3SAT p 3D matching. We need to construct gadgets in 3D matching that behave like Boolean variables and logical clauses.

Simplification Before constructing gadgets, we note that one can transform any 3SAT instance in one that contains each Boolean literal at most twice.

Boolean Variable Gadget Consider T0 = {b0, g0, p1} T1 = {b0, g1, p0} T2 = {b1, g0, p2} T3 = {b1, g1, p3} Suppose that the boys b0 and b1 and the girls g0 and g1 are not involved in any other triples. Then any matching must contain either (T0 and T3 ) or (T1 and T2 ). The two alternatives represent false and true, respectively. The choice of pet will decide whether the variable is negated or not.

Boolean Variable Gadgets To transform an instance of 3SAT to one of 3D matching, we create a copy of the preceding gadget for each variable. If x is a Boolean variable, then we create T0 = {bx0, gx0, px1} // x = false T1 = {bx0, gx1, px0} // x = true T2 = {bx1, gx0, px2} // x = true T3 = {bx1, gx1, px3} // x = false

Clause Gadgets Next, we must create triples that mimic logical clauses. For each clause c , we introduce three triples that contain new boys and girls. The pets in these triples will reflect the three ways in which the clause can be satisfied.

Clause Gadgets If the clause is c = (x  y  z) then this clause can be satisfied by setting x = true, (b) y = false or (c) z = true. For the case (a), we add either { bc, gc, px1 } or { bc, gc, px3 } since px0 and px2 will be taken by the variable gadget. We will use the first choice if c is the first clause containing x, and the second choice otherwise. Recall that we assume that each literal occurs at most twice.

Clause Gadgets If the clause is c = (x  y  z) then this clause can be satisfied by setting x = true, (b) y = false or (c) z = true. For the case (b), we add either { bc, gc, py0 } or { bc, gc, py2 } For the case (c), we add either { bc, gc, pz1 } or { bc, gc, pz3 }

Lost Pets After all the triples have been created, there might be some pets left unmatched. If n variables and m clauses are used, then r = 2n-m pets will be left unmatched. Thus, we add r new boys and girls that love all pets. Now, from any perfect matching, we can recover a satisfying truth assignment. If no satisfying truth assignment exists, then evidently no perfect matching can exist.

Example Consider a  b with a= (x  y  z) , b=(x  y   z) Variables: {bx0, gx0, px1}, {bx0, gx1, px0}, {bx1, gx0, px2}, {bx1, gx1, px3}, {by0, gy0, py1}, {by0, gy1, py0}, {by1, gy0, py2}, {by1, gy1, py3}, {bz0, gz0, pz1}, {bz0, gz1, pz0}, {bz1, gz0, pz2}, {bz1, gz1, pz3} Clauses: {ba, ga, px1}, {ba, ga, py0}, {ba, ga, pz1}, {bb, gb, px3}, {bb, gb, py2}, {bb, gb, pz2} Lost pets: (12 pets, but matching only used 8 so far) {bc, gc, px0}, {bc, gc, px1}, … , {bc, gc, pz3}, … {bf, gf, px0}, {bf, gf, px1}, … , {bf, gf, pz3}.

Zero-One Equations In zero-one equations, we are given an m x n matrix A with entries in {0,1} and the goal is to find a vector x in {0,1}n such that Ax = (1,…,1)t , a vector with m ones. We call this problem ZOE. Theorem: ZOE is an NP-complete problem!

Proof The problem clearly belongs to NP. Since we can verify whether or not a given vector x satisfies this equation in polynomial time. We show that 3D Matching p ZOE

Reduction Let G be an instance of 3D matching. Suppose that G=(V,E) with vertex set V=A  B  C, where the three sets have cardinality n=|A|=|B|=|C| and |V|=3n. and hyperedge set E={t1,…,tn}. We can think of the elements in E as n triples of boys, girls, and pets.

Reduction Let A be the incidence matrix of the hypergraph G, that is, A is an 3n x n matrix, where rows of A are indexed by the elements in V columns of A are indexed by hyperedges in E. The entry (A)v,e = 1 if v is contained in the hyperedge e, and 0 otherwise.

Reduction Let x be an incidence vector of a perfect matching, i.e., xe=1 if e is contained in the matching and xe=0 otherwise. Then Ax=(1,…,1)t as a perfect matching contains for each v in V precisely one triple that contains v.

Reduction Conversely, if we solve Ax=(1,…,1)t for x in {0,1}n, then each row has the following interpretation: For v in V, v is contained in precisely one of the triples in M ={ e in E | xe = 1}. The fact that Ax evaluates to the all one vector means that each element of V occurs precisely once among the hyperedges in M. So M is a perfect matching. Q.e.d

Integer Linear Programming The integer linear programming problem is: For a given matrix A with integer entries, and a vector b of integer entries, find a vector x with integer entries such that Ax  b The corresponding decision problem ILP is whether such a vector x exists.

ILP Theorem: ILP is NP-complete. Proof: We note that ZOE is a special case of ILP. Indeed, each row equation ax=b of ZOE can be written in terms of the inequalities ax<=b and –ax<=-b. Add for each variable xi the inequalities xi <= 1 and -xi <=0. q.e.d.

Dealing with NP-Complete Problems [based on slides by Prof. Welch]

Dealing with NP-Completeness Suppose the problem you need to solve is NP-complete. What do you do next? hope/show bad running time does not happen for inputs of interest find heuristics to improve running time in many cases (but no guarantees) find a polynomial time algorithm that is guaranteed to give an answer close to optimal

Optimization Problems Concentrate on approximation algorithms for optimization problems: every candidate solution has a positive cost Minimization problem: goal is to find smallest cost solution Ex: Vertex cover problem, cost is size of VC Maximization problem: goal is to find largest cost solution Ex: Clique problem, cost is size of clique

Approximation Algorithms An approximation algorithm for an optimization problem runs in polynomial time and always returns a candidate solution

Measuring How Good an Approximation Algorithm Is Ratio bound: bound the ratio of the cost of the solution returned by the approximation algorithm and the cost of an optimal solution minimization problem: cost of approx solution / cost of optimal solution maximization problem: cost of optimal solution / cost of approx solution So ratio is always at least 1, goal is to get it as close to 1 as we can

Alternative Measurements Relative error: |cost of approx soln – cost of optimal soln|/cost of optimal soln Difference: |cost of approx soln – cost of optimal soln|

Approximation Algorithm for Minimum Vertex Cover Problem input: G = (V,E) C :=  E' := E while E' ≠  do pick any (u,v) in E' C := C U {u,v} remove from E' every edge incident on u or v endwhile return C

Min VC Approx Algorithm Time is O(E), which is polynomial. How good an approximation does it provide? Let's look at an example.

Min VC Approx Alg Example b c d a e f g choose (b,c): remove (b,c), (b,a), (c,e), (c,d) choose (e,f): remove (e,f), (e,d), (d,f) Answer: {b,c,e,f,d,g} Optimal answer: {b,d,e} Algorithm's ratio bound is 6/3 = 2.

Ratio Bound of Min VC Alg Theorem: Min VC approximation algorithm has ratio bound of 2. Proof: Let A be the total set of edges chosen to be removed. Size of VC returned is 2*|A| since no two edges in A share an endpoint. Size of A is at most size of a min VC since min VC must contain at least one node for each edge in A. Thus cost of approx solution is at most twice cost of optimal solution

More on Min VC Approx Alg Why not run the approx alg and then divide by 2 to get the optimal cost? Because answer is not always exactly twice the optimal, just never more than twice the optimal. For instance, a different choice of edges to remove gives a different answer: Choosing (d,e) and then (b,c) produces answer {b,c,d,e} with cost 4 as opposed to optimal cost 3

Triangle Inequality Assume TSP inputs with the triangle inequality: distances satisfy property that for all cities a, b, and c, dist(a,c) ≤ dist(a,b) + dist(b,c) i.e., shortest path between 2 cities is direct route Depending on what you are modeling with the distances, an application might or might satisfy this condition.

TSP Approximation Algorithm input: set of cities and distances b/w them that satisfy the triangle inequality create complete graph G = (V,E), where V is set of cities and weight on edge (a,b) is dist(a,b) compute MST of G Go twice around the MST to get a tour (that will have duplicates) Remove duplicates to avoid visiting a city more than once

Analysis of TSP Approx Alg Running time is polynomial (creating complete graph takes O(V2) time, Kruskal's MST algorithm takes time O(E log E) = O(V2log V). How good is the quality of the solution?

Analysis of TSP Approx Alg cost of approx solution ≤ 2*weight of MST, by triangle inequality Why? when tour created by going around the MST is adjusted to remove duplicate nodes, the two red edges are replaced with the green diagonal edge c a b

Analysis of TSP Approx Alg weight of MST < length of min tour Why? Min tour minus one edge is a spanning tree T, whose weight must be at least the weight of MST. And weight of min tour is greater than weight of T.

Analysis of TSP Approx Alg Putting the pieces together: cost of approx solution ≤ 2*weight of MST ≤ 2*cost of min tour So approx ratio is at most 2. Suppose we don't have triangle inequality. How well can we approximate min tour?

TSP Without Triangle Inequality Theorem: If P ≠ NP, then no polynomial time approximation algorithm for TSP (w/o triangle inequality) can have a constant ratio bound. Proof: We will show that if there is such an approximation algorithm, then we could solve a known NP-complete problem (Hamiltonian cycle) in polynomial time, so P would equal NP.

HC Exact Algorithm using TSP Approximation Algorithm input: G = (V,E) 1. convert G to this TSP input: one city for each node in V distance between cities u and v is 1 if (u,v) is in E distance between cities u and v is r*|V| if (u,v) is not in E, where r is the ratio bound of the TSP approx alg Note: This TSP input does not satisfy the triangle inequality

HC (Exact) Algorithm Using TSP Approximation Algorithm 2. run TSP approx alg on the input just created 3. if cost of approx solution returned in step 2 is ≤ r*|V| then return YES else return NO Running time is polynomial.

Correctness of HC Algorithm If G has a HC, then optimal tour in TSP input constructed corresponds to that cycle and has weight |V|. Approx algorithm returns answer with cost at most r*|V|. So if G has HC, then algorithm returns YES.

Correctness of HC Algorithm If G has no HC, then optimal tour for TSP input constructed must use at least one edge not in G, which has weight r*|V|. So weight of optimal tour is > r*|V|, and answer returned by approx alg has weight > r*|V|. So if G has not HC, then algorithm returns NO.