0% found this document useful (0 votes)
74 views32 pages

Algoritmiek Scheduling To Minimize Maximum Lateness

The document discusses minimizing maximum lateness by scheduling jobs. It introduces the problem, defines lateness and the goal of minimizing maximum lateness. It presents a greedy algorithm that schedules jobs in order of earliest deadline first and proves this algorithm is optimal by using the concept of inversions in a schedule.

Uploaded by

Oluwa Muyiwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views32 pages

Algoritmiek Scheduling To Minimize Maximum Lateness

The document discusses minimizing maximum lateness by scheduling jobs. It introduces the problem, defines lateness and the goal of minimizing maximum lateness. It presents a greedy algorithm that schedules jobs in order of earliest deadline first and proves this algorithm is optimal by using the concept of inversions in a schedule.

Uploaded by

Oluwa Muyiwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

4.

2 Scheduling to Minimize Maximum Lateness


Scheduling to Minimizing Maximum 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.

1 2 job number

Ex: tj 3 2 time required

dj 1 3 deadline

lateness = 4 Q. Which schedule is better?


d2 = 3 d1 = 1
0 1 2 3 4 5 6

d1 = 1 d2 = 3 lateness = 2

0 1 2 3 4 5 6
Scheduling to Minimizing Maximum 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.

1 2 job number

Ex: tj 3 2 time required

dj 1 3 deadline

lateness = 4 Q. Which schedule is better?


d2 = 3 d1 = 1
A. The lower; lateness 2.
0 1 2 3 4 5 6

d1 = 1 d2 = 3 lateness = 2

0 1 2 3 4 5 6
Scheduling to Minimizing Maximum 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.

1 2 3 4 5 6 job number

Ex: tj 3 2 1 4 3 2 time required

dj 6 8 9 9 14 15 deadline

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

4
Minimizing Maximum Lateness: Greedy Algorithms

Greedy template. Consider jobs in some order.

 [Shortest processing time first] Consider jobs in ascending order of


processing time tj (least work first).

 [Earliest deadline first] Consider jobs in ascending order of deadline dj


(nearest deadline).

 [Smallest slack] Consider jobs in ascending order of slack dj – tj (least


time to start to make deadline).

Q. Which one do you think may work? (1 min)

5
Minimizing Maximum Lateness: Greedy Algorithms

Greedy template. Consider jobs in some order.

 [Shortest processing time first] Consider jobs in ascending order of


processing time tj (least work first).
1 2
tj 1 10 counterexample
dj 100 10

 [Smallest slack] Consider jobs in ascending order of slack dj - tj


(least time to start to make deadline).
1 2
tj 1 10
counterexample
dj 2 10

6
Minimizing Maximum Lateness: Greedy Algorithm

Greedy algorithm. Earliest deadline first.

Sort n jobs by deadline so that d1  d2  …  dn

t  0
for j = 1 to n
Assign job j to interval [t, t + tj]:
sj  t
fj  t + t j
t  t + tj
output intervals [sj, fj]

7
Minimizing Maximum Lateness: Greedy Algorithm

Greedy algorithm. Earliest deadline first.

1 2 3 4 5 6 job number

tj 3 2 1 4 3 2 time required

dj 6 8 9 9 14 15 deadline

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

Observation. The greedy schedule has no idle time.

8
Minimizing Maximum Lateness: No Idle Time

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

d=4 d=6 d = 12
0 1 2 3 4 5 6 7 8 9 10 11

Q*. How to prove that earliest-deadline-first greedy algorithm is optimal?

9
Minimizing Maximum Lateness: No Idle Time

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

d=4 d=6 d = 12
0 1 2 3 4 5 6 7 8 9 10 11

Q*. How to prove that earliest-deadline-first greedy algorithm is optimal?

A. Idea of proof: exchange argument:


 Take an optimal schedule.
 Change into greedy schedule without losing optimality…. but how?

10
Towards proving greedy is optimal

Idea. Change optimal schedule to greedy without losing optimality.

Greedy

Optimal

Problems to solve first:


• What do we know about the greedy schedule?
• How can we change the optimal to be more like that without losing
optimality?

11
Minimizing Maximum Lateness: Inversions

Def. An inversion in schedule S is a pair of jobs i and j such that:


di < dj but j scheduled before i.
inversion

before swap j i

We’ll now study a number of properties of such an inversion.

Q. How many inversions can a schedule from our Greedy algorithm have?
(0, 1, or more than 1)

12
Minimizing Maximum Lateness: Inversions

Def. An inversion in schedule S is a pair of jobs i and j such that:


di < dj but j scheduled before i.
inversion

before swap j i

