You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Build as optimization, not decision.Value = Min<u64>. Objective: Minimize makespan (completion time of the last task).
Do not add a bound/threshold field — let the solver find the optimum directly. See #765.
Motivation
JOB-SHOP SCHEDULING (P202) from Garey & Johnson, A5 SS18. One of the most studied NP-hard combinatorial optimization problems: given m processors and a set of jobs, each consisting of an ordered sequence of tasks with specified processor assignments and lengths, find a schedule that minimizes the makespan (completion time of the last task). Unlike flow-shop scheduling, each job can have a different machine routing, and consecutive tasks of the same job must be on different processors. NP-hard in the strong sense even for m = 2 [Garey, Johnson, and Sethi, 1976]. Solvable in polynomial time for m = 2 with at most 2 tasks per job [Jackson, 1956].
This should be implemented as an optimization problem (Value = Min<u64>).
Associated rules:
R147: 3-PARTITION -> JOB-SHOP SCHEDULING (establishes strong NP-completeness for m = 2)
Definition
Name:JobShopScheduling
Reference: Garey & Johnson, Computers and Intractability, A5 SS18
Mathematical definition:
INSTANCE: Number m in Z+ of processors, set J of jobs, each j in J consisting of an ordered collection of tasks t_k[j], 1 <= k <= n_j, for each such task t a length l(t) in Z0+ and a processor p(t) in {1,2,...,m}, where p(t_k[j]) != p(t_{k+1}[j]) for all j in J and 1 <= k < n_j.
OBJECTIVE: Find start times sigma(t_k[j]) in Z0+ such that tasks sharing a processor do not overlap (sigma_i(t) > sigma_i(t') implies sigma_i(t) >= sigma_i(t') + l(t')), each job respects precedence (sigma(t_{k+1}[j]) >= sigma(t_k[j]) + l(t_k[j])), and the makespan max_{j in J} (sigma(t_{n_j}[j]) + l(t_{n_j}[j])) is minimized.
Note: The constraint p(t_k[j]) != p(t_{k+1}[j]) (consecutive tasks of the same job must be on different processors) is part of the original Garey & Johnson formulation. Some modern job-shop formulations relax this constraint; this implementation follows the G&J definition.
Variables
Count: One variable per task, grouped by machine. Total = sum of tasks per machine.
Per-variable domain: Lehmer-code radices — for a machine with k tasks assigned, the radices are (k, k-1, ..., 1).
Meaning: Each variable selects the next task from the remaining unplaced tasks on that machine, encoding a permutation of machine task orders. The schedule is reconstructed by propagating longest paths through the combined job-precedence + machine-order DAG.
Schema (data type)
Type name:JobShopScheduling Variants: none (task lengths are non-negative integers)
Field
Type
Description
num_processors
usize
Number of machines m
jobs
Vec<Vec<(usize, u64)>>
jobs[j][k] = (processor, length) for the k-th task of job j
Complexity
Best known exact algorithm: For m = 2 with n_j <= 2 for all j, solvable in polynomial time by Jackson's rule [Jackson, 1956]. For the general case (m >= 2 with arbitrary task counts), strongly NP-hard. The best known exact approaches use dynamic programming (Gromicho et al., 2012) or branch-and-bound (Brucker et al., 1994). Brute-force requires examining all possible orderings of tasks on each machine, giving factorial complexity.
Complexity expression:factorial(num_tasks) (brute-force bound over machine-order permutations)
Extra Remark
Full book text:
INSTANCE: Number m in Z+ of processors, set J of jobs, each j in J consisting of an ordered collection of tasks t_k[j], 1 <= k <= n_j, for each such task t a length l(t) in Z0+ and a processor p(t) in {1,2,...,m}, where p(t_k[j]) != p(t_{k+1}[j]) for all j in J and 1 <= k < n_j, and a deadline D in Z+.
QUESTION: Is there a job-shop schedule for J that meets the overall deadline, i.e., a collection of one-processor schedules sigma_i mapping {t: p(t) = i} into Z0+, 1 <= i <= m, such that sigma_i(t) > sigma_i(t') implies sigma_i(t) >= sigma_i(t') + l(t), such that sigma(t_{k+1}[j]) >= sigma(t_k[j]) + l(t_k[j]) for all j in J and 1 <= k < n_j, and such that for all j in J sigma(t_{n_j}[j]) + l(t_{n_j}[j]) <= D?
Reference: [Garey, Johnson, and Sethi, 1976]. Transformation from 3-PARTITION.
Comment: NP-complete in the strong sense for m = 2. Can be solved in polynomial time if m = 2 and n_j <= 2 for all j in J [Jackson, 1956]. NP-complete (in the ordinary sense) if m = 2 and n_j <= 3 for all j in J, or if m = 3 and n_j <= 2 for all j in J [Gonzalez and Sahni, 1978a]. All the above results continue to hold if "preemptive" schedules are allowed [Gonzalez and Sahni, 1978a]. If in the nonpreemptive case all tasks have the same length, the problem is NP-complete for m = 3 and open for m = 2 [Lenstra and Rinnooy Kan, 1978b].
How to solve
It can be solved by (existing) bruteforce. (Enumerate all possible machine-order permutations; compute makespan via longest-path propagation.)
It can be solved by reducing to integer programming. (ILP with start-time variables sigma(t), precedence constraints, and disjunctive constraints for tasks sharing a machine: for each pair (t, t') on the same machine, either sigma(t) + l(t) <= sigma(t') or sigma(t') + l(t') <= sigma(t). Minimize makespan.)
Job completion times: j_1 at 11, j_2 at 19, j_3 at 14, j_4 at 12, j_5 at 18.
Precedence: each job's tasks execute in order. ✓
No overlap on each machine. ✓
Consecutive tasks of each job are on different processors (by construction). ✓
Important
Build as optimization, not decision.
Value = Min<u64>.Objective: Minimize makespan (completion time of the last task).
Do not add a
bound/thresholdfield — let the solver find the optimum directly. See #765.Motivation
JOB-SHOP SCHEDULING (P202) from Garey & Johnson, A5 SS18. One of the most studied NP-hard combinatorial optimization problems: given m processors and a set of jobs, each consisting of an ordered sequence of tasks with specified processor assignments and lengths, find a schedule that minimizes the makespan (completion time of the last task). Unlike flow-shop scheduling, each job can have a different machine routing, and consecutive tasks of the same job must be on different processors. NP-hard in the strong sense even for m = 2 [Garey, Johnson, and Sethi, 1976]. Solvable in polynomial time for m = 2 with at most 2 tasks per job [Jackson, 1956].
This should be implemented as an optimization problem (
Value = Min<u64>).Associated rules:
Definition
Name:
JobShopSchedulingReference: Garey & Johnson, Computers and Intractability, A5 SS18
Mathematical definition:
INSTANCE: Number m in Z+ of processors, set J of jobs, each j in J consisting of an ordered collection of tasks t_k[j], 1 <= k <= n_j, for each such task t a length l(t) in Z0+ and a processor p(t) in {1,2,...,m}, where p(t_k[j]) != p(t_{k+1}[j]) for all j in J and 1 <= k < n_j.
OBJECTIVE: Find start times sigma(t_k[j]) in Z0+ such that tasks sharing a processor do not overlap (sigma_i(t) > sigma_i(t') implies sigma_i(t) >= sigma_i(t') + l(t')), each job respects precedence (sigma(t_{k+1}[j]) >= sigma(t_k[j]) + l(t_k[j])), and the makespan max_{j in J} (sigma(t_{n_j}[j]) + l(t_{n_j}[j])) is minimized.
Note: The constraint p(t_k[j]) != p(t_{k+1}[j]) (consecutive tasks of the same job must be on different processors) is part of the original Garey & Johnson formulation. Some modern job-shop formulations relax this constraint; this implementation follows the G&J definition.
Variables
Schema (data type)
Type name:
JobShopSchedulingVariants: none (task lengths are non-negative integers)
num_processorsusizejobsVec<Vec<(usize, u64)>>Complexity
factorial(num_tasks)(brute-force bound over machine-order permutations)Extra Remark
Full book text:
INSTANCE: Number m in Z+ of processors, set J of jobs, each j in J consisting of an ordered collection of tasks t_k[j], 1 <= k <= n_j, for each such task t a length l(t) in Z0+ and a processor p(t) in {1,2,...,m}, where p(t_k[j]) != p(t_{k+1}[j]) for all j in J and 1 <= k < n_j, and a deadline D in Z+.
QUESTION: Is there a job-shop schedule for J that meets the overall deadline, i.e., a collection of one-processor schedules sigma_i mapping {t: p(t) = i} into Z0+, 1 <= i <= m, such that sigma_i(t) > sigma_i(t') implies sigma_i(t) >= sigma_i(t') + l(t), such that sigma(t_{k+1}[j]) >= sigma(t_k[j]) + l(t_k[j]) for all j in J and 1 <= k < n_j, and such that for all j in J sigma(t_{n_j}[j]) + l(t_{n_j}[j]) <= D?
Reference: [Garey, Johnson, and Sethi, 1976]. Transformation from 3-PARTITION.
Comment: NP-complete in the strong sense for m = 2. Can be solved in polynomial time if m = 2 and n_j <= 2 for all j in J [Jackson, 1956]. NP-complete (in the ordinary sense) if m = 2 and n_j <= 3 for all j in J, or if m = 3 and n_j <= 2 for all j in J [Gonzalez and Sahni, 1978a]. All the above results continue to hold if "preemptive" schedules are allowed [Gonzalez and Sahni, 1978a]. If in the nonpreemptive case all tasks have the same length, the problem is NP-complete for m = 3 and open for m = 2 [Lenstra and Rinnooy Kan, 1978b].
How to solve
Example Instance
Input:
m = 2 processors, J = {j_1, j_2, j_3, j_4, j_5} (n = 5 jobs).
Total tasks: 12. Search space: 6! x 6! = 518400 machine-order permutations.
Optimal schedule (makespan = 19):
P1: j_1.t1[0,3], j_2.t2[3,6], j_3.t1[6,10], j_4.t2[10,12], j_5.t1[12,14], j_5.t3[17,18]
P2: j_2.t1[0,2], j_4.t1[2,7], j_1.t2[7,11], j_3.t2[11,14], j_5.t2[14,17], j_2.t3[17,19]
Machine 0 Lehmer order: [0,0,0,0,0,0], Machine 1 Lehmer order: [1,3,0,1,1,0]
Config: [0,0,0,0,0,0,1,3,0,1,1,0]
Optimal value: Min(19)
Job completion times: j_1 at 11, j_2 at 19, j_3 at 14, j_4 at 12, j_5 at 18.
Precedence: each job's tasks execute in order. ✓
No overlap on each machine. ✓
Consecutive tasks of each job are on different processors (by construction). ✓