/
CSE 421 Greedy Algorithms / Interval Scheduling Yin Tat Lee CSE 421 Greedy Algorithms / Interval Scheduling Yin Tat Lee

CSE 421 Greedy Algorithms / Interval Scheduling Yin Tat Lee - PowerPoint Presentation

celsa-spraggs
celsa-spraggs . @celsa-spraggs
Follow
342 views
Uploaded On 2019-11-06

CSE 421 Greedy Algorithms / Interval Scheduling Yin Tat Lee - PPT Presentation

CSE 421 Greedy Algorithms Interval Scheduling Yin Tat Lee 1 Interval Scheduling Job starts at and finishes at Two jobs compatible if they dont overlap Goal find maximum subset of mutually compatible jobs ID: 763797

schedule time lateness greedy time schedule greedy lateness jobs classroom inversions optimal job order finish compatible room maximum algorithm

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "CSE 421 Greedy Algorithms / Interval Sch..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

CSE 421 Greedy Algorithms / Interval SchedulingYin Tat Lee 1

Interval Scheduling Job starts at and finishes at .Two jobs compatible if they don’t overlap.Goal: find maximum subset of mutually compatible jobs.   2 Time 0 1 2 3 4 5 6 7 8 9 10 11 f g h e a b c d h e b

Greedy Alg : Earliest Finish Time Consider jobs in increasing order of finish time. Take each job provided it’s compatible with the ones already taken. Implementation. Remember job that was added last to . Job is compatible with if .   3 Sort jobs by finish times so that f(1)  f(2)  ...  f(n). for j = 1 to n { if (job j compatible with ) }return  

Correctness Theorem: Greedy algorithm is optimal. Proof: (technique: “Greedy stays ahead”)Let be jobs picked by greedy, those in some optimal solution in order. We show for all , by induction on . Base Case: chosen to have min finish time, so . IH: for some r IS: Since , is among the candidates considered by greedy when it picked , & it picks min finish, so Observe that we must have , else is among (nonempty) set of candidates for .   4

CSE 421 Greedy Algorithms / Interval PartitioningYin Tat Lee 5

Interval Partitioning Lecture starts at and finishes at .Goal: find minimum number of classrooms to schedule all lectures so that no two occur at the same time in the same room.  6 Time 9 9:30 10 10:30 11 11:30 12 12:30 1 1:30 2 2:30 h c b a e d g f i j 3 3:30 4 4:30 Room 1 Room 2 Room 3 Room 4

Interval Partitioning 7 Time 9 9:30 10 10:30 11 11:30 12 12:30 1 1:30 2 2:30 h c b a e d g f i j 3 3:30 4 4:30 Room 1 Room 2 Room 3 Room 4 C B A E D G F J H I Note: graph coloring is hard in general, but graphs corresponding to interval intersections are simpler.

A Better Schedule This one uses only 3 classrooms 8 Time 9 9:30 10 10:30 11 11:30 12 12:30 1 1:30 2 2:30 h c a e f g i j 3 3:30 4 4:30 d b

A Greedy Algorithm Greedy algorithm: Consider lectures in increasing order of finish time: assign lecture to any compatible classroom. Correctness : This is wrong! 9 Sort intervals by finish time so that f 1  f 2  ...  fn.d  0 for j = 1 to n { if (lect j is compatible with some classroom k, ) schedule lecture j in classroom k else allocate a new classroom d + 1 schedule lecture j in classroom d + 1 d  d + 1 }  

Example 10 Time 0 1 2 3 4 5 6 d a b c Time 0 1 2 3 4 5 6 d a b c Greedy by finish time gives: OPT: Time 0 1 2 3 4 5 6 d a b c In the interval scheduling problem, we want to ignore super long job. In this problem, we need to schedule all the jobs. Picking them tightly is important.

A Greedy Algorithm Greedy algorithm: Consider lectures in increasing order of start time: assign lecture to any compatible classroom. Implementation: Exercise! 11 Sort intervals by starting time so that s 1  s2  ...  sn .d  0for j = 1 to n { if (lect j is compatible with some classroom k, ) schedule lecture j in classroom k else allocate a new classroom d + 1 schedule lecture j in classroom d + 1 d  d + 1 }  

