CS代考 Interval Scheduling

Interval Scheduling

Interval Scheduling
Interval scheduling.

Copyright By PowCoder代写 加微信 powcoder

Job j starts at sj and finishes at fj.
! Two jobs compatible if they don’t overlap.
! Goal: find maximum subset of mutually compatible jobs.
0 1 2 3 4 5 6 7 8 9 10 11

Interval Scheduling
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2 3 4 5 6 7 8 9 10 11

Interval Scheduling
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2 3 4 5 6 7 8 9 10 11

Interval Scheduling
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2 3 4 5 6 7 8 9 10 11

Interval Scheduling
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2 3 4 5 6 7 8 9 10 11

Interval Scheduling
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2 3 4 5 6 7 8 9 10 11

Interval Scheduling
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2 3 4 5 6 7 8 9 10 11

Interval Scheduling
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2 3 4 5 6 7 8 9 10 11

Interval Scheduling
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2 3 4 5 6 7 8 9 10 11

Interval Scheduling
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2 3 4 5 6 7 8 9 10 11

Interval Scheduling: Greedy Algorithms
Greedy template. Consider jobs in some natural order.
Take each job provided it’s compatible with the ones already taken.
[Earliest start time] Consider jobs in ascending order of sj. [Earliest finish time] Consider jobs in ascending order of fj. [Shortest interval] Consider jobs in ascending order of fj – sj.
! [Fewest conflicts] For each job j, count the number of conflicting jobs cj. Schedule in ascending order of cj.

Interval Scheduling: Greedy Algorithms
Greedy template. Consider jobs in some natural order.
Take each job provided it’s compatible with the ones already taken.
counterexample for earliest start time
counterexample for shortest interval
counterexample for fewest conflicts

Interval Scheduling: Greedy Algorithm
Greedy algorithm. Consider jobs in increasing order of finish time. Take each job provided it’s compatible with the ones already taken.
Sort jobs by finish times so that f1 £ f2 £ … £ fn. set of jobs selected
for j = 1 to n {
if (job j compatible with A) A ¬ A È {j}
Implementation. O(n log n).
! Remember job j* that was added last to A.
Job j is compatible with A if sj 3 fj*.

Interval Scheduling: Analysis
Theorem. Greedy algorithm is optimal.
Pf. (by contradiction)
! Assume greedy is not optimal, and let’s see what happens.
Let i1, i2, … ik denote set of jobs selected by greedy.
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.
job ir+1 finishes before jr+1
Greedy: OPT:
why not replace job jr+1 with job ir+1?

Interval Scheduling: Analysis
Theorem. Greedy algorithm is optimal.
Pf. (by contradiction)
! Assume greedy is not optimal, and let’s see what happens.
Let i1, i2, … ik denote set of jobs selected by greedy.
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.
job ir+1 finishes before jr+1
Greedy: OPT:
solution still feasible and optimal, but contradicts maximality of r.

Interval Partitioning

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.
9 9:30 10 10:30 11 11:30 12 12:30 1 1:30 2 2:30 3 3:30 4 4:30

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 only 3.
9 9:30 10 10:30 11 11:30 12 12:30 1 1:30 2 2:30 3 3:30 4 4:30

Interval Partitioning: Lower Bound on Optimal Solution
Def. The depth of a set of open intervals is the maximum number that contain any given time.
Key observation. Number of classrooms needed 3 depth.
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?
9 9:30 10 10:30 11 11:30 12 12:30 1 1:30 2 2:30 3 3:30 4 4:30

Interval Partitioning: Greedy Algorithm
Greedy algorithm. Consider lectures in increasing order of start time: assign lecture to any compatible classroom.
Sort intervals by starting time so that s1 £ s2 £ … £ sn. d ¬ 0 number of allocated classrooms
for j = 1 to n {
if (lecture j is compatible with some classroom k)
schedule lecture j in classroom k
allocate a new classroom d + 1 schedule lecture j in classroom d + 1 d¬d+1
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.

Scheduling to Minimize Lateness

Scheduling to Minimizing 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: !j =max{0, fj -dj }.
Goal: schedule all jobs to minimize maximum lateness L = max !j.
lateness = 2 lateness = 0 max lateness = 6
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Minimizing Lateness: Greedy Algorithms
Greedy template. Consider jobs in some order.
! [Shortest processing time first] Consider jobs in ascending order
of processing time tj.
! [Earliest deadline first] Consider jobs in ascending order of deadline dj.
[Smallest slack] Consider jobs in ascending order of slack dj – tj.

Minimizing Lateness: Greedy Algorithms
Greedy template. Consider jobs in some order.
! [Shortest processing time first] Consider jobs in ascending order
of processing time tj.
counterexample
[Smallest slack] Consider jobs in ascending order of slack dj – tj. counterexample

Minimizing Lateness: Greedy Algorithm
Greedy algorithm. Earliest deadline first.
Sortnjobsbydeadlinesothatd1 £ d2 £ … £ dn
for j = 1 to n
Assign job j to interval [t, t + tj] sj ¬ t, fj ¬ t + tj
t ¬ t + tj
output intervals [sj, fj]
max lateness = 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com