Makespan Scheduling and Graham's List Scheduling
The oldest analysis of an approximation algorithm is Graham's study of scheduling on identical machines (1966), written before NP-completeness existed. The problem, written in scheduling notation: jobs with processing times must be assigned to identical machines; each machine processes its jobs one after another; minimize the makespan , the time at which the last machine finishes. With it already contains PARTITION, so it is NP-hard, and with part of the input it is strongly NP-hard (from 3-PARTITION).
Two lower bounds
Write for the total work and for the longest job. Every schedule satisfies
the busiest machine carries at least the average load, and the machine that runs the longest job runs at least that long. Both bounds are computable in linear time, and together they are strong enough for a factor-2 guarantee.
List scheduling
LIST-SCHEDULING(p_1..p_n, m)
1 all machine loads = 0
2 for j = 1 .. n -- in the given order
3 put job j on a machine with the smallest current load
4 return the assignmentWith a min-heap of loads it runs in time. It does not need to know future jobs, so it is also an online algorithm, the first example of competitive analysis (the subject of Online Algorithms).
Theorem (Graham, 1966). List scheduling, in any job order, has makespan at most .
Proof. Let job finish last, and let be the time it starts, the load of its machine when it was assigned. That machine had the smallest load at that time, so all machines were busy until at least , and their loads then, excluding job and the jobs assigned later, sum to at most . So and
The argument uses each lower bound for one of the two terms, and the factor comes from not counting job twice.
import heapq
import random
def list_schedule(p, m):
loads = [(0, i) for i in range(m)]
for x in p:
load, i = heapq.heappop(loads)
heapq.heappush(loads, (load + x, i))
return max(l for l, _ in loads)
def optimum(p, m):
states = {tuple([0] * m)}
for x in sorted(p, reverse=True):
states = {tuple(sorted(s[:i] + (s[i] + x,) + s[i + 1:])) for s in states for i in range(m)}
return min(max(s) for s in states)
rng = random.Random(13)
print(" m n list OPT ratio bound P/m p_max")
for m, n in [(2, 9), (3, 10), (3, 12), (4, 11), (4, 12)]:
p = [rng.randint(1, 20) for _ in range(n)]
a, o = list_schedule(p, m), optimum(p, m)
print(f"{m:2} {n:3} {a:5} {o:4} {a / o:6.3f} {2 - 1 / m:6.3f} {sum(p) / m:5.1f} {max(p):6}") m n list OPT ratio bound P/m p_max
2 9 31 30 1.033 1.500 30.0 10
3 10 35 30 1.167 1.667 30.0 20
3 12 53 48 1.104 1.667 47.3 19
4 11 41 35 1.171 1.750 35.0 20
4 12 45 36 1.250 1.750 35.5 18
In C++
#include <algorithm>
#include <cstdio>
#include <functional>
#include <queue>
#include <utility>
#include <vector>
int main() {
int m = 3;
std::vector<int> p = {7, 3, 9, 4, 4, 8, 2, 6, 5, 1};
using Item = std::pair<int, int>; // (load, machine)
std::priority_queue<Item, std::vector<Item>, std::greater<Item>> heap;
for (int i = 0; i < m; i++) heap.push({0, i});
std::vector<std::vector<int>> jobs(m);
for (int x : p) {
auto [load, i] = heap.top();
heap.pop();
jobs[i].push_back(x);
heap.push({load + x, i});
}
int makespan = 0, total = 0, pmax = 0;
for (int x : p) { total += x; pmax = std::max(pmax, x); }
while (!heap.empty()) { makespan = std::max(makespan, heap.top().first); heap.pop(); }
for (int i = 0; i < m; i++) {
std::printf("machine %d:", i);
for (int x : jobs[i]) std::printf(" %d", x);
std::printf("\n");
}
std::printf("makespan %d, lower bound max(P/m, p_max) = %.2f\n", makespan, std::max(total / (double)m, (double)pmax));
}machine 0: 7 4 6
machine 1: 3 4 8 1
machine 2: 9 2 5
makespan 17, lower bound max(P/m, p_max) = 16.33
The bound is tight
Give list scheduling unit jobs followed by one job of length . The unit jobs spread evenly, every machine reaches load , and the long job starts on top of one of them: makespan . The optimum puts the long job alone on one machine and the unit jobs per machine on the others: makespan . The ratio is .
import heapq
def list_schedule(p, m):
loads = [0] * m
for x in p:
heapq.heapreplace(loads, loads[0] + x)
return max(loads)
for m in [2, 3, 4, 5, 10]:
p = [1] * (m * (m - 1)) + [m]
a = list_schedule(p, m)
print(f"m = {m:2}: list scheduling {a:2}, OPT {m:2}, ratio {a / m:.3f} = 2 - 1/m = {2 - 1 / m:.3f}")
a_sorted = list_schedule(sorted(p, reverse=True), m)
print(f" longest job first: {a_sorted}")m = 2: list scheduling 3, OPT 2, ratio 1.500 = 2 - 1/m = 1.500
longest job first: 2
m = 3: list scheduling 5, OPT 3, ratio 1.667 = 2 - 1/m = 1.667
longest job first: 3
m = 4: list scheduling 7, OPT 4, ratio 1.750 = 2 - 1/m = 1.750
longest job first: 4
m = 5: list scheduling 9, OPT 5, ratio 1.800 = 2 - 1/m = 1.800
longest job first: 5
m = 10: list scheduling 19, OPT 10, ratio 1.900 = 2 - 1/m = 1.900
longest job first: 10
The bad order puts the longest job last. Sorting the jobs so that the longest come first fixes this instance completely, and in general improves the guarantee to : Longest Processing Time First.
Note: Two mistakes are common when proving such bounds. The first is to use only one lower bound: against alone, one long job makes any schedule look bad, and against alone, many small jobs do; the proof needs both. The second is to assume that the job finishing last is the last job assigned. It need not be, and the proof is careful to pick the job that finishes last, whichever it is, and to bound its start time by the loads at the moment it was assigned.
Variations
- Precedence constraints (): list scheduling that starts any available job whenever a machine is idle is still a -approximation (Graham, 1966); the proof follows a chain of jobs backwards through the idle periods. This is the same argument as Brent's bound for greedy schedulers of parallel computations (Greedy Scheduling and Brent's Bound). Under a variant of the Unique Games Conjecture, is hard for this problem (Svensson, 2011).
- Timing anomalies: Graham also observed that with precedence constraints, adding a machine, shortening jobs or removing constraints can increase the list schedule's makespan. Greedy schedules are not monotone.
- Unrelated machines (, job takes on machine ): LP rounding gives factor 2, and is NP-hard (Lenstra, Shmoys and Tardos, 1990).
- Identical machines, any accuracy: there is a PTAS (Hochbaum and Shmoys, 1987), based on rounding job sizes and dynamic programming, the same pattern as the bin-packing scheme in An Asymptotic PTAS for Bin Packing. Since the problem is strongly NP-hard, no FPTAS exists unless P = NP.
Test yourself
Which two lower bounds on OPT does the list scheduling proof use?
- The number of jobs and the number of machines
- The average load and the longest job
- The LP relaxation and its dual
- The makespan of LPT and of SPT
On unit jobs followed by one job of length , what makespan does list scheduling produce?
Why is list scheduling also an online algorithm?
- It sorts the jobs first
- Each job is assigned when it arrives, using only the current loads, without knowledge of future jobs
- It solves an LP
- It uses randomization