A Structural Lower-Bound on OPT Def . The depth of a set of open intervals is the maximum number that contains any given time.Key observation. Number of classrooms needed  depth.Ex: Depth of schedule below  schedule below is optimal .Q. Does there always exist a schedule equal to depth of intervals?  12 Time 9 9:30 10 10:30 11 11:30 12 12:30 1 1:30 2 2:30 h c a e f g i j 3 3:30 4 4:30 d b

Correctness Theorem: Greedy algorithm is optimal. Proof (exploit structural property). Let # classrooms greedy allocates.Classroom is opened because there are classrooms are in use.So, lectures overlapping at time , i.e. depth .So, all schedules use  d classrooms, So, greedy is optimal ▪  13

CSE 421 Greedy Algorithms / Minimizing LatenessYin Tat Lee 14

Scheduling to Minimizing Lateness Similar to interval scheduling. Instead of start and finish times, request has Time Requirement which must be scheduled in a contiguous blockDeadline by which time the request would like to be finishedRequests are scheduled into time intervals s.t. .Lateness for request is If then request is late by otherwise its lateness Goal: Find a schedule that minimize the Maximum lateness     6   3 1 8 2 2 9 1 3 9 4 4 14 3 5 15 2 6 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 d 5 = 14 d 2 = 8 d 6 = 15 d 1 = 6 d 4 = 9 d 3 = 9 lateness = 0 lateness = 2 max lateness = 6

16 Minimizing Lateness: Greedy Algorithms Greedy template. Consider jobs in some order. [Shortest processing time first] Consider jobs in ascending order of processing time . [Smallest slack] Consider jobs in ascending order of slack .[Earliest deadline first] Consider jobs in ascending order of deadline .   counterexample d j t j 100 1 1 10 10 2 counterexample d j t j 2 1 1 10 10 2

Greedy Algorithm: Earliest Deadline First 17 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 d 4 = 9 d 5 = 14 d 2 = 8 d 6 = 15 d 1 = 6 d 3 = 9 max lateness = 1 Sort deadlines in increasing order for to to end for     6   3 1 8 2 2 9 1 3 9 4 4 14 3 5 15 2 6

Minimizing Lateness: No Idle Time 18 Observation. There exists an optimal schedule with no idle time . Observation. The greedy schedule has no idle time. 0 1 2 3 4 5 6 d = 4 d = 6 7 8 9 10 11 d = 12 0 1 2 3 4 5 6 d = 4 d = 6 7 8 9 10 11 d = 12

Proof for Greedy Algorithm: Exchange Argument We will show that if there is another schedule (think optimal schedule) then we can gradually change so that at each step the maximum lateness in never gets worse.it eventually becomes the same cost as .  19

Minimizing Lateness: Inversions 20 i j before swap inversion Definition An adjacent inversion in schedule is a pair of jobs and such that Job is scheduled immediately after Job Observation Greedy schedule has no adjacent inversions.  

Minimizing Lateness: Inversions 21 Definition An adjacent inversion in schedule is a pair of jobs and such that Job is scheduled immediately after Job ClaimSwapping two adjacent, inverted jobs reduces the number of inversions by one and does not increase the max lateness.   i j i j before swap after swap     inversion

Minimizing Lateness: Inversions Lemma: Swapping two adjacent, inverted jobs does not increase the maximum lateness. Proof: Let be the schedule after swapping. Lateness since is scheduled earlier in than in Requests and together occupy the same total time slot in both schedulesAll other requests have so Maximum lateness has not increased!   22 i j i j before swap after swap     inversion

Optimal schedules and inversions Claim: There is an optimal schedule with no idle time and no inversions Proof: By previous argument there is an optimal schedule with no idle timeIf has an inversion then it has a consecutive pair of requests in its schedule that are inverted and can be swapped without increasing latenessEventually these swaps will produce an optimal schedule with no inversionsEach swap decreases the number of inversions by 1There are at most inversions. (we only care that this is finite.)  14

Idleness and Inversions are the only issue 24 Claim: All schedules with no inversions and no idle time have the same maximum lateness Proof:Schedules can differ only in how they order requests with equal deadlinesConsider all requests having some common deadline Maximum lateness of these jobs is based only on the finish time of the last of these jobs but the set of these requests occupies the same time segment in both schedules Last of these requests finishes at the same time in any such schedule.