Documentation

CslibFrontier.Algorithms.Lean.Scheduling.IdenticalMachines

List Scheduling on Identical Machines #

This module models non-preemptive scheduling of n jobs with processing times p : Fin n → α on m identical machines (P || C_max in the three-field notation). An assignment σ : Fin n → Fin m has machine loads load p σ and makespan makespan p σ; optMakespan m p is the minimum over all m ^ n assignments. With the jobs processed in list order, job j starts on machine σ j at time prefixLoad p σ j (σ j), the load of that machine over the earlier jobs. IsListSchedule p σ states that every job goes to a machine of minimum load over the earlier jobs ([Gra66]), and listSchedule is the computable rule with lowest-index tie-breaking.

Main definitions #

Main results #

References #

def Cslib.Algorithms.Lean.Scheduling.load {α : Type u_1} {n m : ℕ} [AddCommMonoid α] (p : Fin n → α) (σ : Fin n → Fin m) (i : Fin m) :
α

The load of machine i under the assignment σ: the total processing time of the jobs assigned to i.

def Cslib.Algorithms.Lean.Scheduling.prefixLoad {α : Type u_1} {n m : ℕ} [AddCommMonoid α] (p : Fin n → α) (σ : Fin n → Fin m) (k : ℕ) (i : Fin m) :
α

The load of machine i counting only the jobs j with j < k. With jobs processed in list order, prefixLoad p σ j i is the time at which machine i becomes free before job j.

def Cslib.Algorithms.Lean.Scheduling.IsListSchedule {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LE α] (p : Fin n → α) (σ : Fin n → Fin m) :

List scheduling ([Gra66], §I.1; [WS11], §2.3): each job, taken in list order, is assigned to a machine of minimum load over the earlier jobs.

theorem Cslib.Algorithms.Lean.Scheduling.load_def {α : Type u_1} {n m : ℕ} [AddCommMonoid α] (p : Fin n → α) (σ : Fin n → Fin m) (i : Fin m) :
load p σ i = ∑ j : Fin n with σ j = i, p j
theorem Cslib.Algorithms.Lean.Scheduling.prefixLoad_def {α : Type u_1} {n m : ℕ} [AddCommMonoid α] (p : Fin n → α) (σ : Fin n → Fin m) (k : ℕ) (i : Fin m) :
prefixLoad p σ k i = ∑ j : Fin n with ↑j < k ∧ σ j = i, p j
theorem Cslib.Algorithms.Lean.Scheduling.isListSchedule_iff {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LE α] (p : Fin n → α) (σ : Fin n → Fin m) :
IsListSchedule p σ ↔ ∀ (j : Fin n) (i : Fin m), prefixLoad p σ (↑j) (σ j) ≤ prefixLoad p σ (↑j) i
theorem Cslib.Algorithms.Lean.Scheduling.IsListSchedule.prefixLoad_le {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LE α] {p : Fin n → α} {σ : Fin n → Fin m} (hσ : IsListSchedule p σ) (j : Fin n) (i : Fin m) :
prefixLoad p σ (↑j) (σ j) ≤ prefixLoad p σ (↑j) i

In a list schedule, job j starts on a machine that was least loaded before j.

theorem Cslib.Algorithms.Lean.Scheduling.prefixLoad_zero {α : Type u_1} {n m : ℕ} [AddCommMonoid α] (p : Fin n → α) (σ : Fin n → Fin m) (i : Fin m) :
prefixLoad p σ 0 i = 0
theorem Cslib.Algorithms.Lean.Scheduling.prefixLoad_of_le {α : Type u_1} {n m : ℕ} [AddCommMonoid α] (p : Fin n → α) (σ : Fin n → Fin m) {k : ℕ} (hk : n ≤ k) (i : Fin m) :
prefixLoad p σ k i = load p σ i
theorem Cslib.Algorithms.Lean.Scheduling.prefixLoad_succ {α : Type u_1} {n m : ℕ} [AddCommMonoid α] (p : Fin n → α) (σ : Fin n → Fin m) (j : Fin n) (i : Fin m) :
prefixLoad p σ (↑j + 1) i = prefixLoad p σ (↑j) i + if σ j = i then p j else 0
theorem Cslib.Algorithms.Lean.Scheduling.sum_prefixLoad {α : Type u_1} {n m : ℕ} [AddCommMonoid α] (p : Fin n → α) (σ : Fin n → Fin m) (k : ℕ) :
∑ i : Fin m, prefixLoad p σ k i = ∑ j : Fin n with ↑j < k, p j

The machine loads before job k add up to the total processing time of the jobs j < k.

