The Theory of Complexity for Nonpreemptive Scheduling 1
What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial time with the classical deterministic algorithms 2
Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking stage of a nondeterministic algorithm is of polynomial time-complexity, then this algorithm is called an NP (nondeterministic polynomial) algorithm. 3
4 N ondeterministic searching algorithm Search for x in an array A Choice(S) : arbitrarily chooses one of the elements in set S Failure : an unsuccessful completion Success : a successful completion Nonderministic searching algorithm (which will be performed with unbounded parallelism): j ← choice(1 : n) /* guessing */ if A(j) = x then success /* checking */ else failure
5 A nondeterministic algorithm terminates unsuccessfully iff there exist not a set of choices leading to a success signal. A deterministic interpretation of a non- deterministic algorithm can be made by allowing unbounded parallelism in computation. The runtime required for choice(1 : n) is O(1). The runtime for nondeterministic searching algorithm is also O(1)
6 Nondeterministic sorting B ← 0 /* guessing */ for i = 1 to n do j ← choice(1 : n) if B[j] ≠ 0 then failure B[j] = A[i] /* checking */ for i = 1 to n-1 do if B[i] > B[i+1] then failure success Perform the above with unbounded parallelism
Exercise 1 How to handle the circuit satisfiablity problem? 7
NP : the class of decision problem which can be solved by a non-deterministic polynomial algorithm. P: the class of problems which can be solved by a deterministic polynomial algorithm. NP-hard: the class of problems to which every NP problem reduces. NP-complete (NPC): the class of problems which are NP-hard and belong to NP. 8
Some concepts of NP Complete Definition of reduction: Problem A reduces to problem B (A B) iff A can be solved by a deterministic polynomial time algorithm using a deterministic algorithm that solves B in polynomial time. B is harder. Up to now, none of the NPC problems can be solved by a deterministic polynomial time algorithm in the worst case. It does not seem to have any polynomial time algorithm to solve the NPC problems. 9
If A, B NPC, then A B and B A Theory of NP-completeness If any NPC problem can be solved in polynomial time, then all NP problems can be solved in polynomial time. (NP = P) 10
The circuit satisfiability problem The logical formula : x 1 v x 2 v x 3 & - x 1 & - x 2 the assignment : x 1 ← F, x 2 ← F, x 3 ← T will make the above formula true. (-x 1, -x 2, x 3 ) represents x 1 ← F, x 2 ← F, x 3 ← T 11
If there is at least one assignment which satisfies a formula, then we say that this formula is satisfiable; otherwise, it is unsatisfiable. An unsatisfiable formula : x 1 v x 2 & x 1 v -x 2 & -x 1 v x 2 & -x 1 v -x 2 12
Definition of the satisfiability problem: Given a Boolean formula, determine whether this formula is satisfiable or not. A literal : x i or -x i A clause : x 1 v x 2 v -x 3 C i A formula : conjunctive normal form C 1 & C 2 & … & C m 13
Cook ’ s theorem Circuit satisfiablity problem (circuit SAT) is NP-complete. It is the first NP-complete problem. Every NP problem reduces to circuit SAT. To prove the other problems to be NP- complete, just need to show that they are as hard as circuit SAT problem. 14
All the NP problems reduce to circuit SAT The proof is complicated Any problem in NP can be computed with a Boolean combination circuit (i.e., a computer) This circuit has a polynomial number of elements and can be constructed in polynomial time The circuit runs in polynomial time so we can check the result in polynomial time 15
Decision problems The solution is simply “ Yes ” or “ No ”. Optimization problems are more difficult. e.g. the traveling salesperson problem Optimization version: Find the shortest tour Decision version: Is there a tour whose total length is less than or equal to a constant c ? 16
Solving an optimization problem by a decision algorithm Solving minimization problem by decision algorithm Give c 1 and test (decision algorithm) Give c 2 and test (decision algorithm) Give c n and test (decision algorithm) We can find the smallest c i 17
Toward NP-Completeness Once we have found an NP-complete problem, proving that other problems are also NP-complete becomes easier. Given a new problem Y, it is sufficient to prove that Cook’s problem, or any other NP-complete problems, is polynomially reducible to Y. Known problem -> unknown problem 18
NP-Completeness Proof: CLIQUE Given that SAT problem is NP-complete, to prove that CLIQUE problem is NP-complete Problem: Does G=(V,E) contain a clique of size k? Theorem: Clique is NP-Complete. (reduction from SAT) Idea: Make “column” for each of k clauses. No edge within a column. All other edges present except between x and x’ Proof: (Reduction from SAT) CLIQUE is in NP. This is trivial since we can check it easily in polynomial time Goal: Transform arbitrary SAT instance into CLIQUE instance such that SAT answer is “yes” iff CLIQUE answer is “yes 19
NP-Completeness Proof: CLIQUE Example: G = G has m-clique (m is the number of clauses in E), iff E is satisfiable. (Assign value 1 to all variables in clique) 20
Vertex Cover Given that CLIQUE problem is NP-complete, to prove that vertex cover (VC) problem is NP-complete. Definition: A vertex cover of G=(V, E) is V’ V such that every edge in E is incident to some v V’. Vertex Cover(VC): Given undirected G=(V, E) and integer k, does G have a vertex cover with k vertices? CLIQUE: Does G contain a clique of size k? 21
NP-Completeness Proof: Vertex Cover(VC) Problem: Given undirected G=(V, E) and integer k, does G have a vertex cover with k vertices? Theorem: the VC problem is NP-complete. Proof: (Reduction from CLIQUE) VC is in NP. This is trivial since we can check it easily in polynomial time. Goal: Transform arbitrary CLIQUE instance into VC instance such that CLIQUE answer is “yes” iff VC answer is “yes”. 22
NP-Completeness Proof: Vertex Cover(VC) Claim: CLIQUE(G, k) has same answer as VC (, n-k), where n = |V|. Observe: There is a clique of size k in G iff there is a VC of size n-k in. 23
NP-Completeness Proof: Vertex Cover(VC) Observe: If D is a VC in, then has no edge between vertices in V-D. So, we have k-clique in G n-k VC in Can transform in polynomial time. 24
More convenient to use 3SAT For a given Boolean formula in conjunctive normal form (CNF) where each clause contains three variables, find the assignment to make it true Example: Can we find an assignment to make E true? 25
3SAT is NP Complete Just need to rewrite SAT Given a clause with k variables in circuit SAT When k = 1 Add two more literals to construct a clause with 3 literals Example: Original: c i = {x} Construction: c i_new = {(x, u1, u2)^(x, u1’, u2’)^(x, u1, u2’)^(x, u1’, u2)}, in which ’ means negation 26
3SAT is NP Complete When k = 2 Add one literal so that the number of literals in each clause is 3 Example: Original: c i = {(x1, x2)} Add one literal c i_new = {(x1, x2, u)^(x1, x2, u’)} When k > 3 Arrange these literals as a cascade of three literal clauses Example: Original: c i = {(x1, x2, x3, …, xn)} Add one literal c i_new = {(x1, x2, u1)^(x3, u1’, u2)^ … ^(x k-2, u k-4 ’, u k-3 )^(x k-1, x k, u k-3 ’)} 27
Subset sum problem Def: A set of positive integers A = { a 1, a 2, …, a n } a constant C Determine if A A s.t. a i = C e.g. A = { 7, 5, 19, 1, 12, 8, 14 } C = 21, A = { 7, 14 } C = 11, no solution 28
Subset sum is NP complete Reduce from 3SAT problem E = (u 1 + u 3 ’ + u 4 ’)(u 1 ’ + u 2 + u 4 ’) There are 4 literals There are n = 2 clauses in the expression above Suppose the solution is u 1 = u 2 = u 3 = 1, u 4 = 0 29
Table construction for subset sum Reduce from 3SAT select row T1, T2, T3, F4 according to solution Select S2 1 and S2 2 to make the sum of last two columns 4 Now we have found the solution for subset sum Table: 30
Basic Construction Basic idea Create a table for the subset sum problem The first m columns of the table stand for each one of m literals Last n columns stand for each one of m clauses First 2m rows stand for TRUE and FALSE of each literal Last 2n rows stores additional number for each clause to make the sum of this column a constant 31
Exercise 2 To prove the following partition problem to be NP complete Def: Given a set of positive integers A = { a 1,a 2, …,a n }, determine if a partition P, s.t. a i = a i i p i p 32
Exercise 3 To prove the following bin packing problem to be NP complete Def: n items, each of size c i, c i > 0 bin capacity : C Determine if we can assign the items into k bins, s.t. c i C, 1 j k. i bin j 33
Exercise 4 To prove the following knapsack problem to be NP complete Def: n objects, each with a weight w i > 0 a profit p i > 0 capacity of knapsack : M Maximize p i x i 1 i n Subject to w i x i M 1 i n x i = 0 or 1, 1 i n Decision version : Given K, p i x i K ? 1 i n Knapsack problem : 0 x i 1, 1 i n. 34
Three dimensional matching problem is NP complete Reduce from 3SAT problem to show that three dimensional matching (3DM) problem is NP-complete. X, Y, and Z are finite disjoint sets T = X × Y × Z Find M ⊆ T such that for any two distinct triples (x 1, y 1, z 1 ) ∈ M and (x 2, y 2, z 2 ) ∈ M, we have x 1 ≠x 2, y 1 ≠y 2, and z 1 ≠z 2 M covers all elements in X, Y and Z 35
Reduce from 3SAT by example Construct a gadget with 2k cores and 2k tips for each variable x Example: k = 2 This gadget can work as a Boolean variable: when x = 1, we choose cores and tips in light region; when x = 0, we choose the blue region 36
Build Boolean expressions Construct a gadget for each literal in a clause Add two cores for each clause and enclose them with tips uncovered x1x1 x2x2 x3x3 37
Proof Idea Basic idea We choose the wings based on whether we set a variable to true or false. We use the clean up gadgets to cover all the rest of the tips. 38
3DM to Numerical 4DM First show that numerical 4DM is NP- complete. Reduce from 3DM. 4DM problem says that given four sets S1,S2,S3,S4, each of which consists of q distinct elements, and a collection C=S1S2S3S4, one asks whether there exists a subcollection C’ to partition the union of four sets and the sum of values of each set in C’ is B. 39
Reduce from 3DM to numerical 4DM Create four elements for each candidate set (x a,y b,z c ) in M. e 1 in S 1, e 2 in S 2, e 3 in S 3 and e 4 in S 4. If x a is in the candidate set, create an element e 1 with value either 2q 3 +aq 2 (core) or aq 2 (dummy). If y b is in the candidate set, create an element e 2 with value either bq (core) or q 3 +bq (dummy). If z c is in the candidate set, create an element e 3 with value either c (core) or q 3 +c (dummy). create an element e 4 with value 2q 3 -aq 2 -bq-c. If there is only one occurrence of a variable (e.g., x1) in M, then there is only one core element generated. If there are k occurrences (e.g., z7) in M, then there are k elements generated where contains one core element and k-1 dummy elements. Note that different elements can have the same value. Candidate sets in 4DM is created such that it contains either all core elements or all dummy elements. Enumerate all possible candidate sets. Set B=4q 3. 40
Reduction example Suppose that the candidate sets M in 3DM is as follows. (x 1,y 5,z 7 ), (x 2,y 2,z 7 ), (x 2,y 5,z 5 ) … (x 1,y 5,z 7 ) produces e 11 with value 2q 3 +q 2, e 21 with value 5q, e 31 with value q 3 +7, e 41 with value 2q 3 -q 2 -5q-7. (x 2,y 2,z 7 ) produces e 12 with value 2q 3 +2q 2, e 22 with value 2q, e 32 with value 7, e 42 with value 2q 3 -2q 2 -2q-7. (x 2,y 5,z 5 ) produces e 13 with value 2q 2, e 23 with value q 3 +5q, e 33 with value 5, e 43 with value 2q 3 -2q 2 -5q-5. If (x 1,y 5,z 7 ) is picked in M, we pick (e 11 e 21 e 32 e 41 ). Since (x 2,y 2,z 7 ), (x 2,y 5,z 5 ) are not picked, we pick (2q 2 q 3 +2q e 31 e 42 ) and (2q 2 e 23 e 33 e 43 ). The elements with values are those generated from other candidate sets in M. e 12 e 22 e 13 are not picked and they will be picked corresponding to some sets picked in M. 41
If direction When there is solution of 3DM problem, If a set is picked in 3DM, the corresponding core set is picked in numerical 4DM. Otherwise, the corresponding dummy set is picked. Each variable is picked exactly once in 3DM, so each core element is picked exactly once. Note that core elements generated from multiple sets in M could be combined together and picked (since we enumerate candidate sets in numerical 4DM). Given k occurrences of a variable in M, they are in k candidate sets in M. One of them is picked (so is the corresponding core element), and k-1 of them is not picked (so the corresponding k-1 dummy elements are picked). Thus, each generated element is picked exactly once. There is only one e4 for each set in M, which will be used to make the sum of values 4q 3. This is the subcollection of sets to partition the union of four sets and each set with the sum of values to be B. 42
Only if direction Given a solution to numerical 4DM, each core element is covered exactly once. There exists sets which contain only the core elements and one can pick the corresponding sets in M. 43
Numerical 4DM to Numerical 3DM Given a numerical 4DM instance, we have four sets S1, S2, S3, S4. We create three new sets T1, T2, T3. T1 = S1 ⋃ P where P=S3 S4 are pairing elements T2= S2 ⋃ S3 ⋃ F where F are fillers and |F|=q 2 -q T3=S4 ⋃ P’ where P’ are copairing elements Form the collection as follows 44
Form Collection (t1,t2,t3) can be formed as the elements from the following sets through enumeration (S1,S2,P’) (P,S3,S4) (P,F,P’) Weighting functions w1’(p)=3B-w3(s3)-w4(s4) w1’(s1)=w1(s1) w2’(s2)=w2(s2)+2B w2’(s3)=w3(s3)+4B w2’(f)=0 w3’(s4)=w4(s4) w3’(p’)=4B+w3(s3)+w4(s4) 45
Only if direction When there is a solution for numerical 4DM, for each selected candidate set (s1,s2,s3,s4), we pick (t1,t2,t3) as (s1,s2,p’(s3,s4)) and (p(s3,s4),s3,s4). Since |S1|=|S2|=|S3|=|S4|=q, we have picked 2q sets for numerical 3DM. Since |T1|=|T2|=|T3|=q 2 +q, we need to pick q 2 -q sets. They are (p,f,p’). The sum of each set is 7B 46
If Direction When there is a solution for numerical 3DM, since there are only q 2 -q filler elements, we need to pick at least 2q sets in the form of (s1,s2,p’) or (p,s3,s4) to cover all elements. Note that |S1|=|S2|=|S3|=|S4|=q, so there are only q sets of (s1,s2,p’) and q sets of (p,s3,s4). Since |P|=q 2, there are only q sets of (p,s3,s4) which can be picked since other |P| are picked with fillers. Similarly, since |P’|=q 2, there are only q sets of (s1,s2,p’) which can be picked. One then correspondingly picks (s1,s2,s3,s4) Each set has sum 7B in numerical 3DM, and thus each set has sum B in numerical 4DM 47
Numerical 3DM to 3Partition Given a set S of 3m elements where each element a has a value v(s) and ∑ s ∈ S v(s)=mB, one asks whether S can be partitioned into m disjoint subsets S 1,S 2,…,S m such that for each subset ∑ s ∈ Si v(s)=B? Reduce from Numerical 3DM with sum target B’. Form the set S as T1 ⋃ T2 ⋃ T3 and set w(s)=w’(t)+3iB’ where i = 1,2,3. Set B=19B’. 48
Reduction When there is a solution for Numerical 3DM, one accordingly partition the sets and each set has sum 19B’ since the sum of elements in each set in the solution for numerical 3DM is B’. When there is a solution for 3Partition, one accordingly picks the sets in numerical 3DM. 49
3Partition to Nonpreemptive Scheduling Given an instance of 3partition, form an instance of nonpreemptive scheduling problem which contains 3m+1 tasks, T 1,T 2,…,T 3m+1 as follows. For each element s i, create a task T i with p=d=mB+m and c=v(s i ). Create a task T 3m+1 with p=B+1 and d=c=1. We claim that the task set is schedulable if and only if the 3partition instance is feasible. 50
Only if direction When the task set is schedulable Task T 3m+1 is scheduled at time 0, B+1, 2(B+1), … Consider the hyper period mB+m. All of the first 3m tasks need to be scheduled within it. During this hyper period, T 3m+1 has run for m times with total time m. Thus, mB time is for all other tasks. The available time between the first and the second T 3m+1 is B. The task set between them has total time bounded by B. Let S1 denote the corresponding set in S, so ∑ s ∈ S1 v(s) ≦ B Similarly, ∑ s ∈ Si v(s) ≦ B for all 1 ≦ i ≦ m since T 3m+1 has run for m times On the other hand, ∑ s ∈ S1 v(s) + ∑ s ∈ S2 v(s) +…+ ∑ s ∈ Sm v(s)=mB. One has that each ∑ s ∈ Si v(s)=B. 51
If direction When there is a feasible 3partition solution, One can schedule T 3m+1 at time 0, B+1, 2(B+1),… One then puts the other tasks according to the 3partition solution 52
Summary NP-hard and NP-complete NP-completeness proof Polynomial time reduction List of NP-complete problems Knapsack and the nonpreemptive scheduling 53