Observation. Greedy schedule has no inversions.

Q. What is the difference in maximum lateness between two schedules


without inversions and without idle time? (1 min)

13
Minimizing Maximum Lateness: Inversions

Def. An inversion in schedule S is a pair of jobs i and j such that:


di < dj but j scheduled before i.
inversion

before swap j i

Observation. Greedy schedule has no inversions.

Q. What is the difference in maximum lateness between two schedules


without inversions and without idle time?
Pf.
Only difference is an “inversion” of i and j with equal deadline (di=dj).
Maximum lateness of i and j is only influenced by last job (fi - di).
Maximum lateness of i and j is the same if i and j are swapped.

S j i

S’ i j
14
Minimizing Maximum Lateness: Inversions

Def. An inversion in schedule S is a pair of jobs i and j such that:


di < dj but j scheduled before i.
inversion

before swap j i

Observation. Greedy schedule has no inversions.


Observation. All schedules without inversions have same lateness.

Q. If a schedule (with no idle time) has an inversion, how can we find it?

15
Minimizing Maximum Lateness: Inversions

Def. An inversion in schedule S is a pair of jobs i and j such that:


di < dj but j scheduled before i.
inversion

before swap j i

Observation. Greedy schedule has no inversions.


Observation. All schedules without inversions have same lateness.

Observation. If a schedule (with no idle time) has an inversion, then it has


one with a pair of inverted jobs scheduled consecutively.
Pf.
Q. How do we proof “If …, then …” ?

16
Minimizing Maximum Lateness: Inversions

Def. An inversion in schedule S is a pair of jobs i and j such that:


di < dj but j scheduled before i.
inversion

before swap j i

Observation. Greedy schedule has no inversions.


Observation. All schedules without inversions have same lateness.

Observation. If a schedule (with no idle time) has an inversion, then it has


one with a pair of inverted jobs scheduled consecutively.
Pf.
Suppose there is an inversion.
…

 … going through schedule, at some point deadline decreases.

17
Minimizing Maximum Lateness: Inversions

Def. An inversion in schedule S is a pair of jobs i and j such that:


di < dj but j scheduled before i.
inversion

before swap j i

Observation. Greedy schedule has no inversions.


Observation. All schedules without inversions have same lateness.

Observation. If a schedule (with no idle time) has an inversion, then it has


one with a pair of inverted jobs scheduled consecutively.
Pf.
Suppose there is an inversion.
There is a pair of jobs i and j such that: di < dj but j scheduled before i.
Walk through the schedule from j to i.
Increasing deadlines (= no inversions), at some point deadline decreases.

18
Minimizing Maximum Lateness: Inversions

Def. An inversion in schedule S is a pair of jobs i and j such that:


di < dj but j scheduled before i. inversion
fi

before swap j i

after swap i j
f'j
Q. What happens to the number of inversions when we swap two
adjacent, inverted jobs? (reduces, stays equal, increases)
Q. Can we swap two adjacent, inverted jobs without increasing the
maximum lateness?

19
Minimizing Maximum Lateness: Inversions

Def. An inversion in schedule S is a pair of jobs i and j such that:


di < dj but j scheduled before i. inversion
fi

before swap j i

after swap i j
f'j
Claim. Swapping two adjacent, inverted jobs reduces the number of
inversions by one and does not increase the maximum lateness.

Pf.

20
Minimizing Maximum Lateness: Inversions

Def. An inversion in schedule S is a pair of jobs i and j such that:


di < dj but j scheduled before i. inversion
fi

before swap j i

after swap i j
f'j
Claim. Swapping two adjacent, inverted jobs reduces the number of
inversions by one and does not increase the maximum lateness.

Pf. Let  be the max lateness before the swap, and let  ' be it afterwards.
 Q. What happens with the lateness of other jobs?
 Q. What happens with the lateness of i?
 Q. What happens with the lateness of j?

21
Minimizing Maximum Lateness: Inversions

Def. An inversion in schedule S is a pair of jobs i and j such that:


di < dj but j scheduled before i. inversion
fi

before swap j i

after swap i j
f'j
Claim. Swapping two adjacent, inverted jobs reduces the number of
inversions by one and does not increase the maximum lateness.

Pf. Let  be the max lateness before the swap, and let  ' be it afterwards.
  'k = k for all k  i, j
(lateness other jobs the same)
l j  f j  d j (definition)
  'i  i
 fi  d j ( j finishes at time fi)
(new lateness for i smaller)
 fi  di (di  d j )
 If job j is late:
 l i
(definition)

22
Minimizing Lateness: Analysis of Greedy Algorithm

Theorem. Greedy schedule S is optimal.


