The Theory of Complexity for Nonpreemptive Scheduling 1

  • Slides: 53
Download presentation
The Theory of Complexity for Nonpreemptive Scheduling 1

The Theory of Complexity for Nonpreemptive Scheduling 1

What is NP-completeness? n n Consider the circuit satisfiability problem Difficult to answer the

What is NP-completeness? n n 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 n

Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking n If the checking stage of a nondeterministic algorithm is of polynomial time-complexity, then this algorithm is called an NP (nondeterministic polynomial) algorithm. n 3

Nondeterministic searching algorithm Search for x in an array A n Choice(S) : arbitrarily

Nondeterministic searching algorithm Search for x in an array A n Choice(S) : arbitrarily chooses one of the elements in set S n Failure : an unsuccessful completion n Success : a successful completion n Nonderministic searching algorithm (which will be performed with unbounded parallelism): j ← choice(1 : n) /* guessing */ if A(j) = x then success /* checking */ else failure n 4

n n A nondeterministic algorithm terminates unsuccessfully iff there exist not a set of

n n A nondeterministic algorithm terminates unsuccessfully iff there exist not a set of choices leading to a success signal. A deterministic interpretation of a nondeterministic 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) 5

Nondeterministic sorting B← 0 /* guessing */ for i = 1 to n do

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 6

Exercise 1 n How to handle the circuit satisfiablity problem? 7

Exercise 1 n How to handle the circuit satisfiablity problem? 7

n n NP : the class of decision problem which can be solved by

n n 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 n n n Definition of reduction: Problem A reduces

Some concepts of NP Complete n n n 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

n If A, B NPC, then A B and B A n Theory of

n If A, B NPC, then A B and B A n 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 n The logical formula : x 1 v x 2

The circuit satisfiability problem n 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

n n If there is at least one assignment which satisfies a formula, then

n n 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 12

n Definition of the satisfiability problem: Given a Boolean formula, determine whether this formula

n Definition of the satisfiability problem: Given a Boolean formula, determine whether this formula is satisfiable or not. n n n A literal : xi or -xi A clause : x 1 v x 2 v -x 3 Ci A formula : conjunctive normal form C 1& C 2 & … & Cm 13

Cook’s theorem n n Circuit satisfiablity problem (circuit SAT) is NP -complete. It is

Cook’s theorem n n 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 NPcomplete, just need to show that they are as hard as circuit SAT problem. 14

All the NP problems reduce to circuit SAT n The proof is complicated n

All the NP problems reduce to circuit SAT n The proof is complicated n n n 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 n n n The solution is simply “Yes” or “No”. Optimization problems

Decision problems n n n The solution is simply “Yes” or “No”. Optimization problems are more difficult. e. g. the traveling salesperson problem n n 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 n Solving minimization problem by decision

Solving an optimization problem by a decision algorithm n Solving minimization problem by decision algorithm Give c 1 and test (decision algorithm) Give c 2 and test (decision algorithm) Give cn and test (decision algorithm) n n We can find the smallest ci 17

Toward NP-Completeness n n Once we have found an NP-complete problem, proving that other

Toward NP-Completeness n n 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 n n n Given that SAT problem is NP-complete, to prove

NP-Completeness Proof: CLIQUE n n n 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. n No edge within a column. n All other edges present except between x and x’ Proof: (Reduction from SAT) n CLIQUE is in NP. This is trivial since we can check it easily in polynomial time n Goal: Transform arbitrary SAT instance into CLIQUE instance such that SAT answer is “yes” iff CLIQUE answer is “yes 19

NP-Completeness Proof: CLIQUE n Example: G = n G has m-clique (m is the

NP-Completeness Proof: CLIQUE n Example: G = n 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)

Vertex Cover Given that CLIQUE problem is NP-complete, to prove that vertex cover (VC) problem is NP-complete. Definition: q A vertex cover of G=(V, E) is V’ V such that every edge in E is incident to some v V’. n Vertex Cover(VC): Given undirected G=(V, E) and integer k, does G have a vertex cover with k vertices? n CLIQUE: Does G contain a clique of size k? 21

