TExcelTAD
Home › Approximation Algorithms › Makespan Scheduling and Graham's List Scheduling

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 P∥Cmax⁡P \Vert C_{\max} in scheduling notation: nn jobs with processing times p1,…,pn>0p_1, \ldots, p_n > 0 must be assigned to mm identical machines; each machine processes its jobs one after another; minimize the makespan Cmax⁡C_{\max}, the time at which the last machine finishes. With m=2m = 2 it already contains PARTITION, so it is NP-hard, and with mm part of the input it is strongly NP-hard (from 3-PARTITION).

Two lower bounds

Write P=∑jpjP = \sum_j p_j for the total work and pmax⁡p_{\max} for the longest job. Every schedule satisfies

OPT≥PmandOPT≥pmax⁡:\text{OPT} \ge \frac{P}{m} \qquad \text{and} \qquad \text{OPT} \ge p_{\max} :

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

text
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 assignment

With a min-heap of loads it runs in O(nlog⁡m)O(n \log m) 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 (2−1m)OPT\left(2 - \frac{1}{m}\right)\text{OPT}.

Proof. Let job ℓ\ell finish last, and let ss 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 ss, and their loads then, excluding job ℓ\ell and the jobs assigned later, sum to at most P−pℓP - p_\ell. So s≤1m(P−pℓ)s \le \frac{1}{m}(P - p_\ell) and

Cmax⁡=s+pℓ≤Pm+(1−1m)pℓ≤OPT+(1−1m)OPT.□C_{\max} = s + p_\ell \le \frac{P}{m} + \left(1 - \frac{1}{m}\right)p_\ell \le \text{OPT} + \left(1 - \frac{1}{m}\right)\text{OPT} . \qquad \square

The argument uses each lower bound for one of the two terms, and the factor 1−1m1 - \frac{1}{m} comes from not counting job ℓ\ell twice.

python · try it yourself
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++

cpp · try it yourself
#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 m(m−1)m(m - 1) unit jobs followed by one job of length mm. The unit jobs spread evenly, every machine reaches load m−1m - 1, and the long job starts on top of one of them: makespan 2m−12m - 1. The optimum puts the long job alone on one machine and the unit jobs mm per machine on the others: makespan mm. The ratio is 2m−1m=2−1m\frac{2m - 1}{m} = 2 - \frac{1}{m}.

python · try it yourself
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 43−13m\frac{4}{3} - \frac{1}{3m}: Longest Processing Time First.

Note: Two mistakes are common when proving such bounds. The first is to use only one lower bound: against Pm\frac{P}{m} alone, one long job makes any schedule look bad, and against pmax⁡p_{\max} 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 (P∣prec∣Cmax⁡P \mid \text{prec} \mid C_{\max}): list scheduling that starts any available job whenever a machine is idle is still a (2−1m)(2 - \frac{1}{m})-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, 2−ε2 - \varepsilon 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 (R∥Cmax⁡R \Vert C_{\max}, job jj takes pijp_{ij} on machine ii): LP rounding gives factor 2, and 32−ε\frac{3}{2} - \varepsilon 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?

  1. The number of jobs and the number of machines
  2. The average load Pm\frac{P}{m} and the longest job pmax⁡p_{\max}
  3. The LP relaxation and its dual
  4. The makespan of LPT and of SPT

On m(m−1)m(m-1) unit jobs followed by one job of length mm, what makespan does list scheduling produce?

  1. mm
  2. 2m−12m - 1
  3. m+1m + 1
  4. 2m2m

Why is list scheduling also an online algorithm?

  1. It sorts the jobs first
  2. Each job is assigned when it arrives, using only the current loads, without knowledge of future jobs
  3. It solves an LP
  4. It uses randomization