Pf. (by contradiction)
Idea of proof:
 Suppose S is not optimal.
 Take a specific optimal schedule S*.
 Change to look like greedy schedule (less inversions) without losing
optimality.

23
Minimizing Lateness: Analysis of Greedy Algorithm

Theorem. Greedy schedule S is optimal.


Pf. (by contradiction)
Suppose S is not optimal.
Define S* to be an optimal schedule that has the fewest number of
inversions (of all optimal schedules) and has no idle time.
Clearly S≠S*.

24
Minimizing Lateness: Analysis of Greedy Algorithm

Theorem. Greedy schedule S is optimal.


Pf. (by contradiction)
Suppose S is not optimal.
Define S* to be an optimal schedule that has the fewest number of
inversions (of all optimal schedules) and has no idle time.
Clearly S≠S*. Case analysis:
 If S* has no inversions
 If S* has an inversion

25
Minimizing Lateness: Analysis of Greedy Algorithm

Theorem. Greedy schedule S is optimal.


Pf. (by contradiction)
Suppose S is not optimal.
Define S* to be an optimal schedule that has the fewest number of
inversions (of all optimal schedules) and has no idle time.
Clearly S≠S*. Case analysis:
 If S* has no inversions. Q. How can we derive a contradiction?
 If S* has an inversion

26
Minimizing Lateness: Analysis of Greedy Algorithm

Greedy has no inversions.


Theorem. Greedy schedule S is optimal. All schedules without
inversions have same
Pf. (by contradiction) lateness.
Suppose S is not optimal.
Define S* to be an optimal schedule that has the fewest number of
inversions (of all optimal schedules) and has no idle time.
Clearly S≠S*.
 If S* has no inversions, then LS = LS*. Contradiction.
 If S* has an inversion, Q. How can we derive a contradiction?

27
Minimizing Lateness: Analysis of Greedy Algorithm

Greedy has no inversions.


Theorem. Greedy schedule S is optimal. All schedules without
inversions have same
Pf. (by contradiction) lateness.
Suppose S is not optimal.
Define S* to be an optimal schedule that has the fewest number of
inversions (of all optimal schedules) and has no idle time.
Clearly S≠S*.
 If S* has no inversions, then maxl(S) = maxl(S*). Contradiction.
 If S* has an inversion, let i-j be an adjacent inversion.
– swapping i and j does not increase the maximum lateness and strictly
decreases the number of inversions
– this contradicts definition of S*
So S is an optimal schedule. ▪

This proof can be found


on pages 128-131. 28
Greedy Analysis Strategies

Greedy algorithm stays ahead. Show that after each step of the greedy
algorithm, its solution is at least as good as any other algorithm's.

Exchange argument. Gradually transform an optimal solution to the one


found by the greedy algorithm without hurting its quality.

Structural. Discover a simple "structural" bound asserting that every


possible solution must have a certain value. Then show that your algorithm
always achieves this bound.

Q. Which strategy did we use for the problems in this chapter (interval
scheduling, interval partitioning, minimizing lateness) ?

29
Greedy Analysis Strategies

Greedy algorithm stays ahead. Show that after each step of the greedy
algorithm, its solution is at least as good as any other algorithm's.
[Interval scheduling]

Exchange argument. Gradually transform an optimal solution to the one


found by the greedy algorithm without hurting its quality. [Minimizing
lateness, Interval scheduling]

Structural. Discover a simple "structural" bound asserting that every


possible solution must have a certain value. Then show that your algorithm
always achieves this bound. [Interval partitioning]

30
Example exam exercise

Planning a mini-triathlon:
1. swim 20 laps (one at a time)
2. bike 10 km (can be done simultaneously)
3. run 3 km (can be done simultaneously)
expected times are given for each contestant

Def. The completion time is the earliest time all contestants are finished.
Q. In what order should they start to minimize the completion time?
Q. Proof that this order is optimal (minimal).

Ex.
1 2 3 contestant

sj 3 2 4 time required for swimming

bj 5 4 6 time required for biking

rj 3 3 3 time required for running

Come to the instruction (Friday 13:45) if you do not know how to answer this.
31
Variant: Scheduling to Minimizing Total Lateness

Minimizing total 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 total lateness L = Σjj.

1 2 job number

Ex: tj 3 2 time required

dj 1 3 deadline

No polynomial algorithm can


total lateness = 0+4
d2 = 3 d1 = 1 compute optimal schedule
0 1 2 3 4 5 6 (unless P=NP)
(see Master’s course Advanced Algorithms)

d1 = 1 d2 = 3 total lateness = 2+2

0 1 2 3 4 5 6

You might also like