Chapter 4 4.1 Interval Scheduling

Chapter 4 4.1 Interval Scheduling

4.1 Interval Scheduling Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 1 Interval Scheduling Interval Scheduling: Greedy Algorithms Interval scheduling. Greedy template. Consider jobs in some natural order. Job j starts at sj and finishes at fj. Take each job provided it's compatible with the ones already taken. Two jobs compatible if they don't overlap. Goal: find maximum subset of mutually compatible jobs. [Earliest start time] Consider jobs in ascending order of sj. [Earliest finish time] Consider jobs in ascending order of fj. a [Shortest interval] Consider jobs in ascending order of f - s . b j j c [Fewest conflicts] For each job j, count the number of d conflicting jobs cj. Schedule in ascending order of cj. e f g h Time 0 1 2 3 4 5 6 7 8 9 10 11 3 4 Interval Scheduling: Greedy Algorithms Interval Scheduling: Greedy Algorithm Greedy template. Consider jobs in some natural order. Greedy algorithm. Consider jobs in increasing order of finish time. Take each job provided it's compatible with the ones already taken. Take each job provided it's compatible with the ones already taken. Sort jobs by finish times so that f1 ≤ f2 ≤ ... ≤ fn. counterexample for earliest start time set of jobs selected A ← φ for j = 1 to n { counterexample for shortest interval if (job j compatible with A) A ← A ∪ {j} } return A counterexample for fewest conflicts Implementation. O(n log n). Remember job j* that was added last to A. Job j is compatible with A if sj ≥ fj*. 5 6 Interval Scheduling: Analysis Interval Scheduling: Analysis Theorem. Greedy algorithm is optimal. Theorem. Greedy algorithm is optimal. Pf. (by contradiction) Pf. (by contradiction) Assume greedy is not optimal, and let's see what happens. Assume greedy is not optimal, and let's see what happens. Let i1, i2, ... ik denote set of jobs selected by greedy. Let i1, i2, ... ik denote set of jobs selected by greedy. Let j1, j2, ... jm denote set of jobs in the optimal solution with Let j1, j2, ... jm denote set of jobs in the optimal solution with i1 = j1, i2 = j2, ..., ir = jr for the largest possible value of r. i1 = j1, i2 = j2, ..., ir = jr for the largest possible value of r. job ir+1 finishes before jr+1 job ir+1 finishes before jr+1 Greedy: i1 i2 ir ir+1 Greedy: i1 i2 ir ir+1 OPT: j1 j2 jr jr+1 . OPT: j1 j2 jr ir+1 . why not replace job jr+1 solution still feasible and optimal, but contradicts maximality of r. with job ir+1? 7 8 Interval Partitioning 4.1 Interval Partitioning Interval partitioning. Lecture j starts at sj and finishes at fj. Goal: find minimum number of classrooms to schedule all lectures so that no two occur at the same time in the same room. Ex: This schedule uses 4 classrooms to schedule 10 lectures. 4 e j 3 c d g 2 b h 1 a f i 9 9:30 10 10:30 11 11:30 12 12:30 1 1:30 2 2:30 3 3:30 4 4:30 Time 10 Interval Partitioning Interval Partitioning: Lower Bound on Optimal Solution Interval partitioning. Def. The depth of a set of open intervals is the maximum number that Lecture j starts at sj and finishes at fj. contain any given time. Goal: find minimum number of classrooms to schedule all lectures so that no two occur at the same time in the same room. Key observation. Number of classrooms needed ≥ depth. Ex: This schedule uses only 3. Ex: Depth of schedule below = 3 ⇒ schedule below is optimal. a, b, c all contain 9:30 Q. Does there always exist a schedule equal to depth of intervals? 3 c d f j 3 c d f j 2 b g i 2 b g i 1 a e h 1 a e h 9 9:30 10 10:30 11 11:30 12 12:30 1 1:30 2 2:30 3 3:30 4 4:30 9 9:30 10 10:30 11 11:30 12 12:30 1 1:30 2 2:30 3 3:30 4 4:30 Time Time 11 12 Interval Partitioning: Greedy Algorithm Interval Partitioning: Greedy Analysis Greedy algorithm. Consider lectures in increasing order of start time: Observation. Greedy algorithm never schedules two incompatible assign lecture to any compatible classroom. lectures in the same classroom. Theorem. Greedy algorithm is optimal. Sort intervals by starting time so that s1 ≤ s2 ≤ ... ≤ sn. Pf. d ← 0 number of allocated classrooms Let d = number of classrooms that the greedy algorithm allocates. for j = 1 to n { if (lecture j is compatible with some classroom k) Classroom d is opened because we needed to schedule a job, say j, schedule lecture j in classroom k that is incompatible with all d-1 other classrooms. else These d jobs each end after sj. allocate a new classroom d + 1 schedule lecture j in classroom d + 1 Since we sorted by start time, all these incompatibilities are caused d ← d + 1 by lectures that start no later than sj. } Thus, we have d lectures overlapping at time sj + ε. Key observation ⇒ all schedules use ≥ d classrooms. ▪ Implementation. O(n log n). For each classroom k, maintain the finish time of the last job added. Keep the classrooms in a priority queue. 13 14 Scheduling to Minimizing Lateness 4.2 Scheduling to Minimize Lateness Minimizing lateness problem. Single resource processes one job at a time. Job j requires tj units of processing time and is due at time dj. If j starts at time sj, it finishes at time fj = sj + tj. Lateness: lj = max { 0, fj - dj }. Goal: schedule all jobs to minimize maximum lateness L = max lj. Ex: 1 2 3 4 5 6 tj 3 2 1 4 3 2 dj 6 8 9 9 14 15 lateness = 2 lateness = 0 max lateness = 6 d3 = 9 d2 = 8 d6 = 15 d1 = 6 d5 = 14 d4 = 9 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Minimizing Lateness: Greedy Algorithms Minimizing Lateness: Greedy Algorithms Greedy template. Consider jobs in some order. Greedy template. Consider jobs in some order. [Shortest processing time first] Consider jobs in ascending order [Shortest processing time first] Consider jobs in ascending order of processing time tj. of processing time tj. 1 2 tj 1 10 counterexample [Earliest deadline first] Consider jobs in ascending order of dj 100 10 deadline dj. [Smallest slack] Consider jobs in ascending order of slack dj - tj. [Smallest slack] Consider jobs in ascending order of slack dj - tj. 1 2 t 1 10 j counterexample dj 2 10 17 18 Minimizing Lateness: Greedy Algorithm Minimizing Lateness: No Idle Time Greedy algorithm. Earliest deadline first. Observation. There exists an optimal schedule with no idle time. d = 4 d = 6 d = 12 0 1 2 3 4 5 6 7 8 9 10 11 Sort n jobs by deadline so that d1 ≤ d2 ≤ … ≤ dn t ← 0 for j = 1 to n d = 4 d = 6 d = 12 0 1 2 3 4 5 6 7 8 9 10 11 Assign job j to interval [t, t + tj] sj ← t, fj ← t + tj t ← t + tj output intervals [sj, fj] Observation. The greedy schedule has no idle time. max lateness = 1 d1 = 6 d2 = 8 d3 = 9 d4 = 9 d5 = 14 d6 = 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 19 20 Minimizing Lateness: Inversions Minimizing Lateness: Inversions Def. Given a schedule S, an inversion is a pair of jobs i and j such that: Def. Given a schedule S, an inversion is a pair of jobs i and j such that: i < j but j scheduled before i. i < j but j scheduled before i. inversion inversion fi fi before swap j i before swap j i after swap i j [ as before, we assume jobs are numbered so that d1 ≤ d2 ≤ … ≤ dn ] f'j Observation. Greedy schedule has no inversions. Claim. Swapping two consecutive, inverted jobs reduces the number of inversions by one and does not increase the max lateness. Observation. If a schedule (with no idle time) has an inversion, it has one with a pair of inverted jobs scheduled consecutively. Pf. Let l be the lateness before the swap, and let l ' be it afterwards. l 'k = lk for all k ≠ i, j " = f " # d (definition) l 'i ≤ li l j j j = fi # d j ( j finishes at time fi ) If job j is late: $ fi # di (i < j) $ l i (definition) 21 22 ! Minimizing Lateness: Analysis of Greedy Algorithm Greedy Analysis Strategies Theorem. Greedy schedule S is optimal. Greedy algorithm stays ahead. Show that after each step of the greedy Pf. Define S* to be an optimal schedule that has the fewest number of algorithm, its solution is at least as good as any other algorithm's. inversions, and let's see what happens. Can assume S* has no idle time. Structural. Discover a simple "structural" bound asserting that every If S* has no inversions, then S = S*. possible solution must have a certain value. Then show that your If S* has an inversion, let i-j be an adjacent inversion. algorithm always achieves this bound. – swapping i and j does not increase the maximum lateness and strictly decreases the number of inversions Exchange argument. Gradually transform any solution to the one found – this contradicts definition of S* ▪ by the greedy algorithm without hurting its quality.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    13 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us