While this submission is a draft, it cannot be used by other submissions.

Interval scheduling with eligible machine sets

Lax470956.Scheduling · concepts/Lax470956/Scheduling.lean · lax-470956

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural Language Statement

    Definition

    An instance consists of nn jobs and mm identical parallel machines. Job jj has a processing time pj1p_j \ge 1, a deadline djpjd_j \ge p_j, a weight wjw_j, and a set MjM_j of eligible machines. Each job is an interval: job jj, if scheduled, occupies exactly [djpj,dj)[d_j - p_j,\, d_j), 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 WW is attainable.

    Concept map
    1 concept; 12 descendants hidden
    100%
    Proven claimOpen claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Mathlib.Algebra.BigOperators.Fin
    2import Mathlib.Data.Finset.Lattice.Fold
    3
    4/-!
    5---
    6title: Interval scheduling with eligible machine sets
    7type: definition
    8---
    9An instance consists of nn jobs and mm identical parallel machines. Job jj has
    10a processing time pj1p_j \ge 1, a deadline djpjd_j \ge p_j, a weight wjw_j, and a set
    11MjM_j of *eligible* machines. Each job is an interval: job jj, if scheduled, occupies
    12exactly [djpj,dj)[d_j - p_j,\, d_j), so a schedule chooses only *which* machine runs a job,
    13never when.
    14
    15A schedule assigns to every job either an eligible machine or nothing. It is *feasible*
    16if no machine is assigned two jobs whose intervals overlap. Its weight is the total
    17weight of the jobs it schedules. The optimization problem asks for a feasible schedule
    18of maximum weight; the decision problem asks whether weight WW is attainable.
    19
    20# Formalization notes
    21
    22Jobs and machines are `Fin n` and `Fin m` rather than abstract finite types. The
    23difference matters: an instance is something a machine is handed as a word, and a word
    24presents its jobs in an order. An abstract finite type would have to be equipped with an
    25enumeration before anything could be encoded, and the enumeration — not the type — is
    26what the encoding would then describe.
    27
    28The two standing conventions pj1p_j \ge 1 and pjdjp_j \le d_j are fields of the structure,
    29as they are hypotheses of every statement in the source. Without the first, a job of
    30processing time zero occupies an empty interval and overlaps nothing; without the second,
    31the truncated subtraction djpjd_j - p_j would clamp to zero.
    32
    33Overlap is defined on the half-open intervals, so jobs meeting end-to-start do not
    34overlap. `Feasible` constrains only the pairs a schedule actually places on a common
    35machine, and says nothing about rejected jobs; `Complete` is the separate condition that
    36no job is rejected, which the second theorem of this submission is about.
    37
    38The weight of a schedule sums over all jobs, contributing zero for a rejected one, rather
    39than summing over the scheduled ones. The two agree, and the first needs no decidability
    40of the set of scheduled jobs.
    41-/
    42
    43namespace 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
    47of machines allowed to run it. -/
    48structure 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
    66namespace Instance
    67
    68variable (I : Instance)
    69
    70/-- The time at which job `j` starts, namely `d j - p j`: a job occupies exactly the
    71interval `[d j - p j, d j)`. -/
    72def start (j : Fin I.jobs) : ℕ := I.d j - I.p j
    73
    74/-- Jobs `j` and `j'` *overlap*: their half-open intervals meet. -/
    75def 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. -/
    79abbrev Schedule := Fin I.jobs → Option (Fin I.machines)
    80
    81variable {I}
    82
    83/-- A schedule is *feasible* if it places every scheduled job on an eligible machine and
    84never places two overlapping jobs on the same machine. -/
    85def 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. -/
    90def Complete (σ : I.Schedule) : Prop := ∀ j, σ j ≠ none
    91
    92/-- The weight of a schedule: the total weight of the jobs it schedules. -/
    93def weight (σ : I.Schedule) : ℕ := ∑ j, (σ j).elim 0 fun _ => I.w j
    94
    95variable (I)
    96
    97/-- `I` admits a feasible schedule of weight at least `W`. -/
    98def HasWeight (W : ℕ) : Prop := ∃ σ : I.Schedule, Feasible σ ∧ W ≤ weight σ
    99
    100/-- `I` admits a feasible schedule that rejects no job. -/
    101def AllSchedulable : Prop := ∃ σ : I.Schedule, Feasible σ ∧ Complete σ
    102
    103/-- The largest processing time in `I`, and `0` if there are no jobs. -/
    104def pmax : ℕ := Finset.univ.sup I.p
    105
    106end Instance
    107
    108end Lax470956.Scheduling
    109
    Formalization notes

    Jobs and machines are FinnFin n and FinmFin m 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 pj1p_j \ge 1 and pjdjp_j \le d_j 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 djpjd_j - p_j would clamp to zero.

    Overlap is defined on the half-open intervals, so jobs meeting end-to-start do not overlap. FeasibleFeasible constrains only the pairs a schedule actually places on a common machine, and says nothing about rejected jobs; CompleteComplete 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.

    Loading discussion…