15 251 Great Theoretical Ideas in Computer Science Approximation and Online Algorithms Lecture 28 April 28 2009 In the previous lecture we saw two problem classes P and NP The Class P We say a set L is in P if there is a program A and a polynomial p such that for any x in A x runs for at most p x time and answers question is x in L correctly The Class P The class of all sets L that can be recognized in polynomial time The class of all decision problems that can be decided in polynomial time P contains many useful problems graph connectivity minimum spanning tree matchings in graphs shortest paths solving linear systems Ax b linear programming maximum flows Many of this we will re visit in 15 451 NP A set L NP if there exists an algorithm A and a polynomial p such that For all x L For all x L there exists y with y p x For all y with y p x such that A x y YES such that A x y NO in p x time in p x time exists a quickly verifiable proof all non proofs rejected The Class NP The class of sets L for which there exist short proofs of membership of polynomial length that can be quickly verified in polynomial time Recall A doesn t have to find these proofs y it just needs to be able to verify that y is a correct proof P NP For any L in P we can just take y to be the empty string and satisfy the requirements Hence every language in P is also in NP Summary P versus NP Set L is in P if membership in L can be decided in poly time Set L is in NP if each x in L has a short proof of membership that can be verified in poly time Fact P NP Million Billion question Does NP P NP Contains Lots of Problems We Don t Know to be in P Classroom Scheduling Packing objects into bins Scheduling jobs on machines Finding cheap tours visiting a subset of cities Allocating variables to registers Finding good packet routings in networks Decryption What do we do now We d really like to solve these problems But we don t know how to solve them in polynomial time A solution for some of these Try to solve them approximately E g Scheduling Jobs on Machines Input A set of n jobs each job j has processing time pj A set of m identical machines E g m 4 machines n 8 jobs 5 2 2 3 1 2 3 1 E g Scheduling Jobs on Machines Input A set of n jobs each job j has processing time pj A set of m identical machines Allocate these n jobs to these m machines to minimize the latest ending time over all jobs We call this objective function the makespan we think it is NP hard NP hardness proof To prove NP hardness find a problem such that a that problem is itself NP hard b if you can solve Makespan minimization quickly you can solve that problem quickly Can you suggest such a problem The NP hard Partition Problem Given a set A a1 a2 an of n naturals which sum up to 2B B is a natural find a subset of these that sums to exactly B so we ve found a problem such that a the problem is itself NP hard b if you can solve Partition quickly you can solve Makespan minimization quickly Take any instance A a1 an B of Partition Each natural number in A corresponds to a job The processing time pj aj We have m 2 machines Easy Theorem there is a solution with makespan B iff there is a partition of A into two equal parts if you solve Makespan fast you solve Partition fast if Partition is hard Makespan is hard E g Scheduling Jobs on Machines Input A set of n jobs each job j has processing time pj A set of m identical machines Allocate these n jobs to these m machines to minimize the ending time of the last job to finish We call this objective function the makespan NP hard What do we do now Finding the best solution is hard but can we find something that is not much worse than the best Can you suggest an algorithm Graham s Greedy Algorithm Order the jobs j1 j2 jn in some order Initially all the machines are empty For t 1 to n Assign jt to the least loaded machine so far Graham s Greedy Algorithm Order the jobs j1 j2 jn in some order Initially all the machines are empty For t 1 to n Assign jt to the least loaded machine so far Theorem The MakespanGGA of this algorithm is at most 2 OptimalMakespan OPT How do you argue what the optimal value is You don t Suppose you could show that 1 MakespanGGA 2 Blah and 2 Blah OPT then you are done Two candidates for Blah Claim 1 pmax OPT Proof At least one machine gets the largest job Claim 2 t n pt m OPT Proof At least one machine must have at least the average load OPT may be much larger than either of these two pmax t n pt m E g n jobs of size 1 OPT n m pmax 1 E g 1 job of size m OPT m average load 1 Main insight OPT cannot be simultaneously larger than both Claim 3 MakespanGGA pmax t n pt m Look at the heaviest loaded machine Look at the last job jk we scheduled on this machine The load of that machine at that time was at most the average t k 1 pt m t n pt m This last job contributes a load of pk pmax Total load on this machine pmax t n pt m To recap Claim 1 pmax OPT Claim 2 t n pt m OPT Claim 3 MakespanGGA pmax t n pt m OPT OPT Theorem The MakespanGGA of this algorithm is at most 2 OPT Two obvious questions Can we analyse this algorithm better Can we give a better algorithm Is the Algorithm any better Being slightly more careful a few slides back MakespanGGA pmax 1 1 m t n pt m OPT 2 1 m But we cannot do better with this algorithm With x m 1 jobs of size 1 before one job of size x MakespanGGA x m 1 m x x 2 1 m OPT x Bad example With x m 1 jobs of size 1 before one job of size x 4 If only we hadn t spread out the small jobs earlier Better Graham s Greedy Algorithm decreasing order of size Order the jobs j1 j2 jn in some order Initially all the machines are empty For t 1 to n Assign jt to the least loaded machine so far BetterTheorem MakespanGBGA 1 5 OPT Suppose max load machine has only …
View Full Document
Unlocking...