Sub topic 6
Scheduling on Identical Machines: List Scheduling and LPT
This chapter assumes you can follow a proof that compares an algorithm's cost with a lower bound on the optimum, as in the previous chapters. It also assumes you know what a binary heap does and can read Python that uses heapq.
The Makespan Problem
You have n jobs with processing times p1, ..., pn and m identical machines. Every job runs on exactly one machine without interruption. A machine's load is the sum of the processing times of the jobs assigned to it. The makespan is the largest load, which is the time at which the last machine finishes. The goal is to minimize the makespan.
The problem is NP-hard even for m = 2, because deciding whether makespan (sum of p_j)/2 is achievable is exactly the Partition problem. When m is part of the input, the problem is strongly NP-hard by a reduction from 3-Partition. So we should not expect a polynomial-time exact algorithm. Two simple greedy algorithms come with provable guarantees instead.
Two Lower Bounds on OPT
Let P = p1 + ... + pn, and let OPT be the optimal makespan. Every analysis in this chapter rests on two facts.
- Average load: OPT ≥ P/m. The m machines together do P units of work, so at least one of them does at least P/m.
- Largest job: OPT ≥ maxj pj. Some machine must run the longest job.
Neither bound is tight on its own. The proofs combine them.
List Scheduling
Graham's list scheduling (1966) processes jobs in whatever order they arrive. Each job goes to the machine that currently has the smallest load. A min-heap of (load, machine) pairs makes each assignment take O(log m) time.
import heapq
def list_schedule(jobs, m):
loads = [(0, i) for i in range(m)]
heapq.heapify(loads)
assignment = [[] for _ in range(m)]
for p in jobs:
load, i = heapq.heappop(loads)
assignment[i].append(p)
heapq.heappush(loads, (load + p, i))
makespan = max(load for load, _ in loads)
return makespan, assignment
print(list_schedule([1, 1, 1, 1, 1, 1, 3], 3))This prints (5, [[1, 1, 3], [1, 1], [1, 1]]). The optimum is 3: put the long job on one machine and three unit jobs on each of the other two. We will see that this ratio of 5/3 is as bad as list scheduling gets for m = 3.
Proof of the (2 − 1/m) Guarantee
Let machine i have the maximum load in the final schedule, and let j be the last job assigned to it. Job j starts at time sj, which was machine i's load when j was placed. Because the algorithm chose the least-loaded machine, every machine had load at least sj at that moment. Those loads add up to at most the total work excluding job j:
m · sj ≤ P − pj, so sj ≤ (P − pj)/m.
The makespan is therefore
C = sj + pj ≤ P/m + (1 − 1/m) p_j ≤ OPT + (1 − 1/m) OPT = (2 − 1/m) OPT.
The first term uses the average-load bound and the second uses the largest-job bound.
The Bound Is Tight
Take m(m − 1) unit jobs followed by one job of length m. List scheduling spreads the unit jobs evenly, so every machine reaches load m − 1, and then the long job lands on top of one of them: makespan 2m − 1. The optimum puts the long job alone and m unit jobs on each of the other m − 1 machines, for makespan m. The ratio (2m − 1)/m equals 2 − 1/m exactly. The earlier code example is this instance with m = 3.
Longest Processing Time First (LPT)
The bad case above comes from a long job arriving last, when nothing remains to balance it out. LPT fixes this by sorting jobs in decreasing order of processing time and then running list scheduling. The extra cost is the O(n log n) sort.
import heapq
def lpt_schedule(jobs, m):
loads = [(0, i) for i in range(m)]
heapq.heapify(loads)
assignment = [[] for _ in range(m)]
for p in sorted(jobs, reverse=True):
load, i = heapq.heappop(loads)
assignment[i].append(p)
heapq.heappush(loads, (load + p, i))
makespan = max(load for load, _ in loads)
return makespan, assignment
print(lpt_schedule([7, 5, 4, 3, 3, 2], 3))This prints (9, [[7, 2], [5, 3], [4, 3]]). The average-load bound gives OPT ≥ 24/3 = 8, but makespan 8 is impossible: the machine holding the 7 would need a job of length 1, and no such job exists. So OPT = 9 and LPT is optimal here. This also shows that a lower bound used in a proof can be strictly smaller than OPT.
On the earlier bad instance, lpt_schedule([1, 1, 1, 1, 1, 1, 3], 3) returns makespan 3, which is optimal.
A Simple 3/2 Bound
Number the jobs so that p1 ≥ p2 ≥ ... ≥ p_n. Let j be the last job on the machine that determines the makespan.
- If j ≤ m, job j was placed on an empty machine, so C = p_j ≤ OPT.
- If j > m, look at the m + 1 largest jobs. By the pigeonhole principle, two of them share a machine in any schedule, including the optimal one, so OPT ≥ pm + p{m+1} ≥ 2 p{m+1}. Since j > m and jobs are sorted, pj ≤ p_{m+1} ≤ OPT/2.
Plug p_j ≤ OPT/2 into the list scheduling inequality: C ≤ OPT + (1 − 1/m)(OPT/2) < (3/2) OPT.
The Sharper 4/3 − 1/(3m) Bound
Graham proved LPT achieves (4/3 − 1/(3m)) OPT. Here is the proof structure.
- Reduce to the case where j is the last job. Delete every job after j. The makespan of LPT is unchanged, since j still finishes last, and OPT can only decrease. If the bound holds for the smaller instance, it holds for the original one.
- Case p_j ≤ OPT/3. The list scheduling inequality gives C ≤ OPT + (1 − 1/m)(OPT/3) = (4/3 − 1/(3m)) OPT.
- Case p_j > OPT/3. Now j is the smallest job, so every job exceeds OPT/3. Each machine in the optimal schedule then holds at most two jobs, so n ≤ 2m. For such instances one can show LPT is optimal. The intuition is that LPT pairs the largest jobs with the smallest ones, and an exchange argument shows that this pairing is what an optimal schedule does.
The bound is tight. For m = 2, take jobs 3, 3, 2, 2, 2. LPT places the 3s on separate machines, then the 2s alternate, giving loads 7 and 5. The optimum is {3, 3} and {2, 2, 2}, with makespan 6. The ratio 7/6 equals 4/3 − 1/6. The general family uses two jobs of each length 2m − 1, 2m − 2, ..., m + 1, plus three jobs of length m. On it LPT gives 4m − 1 and OPT is 3m.
Comparison
| Algorithm | Time | Ratio | Online? | Tight example |
|---|---|---|---|---|
| List scheduling | O(n log m) | 2 − 1/m | Yes | m(m−1) unit jobs, then one job of length m |
| LPT | O(n log n) | 4/3 − 1/(3m) | No (needs sorting) | 3, 3, 2, 2, 2 on 2 machines |
| PTAS (Hochbaum–Shmoys) | polynomial for fixed ε | 1 + ε | No | none, arbitrarily close to 1 |
A later chapter covers approximation schemes. Because makespan minimization is strongly NP-hard when m is part of the input, it has a PTAS but no FPTAS unless P = NP.
Common Errors
- Using only one lower bound. Neither P/m nor max pj is enough by itself. Bounding sj needs the average, and bounding p_j needs the maximum.
- Bounding sj by P/m instead of (P − pj)/m. The looser version only gives a ratio of 2. Subtracting p_j is what produces the 1/m improvement.
- Assuming LPT is optimal. It is optimal when every job exceeds OPT/3, but not in general, as the 3, 3, 2, 2, 2 example shows.
- Forgetting the sort direction. Sorting in increasing order (shortest first) leaves the longest job for last. On the tight instance this recreates list scheduling's worst case.
- Picking the wrong job for the proof. The argument uses the last job on the machine with the maximum load. It does not use the last job in the input order, which may sit on a lightly loaded machine.
Exercise
Run list scheduling on jobs [2, 2, 2, 2, 4] with m = 2, in the given order. What makespan does it produce, what is OPT, and how does the ratio compare with 2 − 1/m?
Show answer
The four 2s give each machine load 4, then the 4 lands on one machine for makespan 8. OPT is 6, using {2, 4} and {2, 2, 2}. The ratio 8/6 = 4/3 is below 2 − 1/2 = 3/2, so the bound holds but is not reached by this instance.
Exercise
In the 3/2 analysis of LPT, why does OPT ≥ pm + p{m+1} hold, and why does the proof need j > m before using it?
Show answer
The m + 1 largest jobs must fit on m machines, so two of them share a machine. That machine's load is at least the sum of the two smallest of these jobs, pm + p{m+1}. The fact pj ≤ p{m+1} needs j > m, because jobs are sorted in decreasing order. If j ≤ m, job j started on an empty machine and C = p_j ≤ OPT directly.
Exercise
Explain why deleting all jobs after the last-finishing job j keeps LPT's makespan the same and cannot increase OPT.
Show answer
LPT places jobs in sorted order, so jobs after j do not affect where the jobs up to j go. Job j still finishes at the same time, and that time was the makespan. Removing jobs from any schedule, including an optimal one, cannot increase its makespan, so the new OPT is at most the old OPT. A ratio bound for the reduced instance therefore carries over to the original.