Report

MCS 312: NP Completeness and Approximation algorithms Instructor Neelima Gupta [email protected] Table of Contents • 3D Matching • Exact Cover 3-D Matching Problem Problem Definition Given • Disjoint sets X, Y, Z, each of size n • A set T XxYxZ of ordered triples To Find If there exists a set of n triples in T so that each element of XYZ is contained in exactly one of these triples. 3-D Matching Problem Claim 3-D Matching is NP Complete Proof Part I 3-D Matching belongs to NP Given • An instance of 3-D Matching • A certificate containing a collection of triples T’ T It can clearly be verified in polynomial time that each element in X Y Z belongs to exactly one of the triples in T’. 3-D Matching Problem Part II 3-D Matching is NP-hard We prove the above by showing that 3-SAT ≤p 3-D Matching We adopt the following approach We first design gadgets that encode the independent c h o i c e s i n v o l v e d i n t h e t r u t h assignment to each variable We then add gadgets to encode constraints imposed by clauses. Given: A 3-SAT instance with n variables and k clauses 3-D Matching Problem Basic gadget associated with variable xi Core of the gadget as Ai = {ai1,ai2,….,ai,2k} Tips of the gadget Bi = {bi1,bi2,….,bi,2k} A triple tij = (aij,ai,j+1,bij) for all j = 1, 2k, where addition is modulo 2k. A triple tij is even if j is even, and odd otherwise. Analogous for tip bij. • Red nodes are the core elements • Blue nodes are tips Enhancing the variable gadget to model the clauses and the constraints on possible assignments imposed by them For clause C j , clause gadget Two core elements For each of the three terms If term = xi, define a If term = x i ’, define a is defined as follows: Pj = {pj, pj’}. in C j do the following triple (pj, pj’,bi,2j). triple (p j , p j ’,b i , 2 j - 1 ). 3-D Matching Problem We understand this enhancement through an example. Consider the following clause C1= x1’ v x2 v x3’ Interpretation: The matching should select the even tips of the first gadget, or odd tips of the second gadget, or even tips the third gadget. We first create gadgets for the three variables 3-D Matching Problem x1 x2 x3 3-D Matching Problem We now model the assignment constraints with a clause gadget defined as follows: A set of 2 core elements P1 = {p1, p1’} contained in the following 3 triples: • (p1, p1’,b1,1) • (p1, p1’,b2,2) • (p1, p1’,b3,1) 3-D Matching Problem C1 3-D Matching Problem How do we encode the idea that xi can either be set to 0 or 1 ? Either use all the even triples in gadget i, or all odd ones ! • Selecting all even triples corresponds to setting xi = 0. In this case the odd tips would remain free for use. • Selecting all odd triples corresponds to xi = 1. In this case, the even tips would remain free for use. Enhancing the variable gadget to model the clauses and the constraints on possible assignments imposed by them For clause C j , clause gadget is defined as follows: Two core elements Pj = {pj, pj’}. For each of the three terms in C j do the following If term = xi, define a triple (pj, pj’,bi,2j). If term = x i ’, define a triple (p j , p j ’,b i , 2 j - 1 ). Reserving the (2j)th and (2j-1)th tips of each variable gadget for clause gadget j ensures that the clause gadgets never compete for free tips. Since only the 3 triples defined corresponding to the 3 terms of Cj cover Pj, one of these must be used. This enforces the clause constraint. Cleanup Gadgets We introduce (n-1)k cleanup gadgets ! The rth cleanup gadget consists of 2 core elements Qr = {qr, qr’} Create a triple (qr, qr’,b) for every tip b in variable gadgets. 3-D Matching Problem Define X,Y and Z as follows: X consists of 1. all aij with j even ….total number nk 2. The set of all pj ….. total number k 3. The set of all qi ….. total number (n – 1) k Y consists of 1. all aij with j odd ….total number nk 2. The set of all pj’ ….. total number k 3. The set of all qi’….. total number (n – 1) k Z consists of 1. Set of all tips bij …. ….. total number 2 n k Can you see that • X, Y and Z are of same size….what’s the size? • Each triple consists of one element from each of X,Y, and Z. 3-D Matching Problem Y consists of 1. all aij with j odd 2. The set of all pj’ 3. The set of all qi’ Z consists of 1. Set of all tips bij Can you see that • X, Y and Z are of same size • Each triple consists of one element from each of X,Y, and Z. 3-D Matching Problem We understand the above reduction with the help of an example ! Consider an instance of 3-SAT having 4 variables : x1,x2 x3,x4 3 clauses C1 : (x1 v x2 v x3’) C2 : (x2’ v x3 v x4) C3 : (x1’ v x2 v x4’) Variable gadget for x1 has the following components Core A1 = {a11,a12,….,a1,6} Tips B1 = {b11,b12,….,b1,6} A triple t1j = (a1j,a1,j+1,b1j) for all j, where addition is modulo 6. Tip 1 Tip 6 Tip 2 Tip 5 Tip 3 Tip 4 3-D Matching Problem Gadgets for the remaining variables can similarly be drawn. We now bring the clause gadgets into picture C1 : (x1 v x2 v x3’) p1 p1 ’ x1 x2 x3 C2 : (x2’ v x3 v x4) x2 x3 p2 p2 ’ x4 C3 : (x1’ v x2 v x4’) x1 p3 p3 ’ x2 x4 3-D Matching Problem Part I Consider the following satisfying assignment for the given 3-SAT instance x1 = 1 x2 = 0 x3 = 1 x4 = 0 We now try to find a matching. We select the odd triples of gadget for x1 since x1 = 1. This leaves the even tips free for use Tip 1 Tip 6 Tip 2 Tip 5 Tip 3 Tip 4 We select the even triples of gadget for x2 since x 2 = 0. This leaves the odd tips free for use Tip 1 Tip 6 Tip 2 Tip 5 Tip 3 Tip 4 We select the odd triples of gadget for x3 since x3 = 1. This leaves the even tips free for use Tip 1 Tip 6 Tip 2 Tip 5 Tip 3 Tip 4 We select the even triples of gadget for x4 since x 4 = 0. This leaves the odd tips free for use Tip 1 Tip 6 Tip 2 Tip 5 Tip 3 Tip 4 C1 : (x1 v x2 v x3’) p1 p1 ’ x1 x2 x3 C2 : (x2’ v x3 v x4) x2 x3 p2 p2 ’ x4 C3 : (x1’ v x2 v x4’) x1 p3 p3 ’ x2 x4 3-D Matching Problem Claim: 3-SAT is satisfiable if and only if there exists a perfect 3-D Matching Part I Given A satisfying assignment for the 3-SAT instance To Prove There exists a perfect 3-D Matching Recap Define X,Y and Z as follows: X consists of 1. all aij with j even ….total number nk 2. The set of all pj ….. total number k 3. The set of all qi ….. total number (n – 1) k Y consists of 1. all aij with j odd ….total number nk 2. The set of all pj’ ….. total number k 3. The set of all qi’….. total number (n – 1) k Z consists of 1. Set of all tips bij …. ….. total number 2 n k Can you see that • X, Y and Z are of same size….what’s the size? • Each triple consists of one element from each of X,Y, and Z. 3-D Matching Problem Proof Make the corresponding choices of odd/even for each variable gadget based on the given assignment. This leaves at least one free tip for each clause gadget. Using the cleanup gadgets, we cover all the core elements in the variable, clause and cleanup gadgets, and all the tips too ! 3-D Matching Problem Part II Given A perfect 3-D Matching in the instance constructed. Can we claim that this matching cannot possibly cover some even and some odd triples in any variable gadget, i.e., either all even or all odd triples are chosen ? 3-D Matching Problem Yes ! Any two consecutive triples share one of the core elements ! Therefore, any perfect matching cannot pick consecutive triples! • If even triples have been chosen, set xi = 0 • If odd triples have been chosen, set xi = 1 3-D Matching Problem Have the clauses been satisfied too ? Yes ! Since the core elements of every clause gadget have been covered, the following holds true for all clauses: At least one of the three variable gadgets corresponding to a term in any clause Cj must have made the correct even/odd decision. Big Thanks to Sonika Arora