



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




We consider several variants of the scheduling problem, and see how different techniques can be used. During the course we will further explore all these techniques.
Instance: A set S of n intervals [si, ti], i = 1,... , n, where si, ti are the starting and ending times for the i-th interval. Question: A subset S′^ ⊆ S of nonoverlapping intervals – a schedule – of maximum size.
We may assume that no intervals have equal ending time, because if two of them do it is sufficient to keep the shortest one (they overlap anyway). We will show that a “greedy” ap- proach solves this problem efficiently. Consider the following algorithm outline to construct a schedule:
We give a more detailed implementation:
Greedy([s 1 , t 1 ],... , [sn, tn]) Order the intervals according to the ending times ti let Ii = [si, ti], i = 1,... , n, be the intervals in this sorted order /* so t 1 < t 2 < · · · < tn / T ← − ∞ / start at time −∞ / k← 0 / with an empty schedule / for j = 1 to n if sj ≥ T then k←k + 1 ik←j / schedule Ij */ T ←tj return (i 1 , i 2 ,... , ik)
After I 1 ,... , Ij have been considered, let i 1 , i 2 ,... , ik be the indices of the intervals that have been selected into the schedule by the algorithm. To show that Greedy produces an optimal solution, we show that the following invariant holds in the j-th step of the loop:
Invariant-j: The solution Ii 1 , Ii 2 ,... , Iik constructed by Greedy after looking at the first j intervals I 1 , I 2 ,... , Ij can be extended to an optimal solution.
For j = 0, the current schedule is empty, and certainly can be extended to an optimal solution. So consider that the variant holds for j, and we will verify it for j + 1. By inductive hypothesis, there are interval indices i′ 1 , i′ 2 ,... , i′ l such that the intervals with indices i 1 ,... , ik, i′ 1 ,... , i′ l form an optimal solution. Since Greedy considers the intervals ordered by ending time, we know that tj+1 ≤ Ti′ 1. There are two cases to be considered depending on whether Ij+1 is added or not to the schedule:
(i) Ij+1 is added to the schedule: Then sj+1 ≥ tik. If i′ 1 = j +1 then trivially the invariant holds. If i′ 1 6 = j + 1, then the intervals with indices i 1 ,... , ik, j + 1, i′ 2 ,... , i′ l also form a valid solution (since sj+1 ≥ tik and tj+1 ≤ Ti′ 1 ) and is also optimal (because it has the same length as an optimal one).
(ii) Ij+1 is is not added to the schedule: Then sj+1 < tik. Then the invariant trivially holds because the solution of Greedy after this new step is still Ii 1 , Ii 2 ,... , Iik and it can be extended to an optimal solution.
Running Time. Excluding the sorting of the intervals, the algorithm uses time that is linear in the number of intervals because it simply scans the data. Thus, the running time is O(n log n), the sorting time bound.
Other Greedy Approaches. Can other criteria for greediness be used successfully? In lecture, it was suggested to consider first short intervals. Actually, it is not difficult to see that taking the intervals in incresing order of length will fail: a single short interval can block two longer intervals that could otherwise be scheduled. But it seems that a short interval cannot block three other intervals. So, one is tempted to conjecture: This greedy approach gives a solution that has at least half as many intervals as an optimal one. Is this true?
The two arguments of the max correspond to the two possibilities: either Ii is in the solution, or it is not. The suboptimality principle guarantees the correctness of the solution. The base case is best(0) = 0.
We are probably interested in obtaining an actual optimal solution, rather than just the value. For this, we simply need to keep track of the solution in the recursive or iterative formulation:
solution(i) =
solution(k(si)) ∪ {Ii} if best(k(si)) + wi > best(i − 1) solution(i − 1)
with base case solution(0) = ∅.
Given the previous formulation, it is straightforward to write pseudocode for the solution.
Running Time. Again, other than sorting to obtain the ordering I 1 ,... , In, the algo- rithm uses time linear in the number of intervals (sorting also produces the indices k(si)).
Remark. The (weighted) interval scheduling problem is a particular case of a the following more general problem on graphs. An independent set of vertices in a (undirected) graph G = (V, E) is a set I ⊆ V such that for every edge {u, v} ∈ E, either u ∈ I or v ∈ I but not both. The MAXIMUM INDEPENDENT SET (OF VERTICES) problem asks, given a graph G = (V, E), for an independent set I ⊆ V of vertices of maximum size. This is a problem for which there is no “efficient” algorithm known. “Efficient” here is taken to be that runs in polynomial time. Technically, it is said to be NP-hard. The interval scheduling problem is a restricted case that is much simpler: we know a linear time algorithm.
I.3 Multiprocessor Scheduling
with Preemption:Network Flow
Instance: A set of n jobs each with a release time ri, a deadline time di and a processing time (duration) pi, with ri + pi ≤ di, for i = 1,... , n; and a number k ∈ N of processors. Question: Is there a way to schedule the n jobs into k machines, such that the times for each job are “respected”? That is, job i gets alloted a total time pi in the k machines, sequentially –that is, not simultaneously in any two of them– and within the time interval [ri, di].
At first, it is not clear at first how to solve this problem. It turns out that we can obtain an efficient solution through a reduction to a “well-known” and important problem: Flow in a network.
Let t 1 , t 2 ,... , tl be the list of all different times among the ri, di. They determine time intervals Ij = [tj , tj+1], j = 1,... , l − 1. We construct a directed graph G = (V, E) with vertex set V = {s, t} ∪ {v 1 , v 2 ,... , vn} ∪ {w 1 , w 2 ,... , wl− 1 },
where vertex vi corresponds to job i and vertex wj corresponds to interval Ij , and edge set
E = {(s, vi) : 1 ≤ i ≤ n} ∪ {(vi, wj ) : 1 ≤ i ≤ n, 1 ≤ j < l, Ij ⊆ [ri, di]} ∪ {(wj , t) : 1 ≤ j < l}.
Furthermore, we assign capacities to the edges as follows:
c(e) =
pi for e = (s, vi) tj+1 − tj for e = (vi, wj ) k(tj+1 − tj ) for e = (wj , t)
We do not define it formally here, but we are interested in a “flow” from s to t such that it flows along the edges upper bounded by the capacities and it is “conserved” at the vertices (amount of flow into the vertex is equal to amount of flow out of the vertex). We claim that the scheduling problem has a solution if and only if (iff for short) the maximum s-t flow has value
∑n i=1 pi. Given this, the scheduling problem can be solved by a maximum flow algorithm. Efficient algorithms for the later problem are known.
Example. The figure below on the left illustrates an instance with 4 jobs and times that determine 7 intervals. Specifically: r 1 = 0, d 1 = 11, r 2 = 3, d 2 = 9, r 3 = 6, d 3 = 16, r 4 = 1 , d 4 = 14. The figure on the right illustrates the corresponding network with capacities (the flows are not shown because it is too cluttered).
p 3 = 8
0 1 2 3 4 5 6 7 8 9 10 1112 13 14 15 16
job 2
job 1
job 3 job 4
1 2 3 4 5 6 7 1 2 3 3 2 3 2
interval # length
p 1 = 6 p 2 = 5
p 4 = 7
3
2
5
6
1
2
3
4
1
3
4
7
s t
6 5
8
7
2 4 6 6 4 6 4 2 3
3
2
1 3 3 3 2 3 2
2 3 3 2
Figure I.1: On the left: Jobs with release and deadline times (intervals between them are shown with dashed blue lines; the thicker purple lines correspond to a valid schedule). On the right: The corresponding flow network.
I.4 Multiprocessor Scheduling
without Preemption: NP-Hard
Consider now the multiprocessor scheduling problem without preemption. Now the problem becomes much harder. In fact, a particular case in which k = 2 and the release and deadline
Let T be the duration of the schedule produced by Approx and let job L be one whose execution is finished last according to the schedule produced by algorithm Approx^1 (it may not be unique, so any such job), and suppose it is executed in processor j. Consider the situation just before the algorithm schedules job L; let T ′^ be the amount of time spent by processor j before job L is executed. We have (since job L is finished last)
T = T ′^ + pL.
Let I′^ be the set of indices of jobs scheduled by Approx before job L. Since processor j is the one with least work when job L is executed, then
k
i∈I′
pi.
Putting everything together
k
∑^ n
i=
pi ≥
k
i∈I′
pi ≥ T ′^ = T − pL ≥ T −
n max i= pi ≥ T − OPT,
and so T ≤ 2 · OPT. We haven’t made use of the special ordering of the jobs, so it is actually not needed.
(^1) Not the last scheduled by the algorithm, as I said in lecture.