theorem Cslib.Algorithms.Lean.Scheduling.sum_load {α : Type u_1} {n m : ℕ} [AddCommMonoid α] (p : Fin n → α) (σ : Fin n → Fin m) :
∑ i : Fin m, load p σ i = ∑ j : Fin n, p j

The machine loads add up to the total processing time.

def Cslib.Algorithms.Lean.Scheduling.makespan {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LinearOrder α] [NeZero m] (p : Fin n → α) (σ : Fin n → Fin m) :
α

The makespan of an assignment: the maximum machine load.

noncomputable def Cslib.Algorithms.Lean.Scheduling.optMakespan {α : Type u_1} {n : ℕ} (m : ℕ) [AddCommMonoid α] [LinearOrder α] [NeZero m] (p : Fin n → α) :
α

The optimal makespan over all assignments of the jobs to m machines.

theorem Cslib.Algorithms.Lean.Scheduling.makespan_def {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LinearOrder α] [NeZero m] (p : Fin n → α) (σ : Fin n → Fin m) :
makespan p σ = Finset.univ.sup' ⋯ (load p σ)
theorem Cslib.Algorithms.Lean.Scheduling.load_le_makespan {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LinearOrder α] [NeZero m] (p : Fin n → α) (σ : Fin n → Fin m) (i : Fin m) :
load p σ i ≤ makespan p σ
theorem Cslib.Algorithms.Lean.Scheduling.makespan_le_iff {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LinearOrder α] [NeZero m] (p : Fin n → α) (σ : Fin n → Fin m) {B : α} :
makespan p σ ≤ B ↔ ∀ (i : Fin m), load p σ i ≤ B
theorem Cslib.Algorithms.Lean.Scheduling.optMakespan_le {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LinearOrder α] [NeZero m] (p : Fin n → α) (σ : Fin n → Fin m) :
theorem Cslib.Algorithms.Lean.Scheduling.exists_makespan_eq_optMakespan {α : Type u_1} {n : ℕ} (m : ℕ) [AddCommMonoid α] [LinearOrder α] [NeZero m] (p : Fin n → α) :
∃ (σ : Fin n → Fin m), makespan p σ = optMakespan m p
theorem Cslib.Algorithms.Lean.Scheduling.sum_le_card_nsmul_makespan {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LinearOrder α] [IsOrderedAddMonoid α] [NeZero m] (p : Fin n → α) (σ : Fin n → Fin m) :
∑ j : Fin n, p j ≤ m • makespan p σ

The total processing time is at most m times the makespan of any assignment.

theorem Cslib.Algorithms.Lean.Scheduling.le_makespan {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LinearOrder α] [IsOrderedAddMonoid α] [NeZero m] (p : Fin n → α) (hp : ∀ (j : Fin n), 0 ≤ p j) (σ : Fin n → Fin m) (j : Fin n) :
p j ≤ makespan p σ

Every job's processing time is at most the makespan, for nonnegative processing times.

theorem Cslib.Algorithms.Lean.Scheduling.sum_le_card_nsmul_optMakespan {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LinearOrder α] [IsOrderedAddMonoid α] [NeZero m] (p : Fin n → α) :
∑ j : Fin n, p j ≤ m • optMakespan m p

Average-load lower bound on the optimum, ∑ p ≤ m · OPT ([WS11], (2.4)).

theorem Cslib.Algorithms.Lean.Scheduling.le_optMakespan {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LinearOrder α] [IsOrderedAddMonoid α] [NeZero m] (p : Fin n → α) (hp : ∀ (j : Fin n), 0 ≤ p j) (j : Fin n) :

Longest-job lower bound on the optimum ([WS11], (2.3)).

theorem Cslib.Algorithms.Lean.Scheduling.load_le_of_forall_completion_le {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LinearOrder α] (p : Fin n → α) (σ : Fin n → Fin m) {B : α} (hB : 0 ≤ B) (h : ∀ (j : Fin n), prefixLoad p σ (↑j) (σ j) + p j ≤ B) (i : Fin m) :
load p σ i ≤ B

If every job finishes by B (its start prefixLoad p σ j (σ j) plus p j), then every machine load is at most B.

theorem Cslib.Algorithms.Lean.Scheduling.IsListSchedule.completion_le {α : Type u_1} {n m : ℕ} [Field α] [LinearOrder α] [IsStrictOrderedRing α] {p : Fin n → α} {σ : Fin n → Fin m} (hσ : IsListSchedule p σ) (hp : ∀ (j : Fin n), 0 ≤ p j) (j : Fin n) :
↑m * (prefixLoad p σ (↑j) (σ j) + p j) ≤ ∑ k : Fin n, p k + (↑m - 1) * p j

