Part IV · trunk C · constraint programming and SAT · spine
One constraint that sees the whole structure beats many that each see a pair. Matching filters alldifferent; compulsory parts filter cumulative; the price is paid per call.
needs 17, 15~1¾ h slides + 3 h lablab: uv run co lab 18
18 · overview
What a decomposition cannot see; strength versus cost.
Hall sets, the value graph, Régin's matching-based filter.
Cumulative: timetable, edge-finding, disjunctive.
element, table, circuit, gcc — and the one design question.
Words with a dotted underline are glossary terms: click one for its definition. G lists every term in the unit, N shows the notes. Optional extra: interactive figures, linked from the slides they support by a small ▸ chip; skip them freely.
section 1
Pairs cannot count.
18 · why global
$\{x_1, x_2\}$ is a Hall set: $k$ variables whose domains together hold exactly $k$ values. By Hall's theorem (unit 15), alldifferent is satisfiable iff no set of variables has fewer values than members.
Arc consistency on a decomposition is at most as strong as generalised arc consistency on the global constraint, and often strictly weaker. For alldifferent, pairwise AC equals GAC only in the trivial case of fixed variables.
A stronger propagator removes more and costs more per call. It wins only if the nodes saved outweigh the time per node. That trade-off (strength vs cost) is the only design question in CP, and lab then shows both outcomes.
section 2
Unit 15, doing load-bearing work.
18 · alldifferent
The value graph of the example. Thick: a maximum matching. Dashed: edges in no maximum matching, removed. {x₁, x₂} ↔ {1, 2} is an alternating cycle, so those edges stay. The next slide works it out.
$O(m \sqrt n)$ for the matching and $O(m)$ for the rest: Régin's filter. Incrementally, the old matching is repaired rather than recomputed (incremental matching).
Lab step 2's test: on 80 random instances, the kept values equal brute-force supports exactly.
18 · alldifferent · example
$x_1, x_2 \in \{1,2\}$, $x_3 \in \{1,2,3\}$, $x_4 \in \{2,3,4\}$. Ten edges in the value graph.
| step | result |
|---|---|
| 1. maximum matching | $x_1\!-\!1$, $x_2\!-\!2$, $x_3\!-\!3$, $x_4\!-\!4$: covers every variable, no free value |
| 2. orient | matched: $1 \to x_1$, $2 \to x_2$, $3 \to x_3$, $4 \to x_4$; others: $x_1 \to 2$, $x_2 \to 1$, $x_3 \to 1$, $x_3 \to 2$, $x_4 \to 2$, $x_4 \to 3$ |
| 3. SCCs | $\{x_1, x_2, 1, 2\}$ (cycle $x_1 \to 2 \to x_2 \to 1 \to x_1$); every other node alone |
| 4. keep | matched edges, and edges inside an SCC |
| edge | Hall set behind it |
|---|---|
| $x_3 = 1$, $x_3 = 2$ | $\{x_1, x_2\}$ own values $\{1, 2\}$ |
| $x_4 = 2$ | $\{x_1, x_2\}$ own values $\{1, 2\}$ |
| $x_4 = 3$ | $\{x_1, x_2, x_3\}$ own values $\{1, 2, 3\}$ |
Result: $x_3 = 3$, $x_4 = 4$, and $x_1, x_2$ keep $\{1, 2\}$: one matching, one SCC pass, all four removals at once.
Edge $x_3\!-\!1$ is not on any alternating cycle: from $x_3$ you reach 1 and 2 and their cycle, but the only arc into $x_3$ comes from value 3, and that cycle never reaches 3.
18 · alldifferent
Lab then, your unit-17 engine:
| model | nodes | propagations | s | |
|---|---|---|---|---|
| queens 10, all | pairwise | 11 430 | 973 550 | 1.44 |
| alldifferent | 9 326 | 45 382 | 2.56 | |
| sudoku (Inkala) | pairwise | 3 598 | 823 458 | 1.14 |
| alldifferent | 102 | 3 272 | 0.18 | |
| pigeonhole 10 → 9 | pairwise | 725 758 | 16.6 M | 25.9 |
| alldifferent | 0 | 1 | 0.00 |
CP-SAT, queens 11 all solutions: 8.1 s pairwise, 2.1 s with AddAllDifferent.
Two decisions down Inkala's solution path, pairwise ≠ at its fixpoint: alldifferent on row 7 removes 2, 4 and 7 from cell r7c1 (row 7, column 1; domain {2, 4, 5, 7}), leaving 5. The Hall set: r7c2, r7c4, r7c5, r7c6, whose domains hold only {2, 4, 7, 9}.
section 3
Tasks, resources, time.
18 · scheduling
Duration 3, start ∈ {2, 3}: whatever it chooses, the task runs during [3, 5). Lab test: with capacity 1, a second task of duration 3 loses starts 1–4.
cumulative$(s, d, r, C)$: tasks with start variables $s_i$, durations $d_i$ and demands $r_i$ never use more than $C$ at once.
Disjunctive scheduling (one machine) is cumulative with $C = 1$ and every $r_i = 1$. Lab step 4's job-shop uses one per machine.
18 · scheduling · example
Capacity $C = 2$, every demand 1.
| task | duration | start in | compulsory part |
|---|---|---|---|
| A | 4 | $\{0, 1, 2\}$ | $[2, 4)$: latest start 2, earliest end 4 |
| B | 3 | $\{1, 2\}$ | $[2, 4)$: latest start 2, earliest end 4 |
| C | 2 | $\{0, \dots, 5\}$ | empty: latest start 5 > earliest end 2 |
| time | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| profile | 0 | 0 | 2 | 2 | 0 | 0 | 0 |
C runs $[t, t+2)$. Times 2 and 3 are already full (2 of 2).
$t = 1$ covers time 2; $t = 2$ covers 2 and 3; $t = 3$ covers 3. All three removed. $t = 0$, 4, 5 miss the full times and stay.
C's starts: $\{0, 4, 5\}$.
Their own compulsory parts are what fill times 2 and 3, so each must subtract itself before checking. Doing that, neither loses a start: the profile without A is 1 at times 2–3, and A fits.
18 · scheduling
Lab then, ft06 (optimum 55), 100 000 nodes:
| machines as | 55 found at node | proof |
|---|---|---|
| pairwise disjunctions | 588 | not finished |
| cumulative, timetable | 116 | not finished |
| CP-SAT, pairwise | 0.035 s | |
CP-SAT, AddNoOverlap | 0.018 s |
CP-SAT's no-overlap runs edge-finding, not-first/not-last and precedence reasoning, all explained as clauses and learned from (unit 21).
18 · scheduling · example
One machine (capacity 1). Times as est = earliest start, lct = latest completion.
| task | duration | est | lct |
|---|---|---|---|
| A | 2 | 0 | 5 |
| B | 3 | 0 | 5 |
| C | 3 | 1 | 10 |
$\Omega = \{A, B\}$: $\text{est}_\Omega = 0$, $\text{lct}_\Omega = 5$, total duration 5.
Add C: $\text{est}_{\Omega \cup C} + d_{\Omega \cup C} = 0 + 8 = 8 > 5 = \text{lct}_\Omega$. C cannot fit before either task ends, so C ends after all of $\Omega$.
A and B need all of $[0, 5)$, so C starts at 5 or later.
A (start 0–3, duration 2): compulsory part empty. B (start 0–2, duration 3): compulsory $[2, 3)$. C: empty.
So timetable only knows time 2 is taken. C loses starts 1 and 2: C ≥ 3. (A loses starts 1 and 2 too.)
Edge-finding reasons about the total duration of a set of tasks inside a window, which no single time point shows. Here it moves C's earliest start from 3 to 5.
section 4
400 constraints, one question.
18 · catalogue
| constraint | means | filtering |
|---|---|---|
| element$(i, T, v)$ | $v = T[i]$ | GAC by supports, $O(|D_i|)$ |
| table$(x, \mathcal T)$ | $x \in \mathcal T$ | STR, compact tables, MDDs |
| gcc$(x, [l_a, u_a])$ | value $a$ used $l_a$..$u_a$ times | flow (Régin 1996), unit 14 |
| regular$(x, \mathcal A)$ | $x$ spells a word of automaton $\mathcal A$ | layered graph reachability (Pesant 2004) |
| circuit$(\text{succ})$ | successors form one Hamiltonian cycle | alldifferent + subtour pruning |
| cumulative / no-overlap | resource capacity | timetable, edge-finding, energy |
Each strong filter is an algorithm from Parts I–III wearing a CP interface: matching (alldifferent), flow (gcc), DP over an automaton (regular), shortest paths and assignment bounds (circuit, the TSP relaxations of unit 09). Global constraints are where the traditions first cooperate.
Beldiceanu, Carlsson & Rampon's Global Constraint Catalog lists 400+ constraints with semantics, decompositions and filtering algorithms.
18 · lab
uv run co test 18
CO_MINE=15,17 uv run co test 18 # on your own matching and engine
uv run co then 18 # node counts, a named Hall set, CP-SAT's globals
18 · checkpoint
Régin, AAAI 1994.
van Hoeve, "The alldifferent constraint: a survey" (2001).
Baptiste, Le Pape & Nuijten, Constraint-Based Scheduling, ch. 2–3.
Global Constraint Catalog (sofdem.github.io/gccat).
19 search: heuristics, restarts, LNS on job-shop · 21 these propagators, explaining themselves.