1 / 26

Interval Scheduling

Interval Scheduling. Input: Output: Objective:. a set of time-intervals a subset of non-overlapping intervals maximize # of selected intervals. Interval Scheduling. Input: Output: Objective:. a set of time-intervals a subset of non-overlapping intervals

fugater
Download Presentation

Interval Scheduling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Interval Scheduling Input: Output: Objective: a set of time-intervals a subset of non-overlapping intervals maximize # of selected intervals

  2. Interval Scheduling Input: Output: Objective: a set of time-intervals a subset of non-overlapping intervals maximize # of selected intervals Idea #1: Select interval that starts earliest, remove overlapping intervals and recurse.

  3. Interval Scheduling Input: Output: Objective: a set of time-intervals a subset of non-overlapping intervals maximize # of selected intervals Idea #2: Select the shortest interval, remove overlapping intervals and recurse.

  4. Interval Scheduling Input: Output: Objective: a set of time-intervals a subset of non-overlapping intervals maximize # of selected intervals Idea #3: Select the interval with the fewest conflicts, remove overlapping intervals and recurse.

  5. Interval Scheduling Input: Output: Objective: a set of time-intervals a subset of non-overlapping intervals maximize # of selected intervals Idea #4: Select the earliest finishing interval, remove overlapping intervals and recurse.

  6. Interval Scheduling • INTERVAL-SCHEDULING( s1, f1, …, sn, fn ) • Remain = {1,…,n} • Selected = {} • while ( |Remain| > 0 ) { • k = argmin i 2 Remain fi • Selected = Selected [ {k} • Remain = Remain – {k} • for every i in Remain { • if (si < fk) then Remain = Remain – {i} • } • } • RETURN Selected Idea #4: Select the earliest finishing interval, remove overlapping intervals and recurse.

  7. Interval Scheduling • INTERVAL-SCHEDULING( s1, f1, …, sn, fn ) • Remain = {1,…,n} • Selected = {} • while ( |Remain| > 0 ) { • k = argmin i 2 Remain fi • Selected = Selected [ {k} • Remain = Remain – {k} • for every i in Remain { • if (si < fk) then Remain = Remain – {i} • } • } • RETURN Selected Running time:

  8. Interval Scheduling • INTERVAL-SCHEDULING( s1, f1, …, sn, fn ) • Remain = {1,…,n} • Selected = {} • while ( |Remain| > 0 ) { • k = argmin i 2 Remain fi • Selected = Selected [ {k} • Remain = Remain – {k} • for every i in Remain { • if (si < fk) then Remain = Remain – {i} • } • } • RETURN Selected Thm: Algorithm works.

  9. Interval Scheduling • INTERVAL-SCHEDULING( s1, f1, …, sn, fn ) • Remain = {1,…,n} • Selected = {} • while ( |Remain| > 0 ) { • k = argmin i 2 Remain fi • Selected = Selected [ {k} • Remain = Remain – {k} • for every i in Remain { • if (si < fk) then Remain = Remain – {i} • } • } • RETURN Selected Which type of algorithm did we use ?

  10. Schedule All Intervals Input: Output: Objective: a set of time-intervals a partition of the intervals, each part of the partition consists of non-overlapping intervals minimize the number of parts in the partition

  11. Schedule All Intervals Input: Output: Objective: a set of time-intervals a partition of the intervals, each part of the partition consists of non-overlapping intervals minimize the number of parts in the partition Def: depth = max (over time t) number of intervals that are “active” at time t

  12. Schedule All Intervals Input: Output: Objective: a set of time-intervals a partition of the intervals, each part of the partition consists of non-overlapping intervals minimize the number of parts in the partition Def: depth = max (over time t) number of intervals that are “active” at time t

  13. Schedule All Intervals Def: depth = max (over time t) number of intervals that are “active” at time t Observation 1: Need at least depth parts (labels). • SCHEDULE-ALL_INTERVALS ( s1, f1, …, sn, fn ) • Sort intervals by their starting time • for j=1 to n do • Consider = {1,…,depth} • for every i<j that overlaps with j do • Consider = Consider – { Label[i] } • if |Consider| > 0 then • Label[j] = anything from Consider • else • Label[j] = nothing • RETURN Label[]

  14. Schedule All Intervals Thm: Every interval gets a real label. Corollary: Algo returns an optimal solution (i.e. it works!). Running time: • SCHEDULE-ALL_INTERVALS ( s1, f1, …, sn, fn ) • Sort intervals by their starting time • for j=1 to n do • Consider = {1,…,depth} • for every i<j that overlaps with j do • Consider = Consider – { Label[i] } • if |Consider| > 0 then • Label[j] = anything from Consider • else • Label[j] = nothing • RETURN Label[]

  15. Weighted Interval Scheduling Input: Output: Objective: a set of time-intervals, each interval has a cost a subset of non-overlapping intervals maximize the sum of the costs in the subset

  16. Weighted Interval Scheduling Input: Output: Objective: a set of time-intervals, each interval has a cost a subset of non-overlapping intervals maximize the sum of the costs in the subset • WEIGHTED-SCHED-ATTEMPT (s1,f1,c1, …, sn,fn,cn) • Sort intervals by their finishing time • RETURN WEIGHTED-SCHEDULING-RECURSIVE (n) • WEIGHTED-SCHEDULING-RECURSIVE (j) • if (j=0) then RETURN 0 • k=j • while (interval k and j overlap) do k-- • RETURN • max(cj + WEIGHTED-SCHEDULING-RECURSIVE(k), • WEIGHTED-SCHEDULING-RECURSIVE(j-1))

  17. Weighted Interval Scheduling Does the algorithm below work ? • WEIGHTED-SCHED-ATTEMPT (s1,f1,c1, …, sn,fn,cn) • Sort intervals by their finishing time • RETURN WEIGHTED-SCHEDULING-RECURSIVE (n) • WEIGHTED-SCHEDULING-RECURSIVE (j) • if (j=0) then RETURN 0 • k=j • while (interval k and j overlap) do k-- • RETURN • max(cj + WEIGHTED-SCHEDULING-RECURSIVE(k), • WEIGHTED-SCHEDULING-RECURSIVE(j-1))

  18. Weighted Interval Scheduling Dynamic programming ! Heart of the solution: S[ ] = • WEIGHTED-SCHED-ATTEMPT (s1,f1,c1, …, sn,fn,cn) • Sort intervals by their finishing time • RETURN WEIGHTED-SCHEDULING-RECURSIVE (n) • WEIGHTED-SCHEDULING-RECURSIVE (j) • if (j=0) then RETURN 0 • k=j • while (interval k and j overlap) do k-- • RETURN • max(cj + WEIGHTED-SCHEDULING-RECURSIVE(k), • WEIGHTED-SCHEDULING-RECURSIVE(j-1))

  19. Weighted Interval Scheduling Dynamic programming ! Heart of the solution: S[ j ] = max cost using a subset of the first j intervals Another part of the heart: how to compute S[j] ? Finally, what do we return ?

  20. Weighted Interval Scheduling Dynamic programming ! Heart of the solution: S[ j ] = max cost using a subset of the first j intervals • WEIGHTED-SCHED-ATTEMPT (s1,f1,c1, …, sn,fn,cn) • Sort intervals by their finishing time • S[0] = 0 • for j=1 to n do • k = j • while (intervals k and j overlap) do k-- • S[j] = max( S[j-1], cj + S[k] ) • RETURN S[n]

  21. Longest Increasing Subsequence Input: Output: Objective: a sequence of numbers an increasing subsequence maximize length of the subsequence Example: 2 3 1 7 4 6 9 5

  22. Longest Increasing Subsequence Input: Output: Objective: a sequence of numbers an increasing subsequence maximize length of the subsequence Heart of the solution:

  23. Longest Increasing Subsequence Input: Output: Objective: a sequence of numbers an increasing subsequence maximize length of the subsequence Heart of the solution: S[k] =

  24. Longest Increasing Subsequence Input: Output: Objective: a sequence of numbers an increasing subsequence maximize length of the subsequence Heart of the solution: S[k] = the maximum length of an increasing subsequence of the first k numbers ending with the k-th number

  25. Longest Increasing Subsequence Input: Output: Objective: a sequence of numbers a1, a2, …, an an increasing subsequence maximize length of the subsequence Heart of the solution: S[k] = the maximum length of an increasing subsequence of the first k numbers ending with the k-th number S[k] = 1 + maximum S[i] where i < k satisfies ai < ak

  26. Longest Increasing Subsequence • LONGEST-INCR-SUBSEQ (a1,…,an) • for k=1 to n do • S[k] = 1 • for j=1 to k-1 do • if aj<ak and S[k]<S[j]+1 then • S[k] = S[j]+1 • return maxk S[k]

More Related