NP-Completeness Proof: Vertex Cover(VC) n n n Problem: Given undirected G=(V, E) and integer

NP-Completeness Proof: Vertex Cover(VC) n n n 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) n VC is in NP. This is trivial since we can check it easily in polynomial time. n 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) n n Claim: CLIQUE(G, k) has same answer as VC

NP-Completeness Proof: Vertex Cover(VC) n n 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) n n Observe: If D is a VC in ,

NP-Completeness Proof: Vertex Cover(VC) n n 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 3 SAT n n n For a given Boolean formula

More convenient to use 3 SAT n n n 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

3 SAT is NP Complete n n Just need to rewrite SAT Given a

3 SAT is NP Complete n n Just need to rewrite SAT Given a clause with k variables in circuit SAT n When k = 1 n Add two more literals to construct a clause with 3 literals n Example: n Original: ci = {x} n Construction: ci_new = {(x, u 1, u 2)^(x, u 1’, u 2’)^(x, u 1, u 2’)^(x, u 1’, u 2)}, in which ’ means negation 26

3 SAT is NP Complete n n When k = 2 n Add one

3 SAT is NP Complete n n When k = 2 n Add one literal so that the number of literals in each clause is 3 n Example: n Original: ci = {(x 1, x 2)} n Add one literal ci_new = {(x 1, x 2, u)^(x 1, x 2, u’)} When k > 3 n Arrange these literals as a cascade of three literal clauses n Example: n Original: ci = {(x 1, x 2, x 3, … , xn)} n Add one literal ci_new = {(x 1, x 2, u 1)^(x 3, u 1’, u 2)^ … ^(xk-2, uk-4’, uk-3)^(xk-1, xk, uk-3’)} 27

