Interval scheduling with eligible machine sets
Lax470956.Scheduling · concepts/Lax470956/Scheduling.lean · lax-470956
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
An instance consists of jobs and identical parallel machines. Job has a processing time , a deadline , a weight , and a set of eligible machines. Each job is an interval: job , if scheduled, occupies exactly , so a schedule chooses only which machine runs a job, never when.
A schedule assigns to every job either an eligible machine or nothing. It is feasible if no machine is assigned two jobs whose intervals overlap. Its weight is the total weight of the jobs it schedules. The optimization problem asks for a feasible schedule of maximum weight; the decision problem asks whether weight is attainable.
Concept map
Lean source view on GitHub
| 1 | import Mathlib.Algebra.BigOperators.Fin |
| 2 | import Mathlib.Data.Finset.Lattice.Fold |
| 3 | |
| 4 | /-! |
| 5 | --- |
| 6 | title: Interval scheduling with eligible machine sets |
| 7 | type: definition |
| 8 | --- |
| 9 | An instance consists of jobs and identical parallel machines. Job has |
| 10 | a processing time , a deadline , a weight , and a set |
| 11 | of *eligible* machines. Each job is an interval: job , if scheduled, occupies |
| 12 | exactly , so a schedule chooses only *which* machine runs a job, |
| 13 | never when. |
| 14 | |
| 15 | A schedule assigns to every job either an eligible machine or nothing. It is *feasible* |
| 16 | if no machine is assigned two jobs whose intervals overlap. Its weight is the total |
| 17 | weight of the jobs it schedules. The optimization problem asks for a feasible schedule |
| 18 | of maximum weight; the decision problem asks whether weight is attainable. |
| 19 | |
| 20 | # Formalization notes |
| 21 | |
| 22 | Jobs and machines are `Fin n` and `Fin m` rather than abstract finite types. The |
| 23 | difference matters: an instance is something a machine is handed as a word, and a word |
| 24 | presents its jobs in an order. An abstract finite type would have to be equipped with an |
| 25 | enumeration before anything could be encoded, and the enumeration — not the type — is |
| 26 | what the encoding would then describe. |
| 27 | |
| 28 | The two standing conventions and are fields of the structure, |
| 29 | as they are hypotheses of every statement in the source. Without the first, a job of |
| 30 | processing time zero occupies an empty interval and overlaps nothing; without the second, |
| 31 | the truncated subtraction would clamp to zero. |
| 32 | |
| 33 | Overlap is defined on the half-open intervals, so jobs meeting end-to-start do not |
| 34 | overlap. `Feasible` constrains only the pairs a schedule actually places on a common |
| 35 | machine, and says nothing about rejected jobs; `Complete` is the separate condition that |
| 36 | no job is rejected, which the second theorem of this submission is about. |
| 37 | |
| 38 | The weight of a schedule sums over all jobs, contributing zero for a rejected one, rather |
| 39 | than summing over the scheduled ones. The two agree, and the first needs no decidability |
| 40 | of the set of scheduled jobs. |
| 41 | -/ |
| 42 | |
| 43 | namespace Lax470956.Scheduling |
| 44 | |
| 45 | /-- An instance of interval scheduling with eligible machine sets: `jobs` jobs on |
| 46 | `machines` machines, each job with a processing time, a deadline, a weight, and the set |
| 47 | of machines allowed to run it. -/ |
| 48 | structure Instance where |
| 49 | /-- The number `n` of jobs. -/ |
| 50 | jobs : ℕ |
| 51 | /-- The number `m` of machines. -/ |
| 52 | machines : ℕ |
| 53 | /-- The processing time `p j` of job `j`. -/ |
| 54 | p : Fin jobs → ℕ |
| 55 | /-- The deadline `d j` of job `j`. -/ |
| 56 | d : Fin jobs → ℕ |
| 57 | /-- The weight `w j` of job `j`. -/ |
| 58 | w : Fin jobs → ℕ |
| 59 | /-- The machines eligible to run job `j`. -/ |
| 60 | eligible : Fin jobs → Finset (Fin machines) |
| 61 | /-- Every job takes at least one time unit. -/ |
| 62 | p_pos : ∀ j, 0 < p j |
| 63 | /-- Every job fits before its deadline. -/ |
| 64 | p_le_d : ∀ j, p j ≤ d j |
| 65 | |
| 66 | namespace Instance |
| 67 | |
| 68 | variable (I : Instance) |
| 69 | |
| 70 | /-- The time at which job `j` starts, namely `d j - p j`: a job occupies exactly the |
| 71 | interval `[d j - p j, d j)`. -/ |
| 72 | def start (j : Fin I.jobs) : ℕ := I.d j - I.p j |
| 73 | |
| 74 | /-- Jobs `j` and `j'` *overlap*: their half-open intervals meet. -/ |
| 75 | def Overlap (j j' : Fin I.jobs) : Prop := |
| 76 | I.start j < I.d j' ∧ I.start j' < I.d j |
| 77 | |
| 78 | /-- A schedule assigns each job an eligible machine, or nothing. -/ |
| 79 | abbrev Schedule := Fin I.jobs → Option (Fin I.machines) |
| 80 | |
| 81 | variable {I} |
| 82 | |
| 83 | /-- A schedule is *feasible* if it places every scheduled job on an eligible machine and |
| 84 | never places two overlapping jobs on the same machine. -/ |
| 85 | def Feasible (σ : I.Schedule) : Prop := |
| 86 | (∀ j i, σ j = some i → i ∈ I.eligible j) ∧ |
| 87 | (∀ j j' i, j ≠ j' → I.Overlap j j' → σ j = some i → σ j' ≠ some i) |
| 88 | |
| 89 | /-- A schedule is *complete* if it rejects no job. -/ |
| 90 | def Complete (σ : I.Schedule) : Prop := ∀ j, σ j ≠ none |
| 91 | |
| 92 | /-- The weight of a schedule: the total weight of the jobs it schedules. -/ |
| 93 | def weight (σ : I.Schedule) : ℕ := ∑ j, (σ j).elim 0 fun _ => I.w j |
| 94 | |
| 95 | variable (I) |
| 96 | |
| 97 | /-- `I` admits a feasible schedule of weight at least `W`. -/ |
| 98 | def HasWeight (W : ℕ) : Prop := ∃ σ : I.Schedule, Feasible σ ∧ W ≤ weight σ |
| 99 | |
| 100 | /-- `I` admits a feasible schedule that rejects no job. -/ |
| 101 | def AllSchedulable : Prop := ∃ σ : I.Schedule, Feasible σ ∧ Complete σ |
| 102 | |
| 103 | /-- The largest processing time in `I`, and `0` if there are no jobs. -/ |
| 104 | def pmax : ℕ := Finset.univ.sup I.p |
| 105 | |
| 106 | end Instance |
| 107 | |
| 108 | end Lax470956.Scheduling |
| 109 |
Formalization notes
Jobs and machines are and rather than abstract finite types. The difference matters: an instance is something a machine is handed as a word, and a word presents its jobs in an order. An abstract finite type would have to be equipped with an enumeration before anything could be encoded, and the enumeration — not the type — is what the encoding would then describe.
The two standing conventions and are fields of the structure, as they are hypotheses of every statement in the source. Without the first, a job of processing time zero occupies an empty interval and overlaps nothing; without the second, the truncated subtraction would clamp to zero.
Overlap is defined on the half-open intervals, so jobs meeting end-to-start do not overlap. constrains only the pairs a schedule actually places on a common machine, and says nothing about rejected jobs; is the separate condition that no job is rejected, which the second theorem of this submission is about.
The weight of a schedule sums over all jobs, contributing zero for a rejected one, rather than summing over the scheduled ones. The two agree, and the first needs no decidability of the set of scheduled jobs.
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments