Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lecture 9: Machine Scheduling and Modeling Tricks

Open In Colab

The previous notebooks showed problems that are ILO fairly directly. Single-machine scheduling is different: two of its requirements, that jobs do not overlap and that lateness is only penalized when a job is actually late, are not linear at first sight. We model the problem in the same steps as the other applications in this lecture, and introduce the tricks that make it linear. After the model, we look at these tricks in general: binary variables combined with a big M turn either/or choices, fixed costs and conditional constraints into linear constraints.

Learning outcomes

On completion of this notebook, you will be able to:

  • formulate a single-machine scheduling problem as an ILO model;

  • formulate either/or (disjunctive) constraints as linear constraints with a binary variable and a big M;

  • model fixed costs and conditional constraints with binary indicator variables.

Single-Machine Scheduling

Practical Motivation

A production facility receives a list of production orders (jobs), which it processes one at a time on a single machine. Some orders only become available later (the material has not arrived yet), and every order has a promised delivery date. Finishing late costs money, for example a contractual penalty per day, and some customers are more important than others. In which order, and when, should the jobs be processed so that the total penalty is as low as possible? Related problems are project planning and planning in healthcare, such as operating-room scheduling.

Modeling

Problem Definition and Example

There are nn jobs. Job ii has a duration sis_i, a release date rir_i before which it cannot start, a due date did_i, and a tardiness cost cic_i per time unit it finishes after its due date. The machine processes one job at a time, and a job that has started runs until it is finished. The problem is to find a schedule (a start time per job) that minimizes the total weighted tardiness, where the tardiness of a job is how long it finishes after its due date (0 if it is on time).

As an example, take n=3n = 3 jobs:

job iiduration sis_irelease date rir_idue date did_itardiness cost cic_i
16081
24271
351121

For example, processing the jobs in the order 1, 3, 2 without idle time gives job 1 the time interval 0-6, job 3 the interval 6-11 and job 2 the interval 11-15. Jobs 1 and 3 are on time, and job 2 finishes 15−7=815 - 7 = 8 time units late, so this schedule has a total weighted tardiness of 8.

Decision Variables

A schedule is fully described by when each job starts, so the natural decision variables are

xi=start time of job i,i=1,…,n.x_i = \text{start time of job } i, \quad i = 1, \dots, n.

The finish time of job ii is then xi+six_i + s_i. We will see below that two more sets of variables are needed to write the objective and the constraints linearly: a binary yijy_{ij} for the order of each pair of jobs, and a ziz_i for the tardiness of each job.

Objective

The tardiness of job ii is max⁡(xi+si−di,0)\max(x_i + s_i - d_i, 0), so we want to minimize

∑i=1ncimax⁡(xi+si−di,0).\sum_{i=1}^{n} c_i \max(x_i + s_i - d_i, 0).

The maximum is not linear. But since we minimize it, the trick from the project-planning model works: introduce a variable ziz_i for the tardiness of job ii that must be at least both terms of the maximum,

zi≥xi+si−di,zi≥0,i=1,…,n,z_i \ge x_i + s_i - d_i, \quad z_i \ge 0, \quad i = 1, \dots, n,

and minimize ∑i=1ncizi\sum_{i=1}^{n} c_i z_i instead. These constraints only say that ziz_i is at least the tardiness, but because ci>0c_i > 0, the optimizer pushes every ziz_i down until one of them is met exactly, so that zi=max⁡(xi+si−di,0)z_i = \max(x_i + s_i - d_i, 0) at the optimum.

Constraints

Release dates. A job cannot start before it is released:

xi≥ri,i=1,…,n.x_i \ge r_i, \quad i = 1, \dots, n.

No overlap. If job ii is processed before job jj, then job jj can only start once job ii has finished: xi+si≤xjx_i + s_i \le x_j. If jj comes first, we need xj+sj≤xix_j + s_j \le x_i instead. Exactly one of the two must hold, but which one is not known in advance: the order is itself something to decide. So we add a binary decision variable for the order of each pair of jobs,

