Download presentation
1
NP-Completeness: 3D Matching
Andreas Klappenecker
2
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.
3
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.]
4
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.
5
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.
6
3-Dimensional Matching
Let G=(V,E) be a 3-uniform hypergraph, where V is a union of 3 disjoints sets, V = AB 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.
7
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.
8
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.
9
Simplification Before constructing gadgets, we note that one can transform any 3SAT instance in one that contains each Boolean literal at most twice.
10
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.
11
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
12
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.
13
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.
14
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 }
15
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.
16
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}.
17
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!
18
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
19
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.
20
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.
21
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.
22
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
23
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.
24
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.
25
Dealing with NP-Complete Problems
[based on slides by Prof. Welch]
26
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
27
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
28
Approximation Algorithms
An approximation algorithm for an optimization problem runs in polynomial time and always returns a candidate solution
29
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
30
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|
31
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
32
Min VC Approx Algorithm
Time is O(E), which is polynomial. How good an approximation does it provide? Let's look at an example.
33
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.
34
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
35
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
36
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.
37
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
38
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?
39
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
40
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.
41
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?
42
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.
43
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
44
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.
45
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.
46
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.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.