Algorithm Search⌘K

Proofs: Smith's rule

These are the human proofs of Smith's rule, at full length.

Smith's rule minimizes the weighted sum of completion times full

This proof shows: correctness, termination.

We use the pseudocode of the page. The input is a set JJ of n≥0n \ge 0 jobs; job jj has a processing time pj>0p_j > 0 and a real weight wjw_j. For an order π=(π1,…,πn)\pi = (\pi_1, \ldots, \pi_n) of JJ, the completion time of πi\pi_i is Cπi(π)=∑l≤ipπlC_{\pi_i}(\pi) = \sum_{l \le i} p_{\pi_l}, and the cost is K(π)=∑i=1nwπiCπi(π)K(\pi) = \sum_{i=1}^{n} w_{\pi_i} C_{\pi_i}(\pi). Write ρj=wj/pj\rho_j = w_j / p_j. For jobs a,ba, b, since papb>0p_a p_b > 0, the test wapb≥wbpaw_a p_b \ge w_b p_a of line L1 holds if and only if ρa≥ρb\rho_a \ge \rho_b. Call an order sorted when ρπ1≥ρπ2≥⋯≥ρπn\rho_{\pi_1} \ge \rho_{\pi_2} \ge \cdots \ge \rho_{\pi_n}.

Claim. The algorithm stops, it returns a sorted order σ\sigma together with K(σ)K(\sigma), and K(σ)=min⁡πK(π)K(\sigma) = \min_\pi K(\pi). Moreover, an order is optimal if and only if it is sorted.

Step 1: termination and the output. Line L1 is a sort with the key ρ\rho, so it stops and gives a sorted order σ\sigma. The loop of line L3 runs nn times. By induction on ii, after line L4 of iteration ii the value of tt is ∑l≤ipσl=Cσi(σ)\sum_{l \le i} p_{\sigma_l} = C_{\sigma_i}(\sigma), and after line L5 the value of totaltotal is ∑l≤iwσlCσl(σ)\sum_{l \le i} w_{\sigma_l} C_{\sigma_l}(\sigma). For i=ni = n this is K(σ)K(\sigma).

Step 2: the adjacent swap. Let π\pi be an order, let 1≤i<n1 \le i < n, and let π′\pi' be π\pi with the jobs a=πia = \pi_i and b=πi+1b = \pi_{i+1} exchanged. Let s=∑l<ipπls = \sum_{l < i} p_{\pi_l}. Each job other than aa and bb has the same set of predecessors in both orders, so the same completion time. In π\pi, Ca=s+paC_a = s + p_a and Cb=s+pa+pbC_b = s + p_a + p_b. In π′\pi', Cb=s+pbC_b = s + p_b and Ca=s+pa+pbC_a = s + p_a + p_b. So

K(π′)−K(π)=wb(s+pb)+wa(s+pa+pb)−wa(s+pa)−wb(s+pa+pb)=wapb−wbpa.K(\pi') - K(\pi) = w_b(s + p_b) + w_a(s + p_a + p_b) - w_a(s + p_a) - w_b(s + p_a + p_b) = w_a p_b - w_b p_a.

Dividing by papb>0p_a p_b > 0, K(π′)−K(π)K(\pi') - K(\pi) has the sign of ρa−ρb\rho_a - \rho_b.

Step 3: every optimal order is sorted. A set of n!n! orders is finite and not empty, so an optimal order π∗\pi^* exists. Suppose π∗\pi^* is not sorted. Then some ii has ρπi∗<ρπi+1∗\rho_{\pi^*_i} < \rho_{\pi^*_{i+1}}, and by Step 2 the swap of positions ii and i+1i+1 gives an order of strictly smaller cost. This contradicts the optimality of π∗\pi^*. So each optimal order is sorted.

Step 4: all sorted orders have the same cost. Let π\pi and τ\tau be sorted orders. Group the jobs into blocks of equal ratio. In a sorted order, the jobs of each block are consecutive, and the blocks appear in decreasing order of ratio, so π\pi and τ\tau have the same blocks in the same positions and differ only in the order inside the blocks. Inside one block, sort the jobs of π\pi into their order in τ\tau by adjacent swaps, as bubble sort does; each swap exchanges two adjacent jobs of equal ratio, so by Step 2 it does not change the cost, and it keeps the order sorted. After finitely many swaps, π\pi becomes τ\tau. So K(π)=K(τ)K(\pi) = K(\tau).

Step 5: conclusion. By Step 3, the optimal order π∗\pi^* is sorted. By Step 4, K(σ)=K(π∗)K(\sigma) = K(\pi^*), so σ\sigma is optimal. For the second part of the claim: an optimal order is sorted by Step 3, and a sorted order has the cost K(π∗)K(\pi^*) by Step 4, so it is optimal. ■\blacksquare

Cost. Line L1 does O(nlog⁡n)O(n \log n) comparisons with a comparison sort such as merge sort, and each comparison is two multiplications. The loop does nn iterations of O(1)O(1) arithmetic operations. So the time is O(nlog⁡n)O(n \log n) arithmetic operations.

Back to Smith's rule