yij={1if job i is processed before job j,0otherwise,i≠j,y_{ij} = \begin{cases} 1 & \text{if job } i \text{ is processed before job } j, \\ 0 & \text{otherwise,} \end{cases} \quad i \ne j,

with yij+yji=1y_{ij} + y_{ji} = 1, since one of the two jobs comes first. We then switch the constraint xi+si≤xjx_i + s_i \le x_j on or off with a big M, a constant larger than any difference in time that can occur in a sensible schedule:

xi+si≤xj+M(1−yij),i≠j.x_i + s_i \le x_j + M(1 - y_{ij}), \quad i \ne j.

For a pair of jobs ii and jj this gives two constraints, one for yijy_{ij} and one for yjiy_{ji}, and the order decides which one does the work:

orderyijy_{ij}yjiy_{ji}xi+si≤xj+M(1−yij)x_i + s_i \le x_j + M(1 - y_{ij})xj+sj≤xi+M(1−yji)x_j + s_j \le x_i + M(1 - y_{ji})
ii before jj10xi+si≤xjx_i + s_i \le x_jxj+sj≤xi+Mx_j + s_j \le x_i + M (no restriction)
jj before ii01xi+si≤xj+Mx_i + s_i \le x_j + M (no restriction)xj+sj≤xix_j + s_j \le x_i

M=max⁡iri+∑isiM = \max_i r_i + \sum_i s_i is large enough: all jobs can be finished by then, so no sensible schedule has a job finishing more than MM after another job starts.

Complete ILO Model

min⁡∑i=1ncizi(weighted tardiness)s.t.xi≥ri,i=1,…,n(release dates)xi+si≤xj+M(1−yij),i≠j(no overlap)yij+yji=1,i<j(order)zi≥xi+si−di,i=1,…,n(tardiness)yij∈{0,1},i≠jzi≥0,i=1,…,n.\begin{aligned} \min \quad & \sum_{i=1}^{n} c_i z_i & \text{(weighted tardiness)} \\ \text{s.t.} \quad & x_i \ge r_i, \quad i = 1, \dots, n & \text{(release dates)} \\ & x_i + s_i \le x_j + M(1 - y_{ij}), \quad i \ne j & \text{(no overlap)} \\ & y_{ij} + y_{ji} = 1, \quad i < j & \text{(order)} \\ & z_i \ge x_i + s_i - d_i, \quad i = 1, \dots, n & \text{(tardiness)} \\ & y_{ij} \in \{0, 1\}, \quad i \ne j \\ & z_i \ge 0, \quad i = 1, \dots, n. \end{aligned}

The model grows fast: for nn jobs it has n2+nn^2 + n variables and 1.5n2+0.5n1.5n^2 + 0.5n constraints (not counting zi≥0z_i \ge 0 and the binary constraints), mostly because of the yijy_{ij}.

Modeling the Example

For the three jobs, M=max⁡iri+∑isi=2+15=17M = \max_i r_i + \sum_i s_i = 2 + 15 = 17, and the model is

min⁡z1+z2+z3s.t.x1≥0(release dates)x2≥2x3≥1x1+6≤x2+17(1−y12)(no overlap)x1+6≤x3+17(1−y13)x2+4≤x1+17(1−y21)x2+4≤x3+17(1−y23)x3+5≤x1+17(1−y31)x3+5≤x2+17(1−y32)y12+y21=1(order)y13+y31=1y23+y32=1z1≥x1+6−8(tardiness)z2≥x2+4−7z3≥x3+5−12yij∈{0,1},i,j=1,2,3, i≠jz1,z2,z3≥0.\begin{aligned} \min \quad & z_1 + z_2 + z_3 \\ \text{s.t.} \quad & x_1 \ge 0 & \text{(release dates)} \\ & x_2 \ge 2 \\ & x_3 \ge 1 \\ & x_1 + 6 \le x_2 + 17(1 - y_{12}) & \text{(no overlap)} \\ & x_1 + 6 \le x_3 + 17(1 - y_{13}) \\ & x_2 + 4 \le x_1 + 17(1 - y_{21}) \\ & x_2 + 4 \le x_3 + 17(1 - y_{23}) \\ & x_3 + 5 \le x_1 + 17(1 - y_{31}) \\ & x_3 + 5 \le x_2 + 17(1 - y_{32}) \\ & y_{12} + y_{21} = 1 & \text{(order)} \\ & y_{13} + y_{31} = 1 \\ & y_{23} + y_{32} = 1 \\ & z_1 \ge x_1 + 6 - 8 & \text{(tardiness)} \\ & z_2 \ge x_2 + 4 - 7 \\ & z_3 \ge x_3 + 5 - 12 \\ & y_{ij} \in \{0, 1\}, \quad i, j = 1, 2, 3,\ i \ne j \\ & z_1, z_2, z_3 \ge 0. \end{aligned}

Solving the Example in pulp

The jobs are named "J1", "J2" and "J3", like the warehouses and stores in the transportation problem, so that duration["J2"] reads as “the duration of job 2” and cannot be mistaken for a list position. Two things in the code are new. The release dates are not added as separate constraints but as lower bounds of the start-time variables (lowBound=release[i]), which means the same to the solver. And the big M is computed from the data instead of typed in, so it stays large enough when the data changes.

status: Optimal
start times: {'J1': 0.0, 'J2': 6.0, 'J3': 10.0}
processing order: ['J1', 'J2', 'J3']
total weighted tardiness: 6.0

The optimal order is J1, J2, J3, with a total weighted tardiness of 6: jobs 2 and 3 are each 3 time units late. That is better than the order 1, 3, 2 from the example above, which had tardiness 8.

Extensions

Other Objectives

The same variables support other common objectives just by changing the line we minimize:

  • flowtime ∑i(xi+si−ri)\sum_i (x_i + s_i - r_i): total time jobs spend in the system;

  • makespan max⁡i(xi+si)\max_i (x_i + s_i): when the machine finishes everything; minimize it with the project-planning trick, min⁡z\min z subject to xi+si≤zx_i + s_i \le z for all ii;

  • a weighted sum of makespan and tardiness (or: minimize tardiness first, then minimize makespan with the tardiness fixed at its optimum).

Modeling Tricks Used in This Model

The scheduling model used a binary variable and a big M to switch a constraint on or off. The same idea shows up in many other models. This section describes it in general.

Big M and Indicator Variables

Suppose a cost is incurred only when an activity is used at all, regardless of how much. Take the product-mix problem with xx bookcases and yy desks, and suppose that making any desks at all requires a special tool with a fixed cost KK, however many desks are made. Introduce a binary zz meaning “desks are made”, subtract KzK z from the profit 3x+5y3x + 5y, and tie zz to yy with a big M, a constant at least as large as yy could ever be:

y≤Mz.y \le M z.

If y>0y > 0 then zz is forced to 1. If y=0y = 0 then zz could be 0 or 1, but since K>0K > 0 and we are maximizing profit, the optimizer sets it to 0. So effectively z=1⇔y>0z = 1 \Leftrightarrow y > 0. Here M=4M = 4 is large enough: the oak-panel constraint x+3y≤12x + 3y \le 12 already gives y≤4y \le 4. A binary variable used this way, to indicate whether something happens, is called an indicator variable.

Conditional Constraints

The same idea handles a constraint that should hold only under a condition. If binary yy represents the condition and the constraint is x≤bx \le b, then

x≤b+(1−y)Mx \le b + (1 - y) M

is the original constraint when y=1y = 1, and no constraint at all (right-hand side huge) when y=0y = 0. The no-overlap constraints of the scheduling model are of this form, with the condition “job ii comes before job jj”.

Either/Or (Disjunctive) Constraints

In the scheduling model, for every pair of jobs one of two constraints had to hold, and we did not know in advance which one. In general, for two constraints f(x)≤0f(x) \le 0 and g(x)≤0g(x) \le 0 of which at least one must hold, introduce a binary yy and a big M:

f(x)≤(1−y)Mg(x)≤yMy∈{0,1}.\begin{aligned} f(x) &\le (1 - y) M \\ g(x) &\le y M \\ y &\in \{0, 1\}. \end{aligned}

When y=1y = 1 the first constraint is enforced and the second is switched off; when y=0y = 0 the reverse. In the scheduling model we used two binaries yijy_{ij} and yjiy_{ji} with yij+yji=1y_{ij} + y_{ji} = 1 instead of a single yy, which is the same thing written symmetrically.

Choose MM as small as possible while still switching the constraint off: a very large MM makes the LO relaxations that branch and bound solves weak, and can cause numerical trouble in the solver.

References

  • Koole, G. (2019). An Introduction to Business Analytics. §6.7 “Modeling Tricks.” The book’s AMPL example is replaced with pulp.