Algoritmiek Scheduling To Minimize Maximum Lateness
Algoritmiek Scheduling To Minimize Maximum Lateness
1 2 job number
dj 1 3 deadline
d1 = 1 d2 = 3 lateness = 2
0 1 2 3 4 5 6
Scheduling to Minimizing Maximum Lateness
1 2 job number
dj 1 3 deadline
d1 = 1 d2 = 3 lateness = 2
0 1 2 3 4 5 6
Scheduling to Minimizing Maximum Lateness
1 2 3 4 5 6 job number
dj 6 8 9 9 14 15 deadline
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
5
Minimizing Maximum Lateness: Greedy Algorithms
6
Minimizing Maximum Lateness: Greedy Algorithm
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
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
8
Minimizing Maximum Lateness: 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
9
Minimizing Maximum Lateness: 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
10
Towards proving greedy is optimal
Greedy
Optimal
11
Minimizing Maximum Lateness: Inversions
before swap j i
Q. How many inversions can a schedule from our Greedy algorithm have?
(0, 1, or more than 1)
12
Minimizing Maximum Lateness: Inversions
before swap j i
13
Minimizing Maximum Lateness: Inversions
before swap j i
S j i
S’ i j
14
Minimizing Maximum Lateness: Inversions
before swap j i
Q. If a schedule (with no idle time) has an inversion, how can we find it?
15
Minimizing Maximum Lateness: Inversions
before swap j i
16
Minimizing Maximum Lateness: Inversions
before swap j i
17
Minimizing Maximum Lateness: Inversions
before swap j i
18
Minimizing Maximum Lateness: Inversions
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
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
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
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
23
Minimizing Lateness: Analysis of Greedy Algorithm
24
Minimizing Lateness: Analysis of Greedy Algorithm
25
Minimizing Lateness: Analysis of Greedy Algorithm
26
Minimizing Lateness: Analysis of Greedy Algorithm
27
Minimizing Lateness: Analysis of Greedy Algorithm
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.
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]
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
Come to the instruction (Friday 13:45) if you do not know how to answer this.
31
Variant: Scheduling to Minimizing Total Lateness
1 2 job number
dj 1 3 deadline
0 1 2 3 4 5 6