Subset sum problem n Def: A set of positive integers A = { a

Subset sum problem n Def: A set of positive integers A = { a 1, a 2, …, n e. g. A = { 7, 5, 19, 1, 12, 8, 14 } an } a constant C Determine if A A s. t. ai = C n n C = 21, A = { 7, 14 } C = 11, no solution 28

Subset sum is NP complete n Reduce from 3 SAT problem n n E

Subset sum is NP complete n Reduce from 3 SAT problem n n 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 3 SAT n n n Table: select

Table construction for subset sum Reduce from 3 SAT n n n Table: select row T 1, T 2, T 3, F 4 according to solution Select S 21 and S 22 to make the sum of last two columns 4 Now we have found the solution for subset sum 30

Basic Construction n Basic idea n Create a table for the subset sum problem

Basic Construction n Basic idea n Create a table for the subset sum problem n n 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 2 m rows stand for TRUE and FALSE of each literal Last 2 n 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 n Def:

Exercise 2 To prove the following partition problem to be NP complete n Def: Given a set of positive integers A = { a 1, a 2, …, an }, determine if a partition P, s. t. ai = ai n i p 32

Exercise 3 n To prove the following bin packing problem to be NP complete

Exercise 3 n To prove the following bin packing problem to be NP complete n Def: n items, each of size ci , ci > 0 n bin capacity : C Determine if we can assign the items into k bins, s. t. ci C , 1 j k. i binj 33

Exercise 4 n n To prove the following knapsack problem to be NP complete

Exercise 4 n n To prove the following knapsack problem to be NP complete Def: n objects, each with a weight wi > 0 a profit pi > 0 capacity of knapsack : M Maximize pixi 1 i n Subject to wixi M 1 i n xi = 0 or 1, 1 i n n Decision version : Given K, pixi K ? 1 i n n Knapsack problem : 0 xi 1, 1 i n. 34

Three dimensional matching problem is NP complete § n n Reduce from 3 SAT

Three dimensional matching problem is NP complete § n n Reduce from 3 SAT problem to show that three dimensional matching (3 DM) 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 3 SAT by example n n n Construct a gadget with 2

Reduce from 3 SAT by example n n n Construct a gadget with 2 k cores and 2 k 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 n n Construct a gadget for each literal in a clause

Build Boolean expressions n n Construct a gadget for each literal in a clause Add two cores for each clause and enclose them with tips uncovered x 1 x 2 x 3 37

 Proof Idea n Basic idea n We choose the wings based on whether

Proof Idea n Basic idea n We choose the wings based on whether we set a variable to true or false. n We use the clean up gadgets to cover all the rest of the tips. 38

3 DM to Numerical 4 DM n n First show that numerical 4 DM

3 DM to Numerical 4 DM n n First show that numerical 4 DM is NPcomplete. Reduce from 3 DM. 4 DM problem says that given four sets S 1, S 2, S 3, S 4, each of which consists of q distinct elements, and a collection C=S 1� S 2� S 3� S 4, one asks whethere 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 3 DM to numerical 4 DM n n n n n Create

Reduce from 3 DM to numerical 4 DM n n n n n Create four elements for each candidate set (xa, yb, zc) in M. e 1 in S 1, e 2 in S 2, e 3 in S 3 and e 4 in S 4. If xa is in the candidate set, create an element e 1 with value either 2 q 3+aq 2 (core) or aq 2 (dummy). If yb is in the candidate set, create an element e 2 with value either bq (core) or q 3+bq (dummy). If zc 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 2 q 3 -aq 2 -bq-c. If there is only one occurrence of a variable (e. g. , x 1) in M, then there is only one core element generated. If there are k occurrences (e. g. , z 7) 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 4 DM is created such that it contains either all core elements or all dummy elements. Enumerate all possible candidate sets. Set B=4 q 3. 40

Reduction example n n n n n Suppose that the candidate sets M in

Reduction example n n n n n Suppose that the candidate sets M in 3 DM 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 2 q 3+q 2, e 21 with value 5 q, e 31 with value q 3+7, e 41 with value 2 q 3 -q 2 -5 q-7. (x 2, y 2, z 7) produces e 12 with value 2 q 3+2 q 2, e 22 with value 2 q, e 32 with value 7, e 42 with value 2 q 3 -2 q 2 -2 q-7. (x 2, y 5, z 5) produces e 13 with value 2 q 2, e 23 with value q 3+5 q, e 33 with value 5, e 43 with value 2 q 3 -2 q 2 -5 q-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 (2 q 2 q 3+2 q e 31 e 42) and (2 q 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 n n When there is solution of 3 DM problem, If a

If direction n n When there is solution of 3 DM problem, If a set is picked in 3 DM, the corresponding core set is picked in numerical 4 DM. Otherwise, the corresponding dummy set is picked. Each variable is picked exactly once in 3 DM, 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 4 DM). 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 e 4 for each set in M, which will be used to make the sum of values 4 q 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 n Given a solution to numerical 4 DM, each core element

Only if direction n Given a solution to numerical 4 DM, 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 4 DM to Numerical 3 DM n Given a numerical 4 DM instance,

Numerical 4 DM to Numerical 3 DM n Given a numerical 4 DM instance, we have four sets S 1, S 2, S 3, S 4. We create three new sets T 1, T 2, T 3. n n T 1 = S 1 ⋃ P where P=S 3 �S 4 are pairing elements T 2= S 2 ⋃ S 3 ⋃ F where F are fillers and |F|=q 2 q T 3=S 4 ⋃ P’ where P’ are copairing elements Form the collection as follows 44

Form Collection n n (t 1, t 2, t 3) can be formed as

Form Collection n n (t 1, t 2, t 3) can be formed as the elements from the following sets through enumeration n (S 1, S 2, P’) n (P, S 3, S 4) n (P, F, P’) Weighting functions n w 1’(p)=3 B-w 3(s 3)-w 4(s 4) n w 1’(s 1)=w 1(s 1) n w 2’(s 2)=w 2(s 2)+2 B n w 2’(s 3)=w 3(s 3)+4 B n w 2’(f)=0 n w 3’(s 4)=w 4(s 4) n w 3’(p’)=4 B+w 3(s 3)+w 4(s 4) 45

Only if direction n n When there is a solution for numerical 4 DM,

Only if direction n n When there is a solution for numerical 4 DM, for each selected candidate set (s 1, s 2, s 3, s 4), we pick (t 1, t 2, t 3) as (s 1, s 2, p’(s 3, s 4)) and (p(s 3, s 4), s 3, s 4). Since |S 1|=|S 2|=|S 3|=|S 4|=q, we have picked 2 q sets for numerical 3 DM. Since |T 1|=|T 2|=|T 3|=q 2+q, we need to pick q 2 -q sets. They are (p, f, p’). The sum of each set is 7 B 46

If Direction n n When there is a solution for numerical 3 DM, since

If Direction n n When there is a solution for numerical 3 DM, since there are only q 2 -q filler elements, we need to pick at least 2 q sets in the form of (s 1, s 2, p’) or (p, s 3, s 4) to cover all elements. Note that |S 1|=|S 2|=|S 3|=|S 4|=q, so there are only q sets of (s 1, s 2, p’) and q sets of (p, s 3, s 4). Since |P|=q 2, there are only q sets of (p, s 3, s 4) which can be picked since other |P| are picked with fillers. Similarly, since |P’|=q 2, there are only q sets of (s 1, s 2, p’) which can be picked. One then correspondingly picks (s 1, s 2, s 3, s 4) Each set has sum 7 B in numerical 3 DM, and thus each set has sum B in numerical 4 DM 47

Numerical 3 DM to 3 Partition n n Given a set S of 3

Numerical 3 DM to 3 Partition n n Given a set S of 3 m elements where each element a has a value v(s) and ∑s ∈S v(s)=m. B, one asks whether S can be partitioned into m disjoint subsets S 1, S 2, …, Sm such that for each subset ∑ s ∈ Si v(s)=B? Reduce from Numerical 3 DM with sum target B’. Form the set S as T 1 ⋃T 2 ⋃T 3 and set w(s)=w’(t)+3 i. B’ where i = 1, 2, 3. Set B=19 B’. 48

Reduction n n When there is a solution for Numerical 3 DM, one accordingly

Reduction n n When there is a solution for Numerical 3 DM, one accordingly partition the sets and each set has sum 19 B’ since the sum of elements in each set in the solution for numerical 3 DM is B’. When there is a solution for 3 Partition, one accordingly picks the sets in numerical 3 DM. 49

3 Partition to Nonpreemptive Scheduling n n Given an instance of 3 partition, form

3 Partition to Nonpreemptive Scheduling n n Given an instance of 3 partition, form an instance of nonpreemptive scheduling problem which contains 3 m+1 tasks, T 1, T 2, …, T 3 m+1 as follows. For each element si, create a task Ti with p=d=m. B+m and c=v(si). Create a task T 3 m+1 with p=B+1 and d=c=1. We claim that the task set is schedulable if and only if the 3 partition instance is feasible. 50

Only if direction n When the task set is schedulable n n n n

Only if direction n When the task set is schedulable n n n n Task T 3 m+1 is scheduled at time 0, B+1, 2(B+1), … Consider the hyper period m. B+m. All of the first 3 m tasks need to be scheduled within it. During this hyper period, T 3 m+1 has run for m times with total time m. Thus, m. B time is for all other tasks. The available time between the first and the second T 3 m+1 is B. The task set between them has total time bounded by B. Let S 1 denote the corresponding set in S, so ∑ s ∈ S 1 v(s) ≦ B Similarly, ∑ s ∈ Si v(s) ≦ B for all 1 ≦ i ≦ m since T 3 m+1 has run for m times On the other hand, ∑ s ∈ S 1 v(s) + ∑ s ∈ S 2 v(s) +…+ ∑ s ∈ Smv(s)=m. B. One has that each ∑ s ∈ Si v(s)=B. 51

If direction n When there is a feasible 3 partition solution, n n One

If direction n When there is a feasible 3 partition solution, n n One can schedule T 3 m+1 at time 0, B+1, 2(B+1), … One then puts the other tasks according to the 3 partition solution 52

Summary § § § NP-hard and NP-completeness proof Polynomial time reduction List of NP-complete

Summary § § § NP-hard and NP-completeness proof Polynomial time reduction List of NP-complete problems Knapsack and the nonpreemptive scheduling 53