Instances with processing times in and their bit-string encodings (Theorem 6)
DefinitionUnrelatedSched_TwoTimes_Supplement_OneTwoEncodingThis file fixes the data of Theorem 6 of Lenstra, Shmoys and Tardos and how that data is written as a bit string, so that a running time can be measured.
Instances. There are machines and jobs ; job needs time units on machine . The matrix is a matrix if
each entry being chosen independently.
Input encoding. The instance is written as the bit string consisting of ones, a zero, ones, a zero, and then the entries of row by row (machine first; within a machine, job first), one bit per entry: for and for . On a matrix this string determines , and , and its length is .
Output encoding. A schedule , which runs job on machine , is written as the concatenation over of ones followed by a zero. Given it determines , and its length is at most .
These encodings give Theorem 6's phrase "solvable in polynomial time" a concrete input and output on which a Turing machine's running time is counted.
Formalization Note Machines are Fin m, jobs Fin n and processing times natural numbers; the indicator bit of an entry is decide (P i j = 2). The encoding is meant for matrices only: on other matrices it forgets every entry except whether it equals . The numbers and are written in unary; since the matrix is part of the input, this changes the input length by at most a constant factor whenever .
import Mathlib
namespace UnrelatedSched.TwoTimes.Supplement
/-- The processing-time matrix `P` (machines `Fin m`, jobs `Fin n`) has every entry in `{1, 2}`
(Lenstra, Shmoys, Tardos, CWI Report OS-R8714 (1987), §5, Theorem 6, p. 8). Each entry is
constrained independently. -/
def IsOneTwoMatrix {m n : ℕ} (P : Matrix (Fin m) (Fin n) ℕ) : Prop :=
∀ i j, P i j = 1 ∨ P i j = 2
/-- The binary input encoding of a scheduling instance with processing times in `{1, 2}`:
the number of machines `m` in unary (`m` copies of `true`), a separator `false`, the number of jobs
`n` in unary, a separator `false`, and then the `m * n` entries of `P` in row-major order
(machine `0` first, then within a machine job `0` first), one bit each: `false` for `P i j = 1`
and `true` for `P i j = 2`. On a `{1, 2}` matrix this determines `m`, `n` and `P`, and its length
is `m + n + m * n + 2`. -/
def encodeInstance {m n : ℕ} (P : Matrix (Fin m) (Fin n) ℕ) : List Bool :=
List.replicate m true ++ [false] ++ List.replicate n true ++ [false] ++
(List.ofFn fun i : Fin m => List.ofFn fun j : Fin n => decide (P i j = 2)).flatten
/-- The binary output encoding of a schedule `σ : Fin n → Fin m` (job `j` runs on machine `σ j`):
for each job `j = 0, …, n - 1` in turn, the machine index `σ j` in unary (`σ j` copies of `true`)
followed by a separator `false`. It determines `σ` (given `n`), and its length is at most
`n * m`. -/
def encodeSchedule {m n : ℕ} (σ : Fin n → Fin m) : List Bool :=
(List.ofFn fun j : Fin n => List.replicate (σ j : ℕ) true ++ [false]).flatten
end UnrelatedSched.TwoTimes.Supplement