Skip to content

[Model] SequencingWithinIntervals #219

@isPANN

Description

@isPANN

Motivation

SEQUENCING WITHIN INTERVALS (P5) from Garey & Johnson, Chapter 3, Section 3.2.2, p.70. A canonical NP-complete single-machine scheduling problem: given tasks each with a release time, deadline, and length, can all tasks be non-overlappingly scheduled so that each runs strictly within its allowed window? Its NP-completeness (Theorem 3.8 in GJ) is proved by reduction from PARTITION using an "enforcer" task that pins the schedule at the midpoint of the time horizon, forcing a balanced split. This is historically significant as one of the first NP-completeness results for single-machine scheduling.

Planned reductions: (1) Partition → SequencingWithinIntervals (implementing the NP-completeness reduction from GJ Theorem 3.8); (2) SequencingWithinIntervals → ILP (binary ILP encoding with ordering variables, as described in "How to solve" below).

Definition

Name: SequencingWithinIntervals
Reference: Garey & Johnson, Computers and Intractability, Chapter 3, Section 3.2.2, p.70

Mathematical definition:

INSTANCE: A finite set T of "tasks" and, for each t ∈ T, an integer "release time" r(t) ≥ 0, an integer "deadline" d(t) ≥ 0, and a "length" l(t) ∈ ℤ+, satisfying r(t) + l(t) ≤ d(t).
QUESTION: Does there exist a feasible schedule for T, that is, a function σ: T → ℤ_{≥0} such that, for each t ∈ T, σ(t) ≥ r(t), σ(t)+l(t) ≤ d(t), and, if t' ∈ T−{t}, then either σ(t')+l(t') ≤ σ(t) or σ(t') ≥ σ(t)+l(t)? (The task t is "executed" from time σ(t) to time σ(t)+l(t), cannot start executing until time r(t), must be completed by time d(t), and its execution cannot overlap the execution of any other task t'.)

Variables

  • Count: n = |T| (one integer variable per task, choosing its start time)
  • Per-variable domain: For each task t, σ(t) ∈ {r(t), r(t)+1, ..., d(t)−l(t)} (all valid integer start times)
  • Meaning: σ(t) is the start time of task t. The constraint σ(t)+l(t) ≤ d(t) ensures t finishes before its deadline; σ(t) ≥ r(t) ensures t starts after its release time. Non-overlap constraints between all pairs of tasks are additional feasibility conditions.
  • Input validity precondition: For every t ∈ T, r(t) + l(t) ≤ d(t) must hold. If this is violated for some task, the variable domain {r(t), …, d(t)−l(t)} is empty and no feasible schedule exists by construction; implementations should assert this precondition at construction time.

Schema (data type)

Type name: SequencingWithinIntervals
Variants: none (no type parameters; all times and lengths are plain non-negative integers)

Field Type Description
release_times Vec<u64> Release time r(t) ≥ 0 for each task t ∈ T
deadlines Vec<u64> Deadline d(t) ≥ 0 for each task t ∈ T; must satisfy d(t) ≥ r(t) + l(t)
lengths Vec<u64> Processing length l(t) ≥ 1 for each task t ∈ T

(All three vectors have the same length n = |T|; index i corresponds to task t_i.)

Complexity

  • Best known exact algorithm: The problem is NP-complete (Garey & Johnson, Theorem 3.8, 1979). For general instances, dynamic programming over task subsets achieves O*(2^n) time: for each subset S ⊆ T, determine the earliest time by which all tasks in S can be feasibly completed, building up from single-task subsets. This is the standard subset-DP approach for single-machine scheduling. [Garey & Johnson, 1979.]
  • Complexity string for declare_variants!: "2 ^ num_tasks"

Extra Remark

Full book text (verbatim):

INSTANCE: A finite set T of "tasks" and, for each t ∈ T, an integer "release time" r(t) ≥ 0, a "deadline" d(t) ∈ Z+, and a "length" l(t) ∈ Z+.
QUESTION: Does there exist a feasible schedule for T, that is, a function σ: T → Z+ such that, for each t ∈ T, σ(t) ≥ r(t), σ(t)+l(t) ≤ d(t), and, if t' ∈ T−{t}, then either σ(t')+l(t') ≤ σ(t) or σ(t') ≥ σ(t)+l(t)? (The task t is "executed" from time σ(t) to time σ(t)+l(t), cannot start executing until time r(t), must be completed by time d(t), and its execution cannot overlap the execution of any other task t'.)

Deviations from verbatim text (with justification):

  1. σ: T → Z+ corrected to σ: T → ℤ_{≥0}: The book's use of Z+ is inconsistent with r(t) ≥ 0 and with Theorem 3.8's own example where σ(t_1) = 0. The standard modern formulation uses ℤ_{≥0}.
  2. Precondition r(t) + l(t) ≤ d(t) made explicit: The book implicitly assumes this (otherwise the problem is trivially infeasible for that task), but does not state it in the instance description. It is added here for implementation correctness.

How to solve

  • It can be solved by (existing) bruteforce. (Enumerate all n! orderings; for each ordering check whether tasks can be placed feasibly without violating release/deadline/non-overlap constraints.)
  • It can be solved by reducing to integer programming. (Binary ILP with ordering variables x_{tt'} ∈ {0,1} indicating whether t precedes t', plus start-time variables; this gives an ILP with O(n^2) variables and constraints.)
  • Other: Constraint programming / branch-and-bound with interval propagation is effective in practice.

Example Instance

Instance 1 (YES):
5 tasks on a single machine with overlapping availability windows:

Task Release r Deadline d Length l
t₁ 0 5 2
t₂ 1 8 2
t₃ 3 9 2
t₄ 6 12 3
t₅ 0 12 2

Each task can only start within its window [r, d−l], and the windows overlap, so finding a non-overlapping assignment is non-trivial. One feasible schedule: t₁ at [0, 2), t₂ at [2, 4), t₃ at [4, 6), t₄ at [6, 9), t₅ at [9, 11).

Exhaustive enumeration: Search space = 4×6×5×4×11 = 5,280 configurations. Exactly 41 feasible schedules. (Used in find_all_satisfying test)

Instance 2 (NO):
Two tasks that must both occupy [0, 2): r = [0, 0], d = [2, 2], l = [2, 2]. Each task has only one possible start time (0), so they always overlap. Search space = 1. 0 feasible schedules. (Used in find_all_satisfying empty test)

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoodAn issue passed all checks.modelA model problem to be implemented.

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions