0% found this document useful (0 votes)
76 views2 pages

Job Scheduling

The document describes an algorithm for scheduling jobs to maximize profits given job deadlines and profits. It defines the problem, provides definitions for schedules, feasibility, and optimality. It then presents a greedy algorithm that sorts jobs by profit and schedules the most profitable jobs first while respecting deadlines. A lemma states this greedy algorithm produces a promising schedule, which can be extended to an optimal schedule. This implies the greedy algorithm finds an optimal schedule.

Uploaded by

eLearner
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PS, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views2 pages

Job Scheduling

The document describes an algorithm for scheduling jobs to maximize profits given job deadlines and profits. It defines the problem, provides definitions for schedules, feasibility, and optimality. It then presents a greedy algorithm that sorts jobs by profit and schedules the most profitable jobs first while respecting deadlines. A lemma states this greedy algorithm produces a promising schedule, which can be extended to an optimal schedule. This implies the greedy algorithm finds an optimal schedule.

Uploaded by

eLearner
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PS, PDF, TXT or read online on Scribd
You are on page 1/ 2

cs2me3 Notes on Job Scheduling Winter 2005

by Michael Soltys
January 20, 2005

Job Scheduling with Deadlines and Profits


We have n jobs, each of which takes unit time, and a processor on which we would like to schedule
them in as profitable a manner as possible. Each job has a profit associated with it, as well as a
deadline; if the job is not scheduled by its deadline, then we don’t get its profit. Because each job
takes the same amount of time, we will think of a schedule S as consisting of a sequence of job
“slots” 1, 2, 3, . . . where S(t) is the job scheduled in slot t.
Formally, the input to the problem is a sequence of pairs (d1 , g1 ), (d2 , g2 ), . . . , (dn , gn ) where
gi is a non-negative real number representing the profit obtainable from job i, and di ∈ N is the
deadline for job i.

Definition 1 A schedule is an array S(1), S(2), . . . , S(d) where d = max di (i.e. the latest dead-
line, beyond which no jobs can be scheduled), such that if S(t) = i, then job i is scheduled at time
t, 1 ≤ t ≤ d. If S(t) = 0, then no job is scheduled at time t.

Definition 2 A schedule S is feasible if (a) If S(t) = i > 0, then t ≤ di (i.e., every scheduled job
meets its deadline), and (b) If t1 6= t2 and S(t1 ) 6= 0, then S(t1 ) 6= S(t2 ) (i.e. each job is scheduled
at most once).

Definition 3 Let the total profit of schedule S be P (S) = gS(1) + gS(2) + . . .+ gS(d), where g0 = 0.
We want to find a feasible schedule S whose profit P (S) is as large as possible. This can be
accomplished with the following greedy algorithm:

Sort the jobs in non-increasing order of profits: g1 ≥ g2 ≥ . . . ≥ gn


d ←− maxi di
for t : 1..d
S(t) ←− 0
end for
for i : 1..n
Find the largest t such that (S(t) = 0 and t ≤ di ), and let S(t) ←− i
[find the latest possible free slot meeting the deadline]
end for

Theorem 1 The greedy solution above is optimal (i.e. the profit P (S) of the schedule S computed
by this greedy algorithm is as large as possible).

Definition 4 A schedule is promising if it can be extended to an optimal schedule. Schedule S ′


extends schedule S iff for all 1 ≤ t ≤ d, if S(t) 6= 0, then S(t) = S ′ (t).

Lemma 1 The following is a loop invariant of the above greedy algorithm: S is promising.

1
Exercise: Why does Lemma 1 imply Theorem 1? (Hint: simple observation).

Proof: (of Lemma 1) The proof is by induction.


Basis Case: Initially S = (0, 0, . . . , 0) is promising (take any optimal schedule; it is an
extension).
Induction Step: Suppose that S is promising, and let Sopt be some optimal schedule that
extends S. Let S ′ be the result of one more iteration through the loop where job i is considered.
We must prove that S ′ continues to be promising, so the goal is to show that there is an optimal

schedule Sopt that extends S ′ . We consider two cases:
case (I) job i cannot be scheduled. Then S ′ = S, so we let Sopt

= Sopt , and we are done.
case (II) job i is scheduled at time t0 , so S ′ (t0 ) = i (whereas S(t0 ) = 0) and t0 is the latest
possible time for job i in the schedule S.
subcase (a) job i is scheduled in Sopt at time t1 :

If t1 = t0 then, as in case (I), just let Sopt = Sopt .
′ ′
If t1 < t0 then let Sopt be Sopt except that we interchange t0 and t1 , that is: Sopt (t0 ) =
′ ′ ′
Sopt (t1 ) = i and Sopt (t1 ) = Sopt (t0 ). Then Sopt is feasible (why?), it extends S (why?),

and P (Sopt ) = P (Sopt ) (why?).
The case t1 > t0 is not possible (why?).

subcase (b) job i is not scheduled in Sopt . Then we simply define Sopt to be the same as
′ ′ ′
Sopt , except Sopt (t0 ) = i. Since Sopt is feasible, so is Sopt , and since Sopt extends S ′ ,

we only have to show that P (Sopt ) = P (Sopt ). This follows from the following claim:
Claim: Let Sopt (t0 ) = j. Then gj ≤ gi .
We prove the claim by contradiction: assume that gj > gi (note that in this case j 6= 0).
Then job j was considered before job i. Since job i was scheduled at time t0 , job j
must have been scheduled at time t2 6= t0 (we know that job j was scheduled in S since
S(t0 ) = 0, and t0 ≤ dj , so there was a slot for job j, and therefore it was scheduled).
But Sopt extends S, and S(t2 ) = j 6= Sopt (t2 ) — contradiction.
This finishes the proof of the Induction Step. 

Exercise: Make sure you can answer all the “why’s” in the above proof. Also, where in the
proof of the claim you use the fact that j 6= 0?

You might also like