Inside CP-SAT: SAT Translation and CDCL

How CP-SAT translates finite-domain constraint problems into Boolean satisfiability (SAT) clauses, and how the underlying solver searches using Boolean Constraint Propagation (BCP) and Conflict-Driven Clause Learning (CDCL) with non-chronological backjumping.

Step 1 of 157%

Tutorial

Direct Encoding of CP Variables into SAT

CP-SAT solves a constraint problem by rewriting it as a set of Boolean clauses and passing the result to a SAT engine. The first step is replacing every finite-domain variable with a collection of Booleans.

The direct encoding of a CP variable xx with domain Dx={v1,v2,,vk}D_x = \{v_1, v_2, \ldots, v_k\} introduces kk Boolean variables

bx=v1,  bx=v2,  ,  bx=vk,b_{x=v_1},\; b_{x=v_2},\; \ldots,\; b_{x=v_k},

where bx=vib_{x=v_i} is true iff the CP variable xx takes the value viv_i.

Two families of clauses guarantee that xx takes exactly one value:

At-least-one (ALO): a single clause

bx=v1bx=v2bx=vk.b_{x=v_1} \lor b_{x=v_2} \lor \cdots \lor b_{x=v_k}.

At-most-one (AMO, pairwise): for every pair i<ji<j,

¬bx=vi¬bx=vj.\lnot b_{x=v_i} \lor \lnot b_{x=v_j}.

The AMO family contributes (k2)\binom{k}{2} clauses, one per pair of domain values.

Mini-example. For x{1,2}x \in \{1, 2\} we get k=2k=2 Booleans and 1+(22)=1+1=21 + \binom{2}{2} = 1 + 1 = 2 clauses:

bx=1bx=2,¬bx=1¬bx=2.b_{x=1} \lor b_{x=2}, \qquad \lnot b_{x=1} \lor \lnot b_{x=2}.
navigate · Enter open · Esc close · ⌘K/Ctrl K toggle