500 likes | 889 Views
NP-Completeness. Observation. All problems below are NP-complete and polynomial reduce to one another!. by definition of NP-completeness. CIRCUIT-SAT. 3-SAT. 3-SAT reduces to INDEPENDENT SET. INDEPENDENT SET. DIR-HAM-CYCLE. GRAPH 3-COLOR. SUBSET-SUM. VERTEX COVER. SCHEDULING.
E N D
NP-Completeness • Observation. All problems below are NP-complete and polynomial reduce to one another! by definition of NP-completeness CIRCUIT-SAT 3-SAT 3-SAT reduces to INDEPENDENT SET INDEPENDENT SET DIR-HAM-CYCLE GRAPH 3-COLOR SUBSET-SUM VERTEX COVER SCHEDULING HAM-CYCLE PLANAR 3-COLOR SET COVER TSP
Graph Coloring Basic genres. Packing problems: SET-PACKING, INDEPENDENT SET. Covering problems: SET-COVER, VERTEX-COVER. Constraint satisfaction problems: SAT, 3-SAT. Sequencing problems: HAMILTONIAN-CYCLE, TSP. Partitioning problems: 3D-MATCHING, 3-COLOR. Numerical problems: SUBSET-SUM, KNAPSACK.
3-Colorability • 3-COLOR: Given an undirected graph G does there exists a way to color the nodes red, green, and blue so that no adjacent nodes have the same color? yes instance
3-Colorability • Claim. 3-SAT P3-COLOR. • Pf. Given 3-SAT instance , we construct an instance of 3-COLOR that is 3-colorable iff is satisfiable. • Construction. • For each literal, create a node. • Create 3 new nodes T, F, B; connect them in a triangle, and connect each literal to B. • Connect each literal to its negation. • For each clause, add gadget of 6 nodes and 13 edges. to be described next
3-Colorability • Claim. Graph is 3-colorable iff is satisfiable. • Pf. Suppose graph is 3-colorable. • (i) Let’s call the colors of T and F “true color” and “false color”, resp. • (ii) Then each literal has either true color or false color. • (iii) A literal and its negation always have opposite colors. true false T F B base
3-Colorability • Claim. Graph is 3-colorable iff is satisfiable. • Pf. Suppose graph is 3-colorable. • (i) Let’s call the colors of T and F “true color” and “false color”, resp. • (ii) Then each literal has either true color or false color. • (iii) A literal and its negation always have opposite colors. • (iv) Ensures at least one literal in each clause is true color. B 6-node gadget T F false true
contradiction 3-Colorability • Claim. Graph is 3-colorable iff is satisfiable. • Pf. Suppose graph is 3-colorable. • (i) Let’s call the colors of T and F “true color” and “false color”, resp. • (ii) Then each literal has either true color or false color. • (iii) A literal and its negation always have opposite colors. • (iv) Ensures at least one literal in each clause is true color. B not 3-colorable if all are red T F false true
3-Colorability • Claim. Graph is 3-colorable iff is satisfiable. • Pf. Suppose graph is 3-colorable. • (i) Let’s call the colors of T and F “true color” and “false color”, resp. • (ii) Then each literal has either true color or false color. • (iii) A literal and its negation always have opposite colors. • (iv) Ensures at least one literal in each clause is true color. If a literal has a true color, then the gadget is 3-colorable. B T F false true
3-Colorability • Claim. Graph is 3-colorable iff is satisfiable. • Pf. Suppose 3-SAT formula is satisfiable. • Color all true literals green as T. • Color node below green node red as F, and node below that blue as B if possible. • Color remaining middle row nodes blue. • Color remaining bottom nodes as forced. ▪ a literal set to true in 3-SAT assignment B T F false true
Map 3-Colorability • MAP-3-COLOR. Given a planar map, can it be colored using 3 colors so that no adjacent regions have the same color? YES instance.
Map 3-Colorability • MAP-3-COLOR. Given a planar map, can it be colored using 3 colors so that no adjacent regions have the same color? NO instance.
Planarity • Def. A graph is planar if it can be embedded in the plane in such a way that no two edges cross. • Applications: VLSI circuit design, computer graphics. • Kuratowski's Theorem. An undirected graph G is non-planar iff it contains a subgraph homeomorphic to K5 or K3,3. K5: non-planar K3,3: non-planar planar homeomorphic to K3,3
Planarity Testing • Planarity testing. [Hopcroft-Tarjan 1974]O(n). • Remark. Many intractable graph problems can be solved in poly-time if the graph is planar; many tractable graph problems can be solved faster if the graph is planar. simple planar graph can have at most 3n edges
Planar Graph 3-Colorability • Q. Is this planar graph 3-colorable?
Map 3-Colorability and Graph 3-Colorability • Claim.Map-3-COLOR PPLANAR-GRAPH-3-COLOR. • Pf sketch. Create a vertex for each region, and an edge between regions that share a nontrivial border.
Planar Graph 3-Colorability • Claim. W is a planar graph such that: • In any 3-coloring of W, opposite corners have the same color. • Any assignment of colors to the corners in which opposite corners have the same color extends to a 3-coloring of W. • Pf. W has only two 3-colorings (or by permuting colors). • four corners same color four corners two colors W:
b a' a b' Planar Graph 3-Colorability • Claim. 3-COLOR PPLANAR-GRAPH-3-COLOR. • Pf. Given instance of 3-COLOR, draw graph in plane, letting edges cross. • Replace each edge crossing with planar gadget W. • In any 3-coloring of W, a a' and b b'. • If a a' and b b' then can extend to a 3-coloring of W. b a' a b' a crossing gadget W
Planar Graph 3-Colorability • Claim. 3-COLOR PPLANAR-GRAPH-3-COLOR. • Pf. Given instance of 3-COLOR, draw graph in plane, letting edges cross. • Replace each edge crossing with planar gadget W. • In any 3-coloring of W, a a' and b b'. • If a a' and b b' then can extend to a 3-coloring of W. W W W a' a a' a multiple crossings gadget W
Planar k-Colorability • PLANAR-2-COLOR. Solvable in linear time. • PLANAR-3-COLOR. NP-complete. • PLANAR-4-COLOR. Solvable in O(1) time. • Theorem. [Appel-Haken, 1976] Every planar map is 4-colorable. • Resolved century-old open problem. • Used 50 days of computer time to deal with many special cases. • First major theorem to be proved using computer. • False intuition. If PLANAR-3-COLOR is hard, then so is PLANAR-4-COLOR and PLANAR-5-COLOR.
Numerical Problems Basic genres. Packing problems: SET-PACKING, INDEPENDENT SET. Covering problems: SET-COVER, VERTEX-COVER. Constraint satisfaction problems: SAT, 3-SAT. Sequencing problems: HAMILTONIAN-CYCLE, TSP. Partitioning problems: 3-COLOR, 3D-MATCHING. Numerical problems:SUBSET-SUM, KNAPSACK.
Subset Sum • SUBSET-SUM.Given a set of natural numbers w1, …, wn and an integer W, is there a subset that adds up to exactly W? • Ex: { 1, 4, 16, 64, 256, 1040, 1041, 1093, 1284, 1344 }, W = 3754. • Yes. 1 + 16 + 64 + 256 + 1040 + 1093 + 1284 = 3754. • Remark. With arithmetic problems, input integers are encoded in binary. Polynomial reduction must be polynomial in the size of binary encoding. • Claim. 3-SAT PSUBSET-SUM. • Pf. Given an instance of 3-SAT, we construct an instance of SUBSET-SUM that has solution iff is satisfiable.
Subset Sum • Construction. Given 3-SAT instance with n variables and k clauses, form 2n + 2k decimal integers, each of n+k digits, as illustrated below. • Claim. is satisfiable iff there exists a subset that sums to W. • Pf. No carries possible. x y z C1 C2 C3 x 1 0 0 0 1 0 100,010 x 1 0 0 1 0 1 100,101 y 0 1 0 1 0 0 10,100 y 0 1 0 0 1 1 10,011 z 0 0 1 1 1 0 1,110 z 0 0 1 0 0 1 1,001 0 0 0 1 0 0 100 0 0 0 2 0 0 200 0 0 0 0 1 0 10 dummies to get clausecolumns to sum to 4 0 0 0 0 2 0 20 0 0 0 0 0 1 1 0 0 0 0 0 2 2 W 1 1 1 4 4 4 111,444
Set Partition • PARTITION.Given a set of natural numbers w1, …, wn , is there a subset that adds up to exactly half sum of all wi? • Claim. PARTITION P SUBSET-SUM. • Pf. PARTITION is a special of SUBSET-SUM. • Claim. SUBSET-SUM PPARTITION. • Pf.
Bin Packing • BIN-PACKING.Given a set S of real numbers w1, …, wn , 0 < wi 1, and integer K, is there a partition of S into K subsets such that each subset adds up no more than 1? • Claim. PARTITION P BIN-PACKING. • Pf.
The Knapsack Problem • Input • Capacity K • n items with weights wi and values vi • Goal • Output a set of items S such that • the sum of weights of items in S is at most K • and the sum of values of items in S is maximized
The Simplest Versions… • Can items be divided up such that only a portion is taken? • The thief can hold 5 pounds and has to choose from: • 3 pounds of gold dust at $379.22/pound • 6 pounds of silver dust at $188.89/pound • 1/9 pound of platinum dust at $433.25/pound • Are all of the weights or total values identical? • The thief breaks into a ring shop where all of the rings weight 1oz. He can hold 12 ounces; which should he take?
A Deceptively Hard Version… What if each problem has the same price/pound? This problem reduces to the bin-packing problem: we want to fit as many pounds of material into the knapsack as possible. How can we approach this problem?
Example The thief breaks into a gold refinery; he can steal from a selection of raw gold nuggets, each of the same value per pound. If he can carry 50 pounds, what selection would maximize the amount he carries out? 47.3 pounds 6.0 pounds 5.2 pounds 36.7 pounds 5.6 pounds 5.2 pounds 25.5 pounds 5.6 pounds 5.0 pounds 16.7 pounds 5.4 pounds 3.2 pounds 8.8 pounds 5.3 pounds 0.25 pounds
An Easier Version... What if all of the sizes we are working with are relatively small integers? For example, if we could fit 10 pounds and: Object A is 2 pounds and worth $40 Object B is 3 pounds and worth $50 Object C is 1 pound and worth $100 Object D is 5 pounds and worth $95 Object E is 3 pounds and worth $30 We can use dynamic programming!
Definining subproblems • Define P(i,w) to be the problem of choosing a set of objects from the first i objects that maximizes value subject to weight constraint of w. • V(i,w) is the value of this set of items • Original problem corresponds to V(n, K) • Recursive Definition: • V(i,w) = max (V(i-1,w-wi) + vi, V(i-1, w)) • A maximal solution for P(i,w) either • uses item i (first term in max) • or does NOT use item i (second term in max) • V(0,w) = 0 (no items to choose from) • V(i,0) = 0 (no weight allowed)
The solution... Items wA = 2 vA = $40 wB = 3 vB = $50 wC = 1 vC = $100 wD = 5 vD = $95 wE = 3 vE = $30 Weight
Decision Problem: Knapsack • KNAPSACK.Given a set of n objects, each object i has a weight wi and value vn , and two numbers W and V, is there a subset of objects whose total weight is no more than W and whose total value is no less than V? • Claim. PARTITION P KNAPSACK. • Pf.
Integer Linear Programming • Types of Integer Linear Programming Models • Graphical Solution for an All-Integer LP • Spreadsheet Solution for an All-Integer LP • Application Involving 0-l Variables • Special 0-1 Constraints
Types of Integer Programming Models • A linear program in which all the variables are restricted to be integers is called an integer linear program (ILP). • If only a subset of the variables are restricted to be integers, the problem is called a mixed integer linear program (MILP). • Binary variables are variables whose values are restricted to be 0 or 1. If all variables are restricted to be 0 or 1, the problem is called a 0-1 or binary integer program.
Example: All-Integer LP • Consider the following all-integer linear program: • Max 3x1 + 2x2 • s.t. 3x1 + x2< 9 • x1 + 3x2< 7 • -x1 + x2< 1 • x1, x2> 0 and integer
Example: All-Integer LP • LP Relaxation x2 -x1 + x2 < 1 5 3x1 + x2 < 9 4 Max 3x1 + 2x2 3 LP Optimal (2.5, 1.5) 2 x1 + 3x2 < 7 1 x1 1 2 3 4 5 6 7
Example: All-Integer LP • LP Relaxation • Solving the problem as a linear program ignoring the integer constraints, the optimal solution to the linear program gives fractional values for both x1 and x2. From the graph on the previous slide, we see that the optimal solution to the linear program is: • x1 = 2.5, x2 = 1.5, z = 10.5
Example: All-Integer LP • Rounding Up • If we round up the fractional solution (x1 = 2.5, x2 = 1.5) to the LP relaxation problem, we get x1 = 3 and x2 = 2. From the graph on the next page, we see that this point lies outside the feasible region, making this solution infeasible.
Example: All-Integer LP • Rounded Up Solution x2 -x1 + x2 < 1 5 3x1 + x2 < 9 4 Max 3x1 + 2x2 3 ILP Infeasible (3, 2) 2 LP Optimal (2.5, 1.5) x1 + 3x2 < 7 1 x1 1 2 3 4 5 6 7
Example: All-Integer LP • Rounding Down • By rounding the optimal solution down to x1 = 2, x2 = 1, we see that this solution indeed is an integer solution within the feasible region, and substituting in the objective function, it gives z = 8. • We have found a feasible all-integer solution, but have we found the optimal all-integer solution? • The answer is NO! The optimal solution is x1 = 3 and x2 = 0 giving z = 9, as evidenced in the next two slides.
Example: All-Integer LP x2 5 -x1 + x2 < 1 3x1 + x2 < 9 4 Max 3x1 + 2x2 3 2 ILP Optimal (3, 0) x1 + 3x2 < 7 1 x1 1 2 3 4 5 6 7
Example: All-Integer LP • Complete Enumeration of Feasible ILP Solutions • There are eight feasible integer solutions to this problem: • x1x2z • 1. 0 0 0 • 2. 1 0 3 • 3. 2 0 6 • 4. 3 0 9 optimal solution • 5. 0 1 2 • 6. 1 1 5 • 7. 2 1 8 • 8. 1 2 7
Special 0-1 Constraints • When xi and and xj represent binary variables designating whether projects i and j have been completed, the following special constraints may be formulated: • At most k out of n projects will be completed: • Sxj<k • Project j is conditional on project i: xj - xi< 0 • Project i is a co-requisite for project j: xj - xi = 0 • Projects i and j are mutually exclusive: xi + xj< 1
Decision Problem: 0-1 Programming • 0-1 PROGRAMMING.Given a n by m matrix A, a vector B of m numbers, a vector X of n variables, is there a binary solution of X such that AX B ? • Claim. 3-SAT P0-1 PROGRAMMING. • Pf.
Scheduling With Release Times • SCHEDULE-RELEASE-TIMES.Given a set of n jobs with processing time ti, release time ri, and deadline di, is it possible to schedule all jobs on a single machine such that job i is processed with a contiguous slot of ti time units in the interval [ri, di ] ? • Claim. SUBSET-SUM PSCHEDULE-RELEASE-TIMES. • Pf. Given an instance of SUBSET-SUM w1, …, wn, and target W, • Create n jobs with processing time ti = wi, release time ri = 0, and no deadline (di = 1 + j wj). • Create job 0 with t0 = 1, release time r0 = W, and deadline d0 = W+1. Can schedule jobs 1 to n anywhere but [W, W+1] job 0 0 W W+1 S+1
Polynomial-Time Reductions constraint satisfaction 3-SAT Dick Karp (1972)1985 Turing Award 3-SAT reduces to INDEPENDENT SET INDEPENDENT SET DIR-HAM-CYCLE GRAPH 3-COLOR SUBSET-SUM VERTEX COVER SCHEDULING HAM-CYCLE PLANAR 3-COLOR SET COVER TSP sequencing partitioning numerical packing and covering