-
Notifications
You must be signed in to change notification settings - Fork 3
[Model] PreemptiveScheduling #504
Description
Important
Build as optimization, not decision. Value = Min<usize>.
Objective: Minimize makespan (completion time of the last task) with preemption allowed.
Do not add a bound/threshold field — let the solver find the optimum directly. See #765.
Motivation
PREEMPTIVE SCHEDULING (P196) from Garey & Johnson, A5 SS12. A fundamental NP-hard multiprocessor scheduling problem that allows tasks to be interrupted and resumed later (preemption), while requiring precedence constraints to be respected. Despite the flexibility of preemption, the problem remains NP-complete in general (reduction from 3SAT). Polynomial-time solvable for m = 2 processors, forest-structured precedence, or empty precedence with individual deadlines.
Associated rules:
- R141: 3SAT → PreemptiveScheduling (this model is the target)
Definition
Name: PreemptiveScheduling
Reference: Garey & Johnson, Computers and Intractability, A5 SS12
Mathematical definition:
INSTANCE: Set T of n tasks, number m ∈ Z⁺ of processors, partial order ≺ on T (precedence constraints), and for each t ∈ T a length l(t) ∈ Z⁺.
OBJECTIVE: Find an m-processor preemptive schedule σ that obeys the precedence constraints and minimizes the makespan (completion time of the last task).
A preemptive schedule allows subdividing each task t into subtasks t₁, t₂, …, tₖ with Σ l(tᵢ) = l(t), where subtasks run non-overlapping on any processor. At most m tasks may be processed simultaneously. Precedence constraints require that all subtasks of t complete before any subtask of t' whenever t ≺ t'.
The makespan lower bound is max(max_t l(t), ⌈Σ l(t) / m⌉, critical_path_length).
The corresponding decision problem (GJ SS12) asks whether a schedule exists with makespan ≤ D for a given deadline D ∈ Z⁺.
Variables
- Count: n × D_max, where D_max = Σ l(t) (upper bound on makespan). Each variable x_{t,u} indicates whether task t is being processed at time slot u.
- Per-variable domain: {0, 1} (binary: processing or not at this time slot)
- Meaning: config[t × D_max + u] = 1 means task t is being processed at time u. A valid schedule satisfies: (1) Σ_u x_{t,u} = l(t) for all tasks, (2) Σ_t x_{t,u} ≤ m for all time slots, (3) precedence constraints are respected (all time slots for predecessor t complete before any time slot for successor t'). The makespan is the last time slot u with any x_{t,u} = 1.
dims() returns [2; n × D_max].
Schema (data type)
Type name: PreemptiveScheduling
Variants: none (no type parameters)
| Field | Type | Description | Getter |
|---|---|---|---|
lengths |
Vec<usize> |
Processing time l(t) for each task t | num_tasks() → self.lengths.len() |
num_processors |
usize |
Number of identical processors m | num_processors() |
precedences |
Vec<(usize, usize)> |
Edges (i, j) of the precedence DAG | num_precedences() → self.precedences.len() |
Problem type: Optimization (minimization)
Value type: Min<usize>
Complexity
- Decision complexity: NP-complete by reduction from 3SAT (Ullman, 1975), even with unit-length tasks.
- Best known exact algorithm: ILP or constraint programming formulations. Brute-force over all possible time-slot assignments is O(2^(n·D_max)).
- Complexity string for
declare_variants!:"2^(num_tasks * num_tasks)"(brute-force over binary schedule matrices; D_max ≤ Σ l(t) ≤ n · max_l ≤ n²) - Special cases:
- m = 2 processors: polynomial (Muntz & Coffman, 1969)
- Forest precedence: polynomial (Muntz & Coffman, 1970)
- Empty precedence with individual deadlines: polynomial (Horn, 1974)
- References:
- [Ullman, 1975] J. D. Ullman, "NP-complete scheduling problems", JCSS 10, 1975.
- [Muntz & Coffman, 1969] R. R. Muntz and E. G. Coffman, "Optimal preemptive scheduling on two-processor systems", IEEE Trans. Computers, 1969.
- [Muntz & Coffman, 1970] R. R. Muntz and E. G. Coffman, "Preemptive scheduling of real-time tasks on multiprocessor systems", JACM 17(2), 1970.
- [Horn, 1974] W. A. Horn, "Some simple scheduling algorithms", Naval Research Logistics Quarterly 21, 1974.
Extra Remark
Full book text:
INSTANCE: Set T of tasks, number m in Z+ of processors, partial order < on T, length l(t) in Z+ for each t in T, and an overall deadline D in Z+.
QUESTION: Is there an m-processor "preemptive" schedule for T that obeys the precedence constraints and meets the overall deadline? (Such a schedule sigma is identical to an ordinary m-processor schedule, except that we are allowed to subdivide each task t in T into any number of subtasks t1, t2, ..., tk such that sum_{i=1}^{k} l(ti) = l(t) and it is required that sigma(ti + 1) >= sigma(ti)+l(ti) for 1 <= i < k. The precedence constraints are extended to subtasks by requiring that every subtask of t precede every subtask of t' whenever t < t'.)
Reference: [Ullman, 1975]. Transformation from 3SAT.
Comment: Can be solved in polynomial time if m = 2 [Muntz and Coffman, 1969], if < is a "forest" [Muntz and Coffman, 1970], or if < is empty and individual task deadlines are allowed [Horn, 1974].
Note: The original GJ formulation is a decision problem with deadline D. This issue reformulates it as an optimization problem (minimize makespan). The decision version is recovered by checking whether the optimal makespan ≤ D.
How to solve
- It can be solved by (existing) bruteforce. The search space 2^(n·D_max) is too large for practical brute-force enumeration.
- It can be solved by reducing to integer programming. Binary ILP: x_{t,u} ∈ {0,1} for each task t and time slot u; Σ_u x_{t,u} = l(t); Σ_t x_{t,u} ≤ m; precedence ordering constraints; minimize makespan variable.
- Other: Polynomial-time algorithms for special cases (m=2, forest precedence, empty precedence).
Example Instance
Input:
T = {t₁, t₂, t₃, t₄, t₅} (n = 5 tasks), m = 2 processors
Lengths: l(t₁) = 2, l(t₂) = 1, l(t₃) = 3, l(t₄) = 2, l(t₅) = 1
Precedences: t₁ ≺ t₃, t₂ ≺ t₄
Total work = 2 + 1 + 3 + 2 + 1 = 9.
Work lower bound: ⌈9/2⌉ = 5.
Critical path: max(l(t₁)+l(t₃), l(t₂)+l(t₄)) = max(2+3, 1+2) = 5.
Lower bound: max(5, 5) = 5.
Optimal preemptive schedule (makespan = 5):
| Time | Proc 1 | Proc 2 | Notes |
|---|---|---|---|
| 0 | t₁ (1/2) | t₂ (1/1 ✓) | t₂ completes |
| 1 | t₁ (2/2 ✓) | t₅ (1/1 ✓) | t₁, t₅ complete |
| 2 | t₃ (1/3) | t₄ (1/2) | t₁ done → t₃ eligible; t₂ done → t₄ eligible |
| 3 | t₃ (2/3) | t₄ (2/2 ✓) | t₄ completes |
| 4 | t₃ (3/3 ✓) | idle | t₃ completes |
Makespan = 5 = lower bound. Optimal.
Suboptimal feasible schedule (makespan = 6):
| Time | Proc 1 | Proc 2 |
|---|---|---|
| 0 | t₂ (✓) | t₅ (✓) |
| 1 | t₁ (1/2) | idle |
| 2 | t₁ (✓) | t₄ (1/2) |
| 3 | t₃ (1/3) | t₄ (✓) |
| 4 | t₃ (2/3) | idle |
| 5 | t₃ (✓) | idle |
Makespan = 6 > 5. Valid but suboptimal (t₁ starts late, wasting processor capacity).
Expected outcome: Min(5)
Reduction Rule Crossref
- R141: Satisfiability (3SAT) → PreemptiveScheduling
- Direct ILP: PreemptiveScheduling → ILP (binary time-slot assignment model)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status