Graham's averaging bound for one job: under list scheduling, job j finishes by (∑_{k ≠ j} p k) / m + p j.

theorem Cslib.Algorithms.Lean.Scheduling.IsListSchedule.card_mul_makespan_le {α : Type u_1} {n m : ℕ} [Field α] [LinearOrder α] [IsStrictOrderedRing α] [NeZero m] {p : Fin n → α} {σ : Fin n → Fin m} (hσ : IsListSchedule p σ) (hp : ∀ (j : Fin n), 0 ≤ p j) (τ : Fin n → Fin m) :
↑m * makespan p σ ≤ (2 * ↑m - 1) * makespan p τ

Graham's list-scheduling bound ([Gra66], §II, Theorem (p. 1570) with n = n' and no precedences; [WS11], Theorem 2.6 and the refinement after Theorem 2.5): every list schedule has makespan at most 2 - 1/m times the makespan of any assignment, stated without division as m · C_LS ≤ (2m - 1) · C.

theorem Cslib.Algorithms.Lean.Scheduling.IsListSchedule.makespan_le_optMakespan {α : Type u_1} {n m : ℕ} [Field α] [LinearOrder α] [IsStrictOrderedRing α] [NeZero m] {p : Fin n → α} {σ : Fin n → Fin m} (hσ : IsListSchedule p σ) (hp : ∀ (j : Fin n), 0 ≤ p j) :
makespan p σ ≤ (2 - 1 / ↑m) * optMakespan m p

Graham's bound against the optimum: C_LS ≤ (2 - 1/m) · OPT.

def Cslib.Algorithms.Lean.Scheduling.argminFin {α : Type u_1} {m : ℕ} [LinearOrder α] [NeZero m] (f : Fin m → α) :
Fin m

A machine minimizing f, the lowest-indexed one among ties (Graham's convention that simultaneous claims go to the processor of smaller index).

theorem Cslib.Algorithms.Lean.Scheduling.argminFin_le {α : Type u_1} {m : ℕ} [LinearOrder α] [NeZero m] (f : Fin m → α) (i : Fin m) :
f (argminFin f) ≤ f i
def Cslib.Algorithms.Lean.Scheduling.listScheduleAux {α : Type u_1} {m : ℕ} [AddCommMonoid α] [LinearOrder α] [NeZero m] {n : ℕ} :
(Fin n → α) → List (Fin m)

The machines chosen by list scheduling, in list order, as plain data so that each earlier choice is computed once: job n goes to a least loaded machine (lowest index among ties) for the schedule of the first n jobs.

def Cslib.Algorithms.Lean.Scheduling.listSchedule {α : Type u_1} {n m : ℕ} [AddCommMonoid α] [LinearOrder α] [NeZero m] (p : Fin n → α) (j : Fin n) :
Fin m

Graham's list scheduling in list order, with lowest-index tie-breaking.

The recursive description of listSchedule: job n goes to a least loaded machine for the schedule of the first n jobs.

def Cslib.Algorithms.Lean.Scheduling.grahamTight (α : Type u_1) [Field α] (m : ℕ) (j : Fin (m * (m - 1) + 1)) :
α

The standard tight instance for Graham's bound on m machines: m (m - 1) unit jobs followed by one job of length m.

theorem Cslib.Algorithms.Lean.Scheduling.grahamTight_of_lt {α : Type u_1} {m : ℕ} [Field α] {j : Fin (m * (m - 1) + 1)} (hj : ↑j < m * (m - 1)) :
grahamTight α m j = 1
theorem Cslib.Algorithms.Lean.Scheduling.grahamTight_last {α : Type u_1} {m : ℕ} [Field α] :
grahamTight α m (Fin.last (m * (m - 1))) = ↑m

The optimum of the tight instance is m: the long job alone on one machine, and m unit jobs on each of the others.

theorem Cslib.Algorithms.Lean.Scheduling.IsListSchedule.makespan_grahamTight {α : Type u_1} {m : ℕ} [Field α] [LinearOrder α] [IsStrictOrderedRing α] [NeZero m] {σ : Fin (m * (m - 1) + 1) → Fin m} (hσ : IsListSchedule (grahamTight α m) σ) :
makespan (grahamTight α m) σ = (2 - 1 / ↑m) * optMakespan m (grahamTight α m)

Tightness of Graham's bound. Every list schedule of grahamTight α m has makespan 2m - 1 = (2 - 1/m) · OPT, so the ratio of IsListSchedule.makespan_le_optMakespan is attained on m machines for every m.