15
Towards an Optimal CNF Encoding of Boolean Cardinality Constraints Carsten Sinz Institute for Formal Models and Verification Johannes Kepler University Linz Linz, Austria

Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

Towards an Optimal CNF Encodingof Boolean Cardinality Constraints

Carsten SinzInstitute for Formal Models and Verification

Johannes Kepler University LinzLinz, Austria

Page 2: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

1

Boolean Cardinality Constraints Number restrictions: ”at most“, ”at least“ Notation:

: at most k true : at least k true

Examples:!

" k(x1,...,x

n)

!

" k(x1,...,x

n)

!

" 3(x,y,z) = x # y # z

!

"1(x,y,z) = ¬(x # y)#¬(x # z)#¬(y # z)

!

= (¬x"¬y)# (¬x"¬z)# (¬y"¬z)

Page 3: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

2

Why Translate CardinalityConstraints to CNF? Cardinality constraints occur frequently in

practice: product configuration, (frequency) assignment

problems, discrete tomography,... SAT-Solvers (typically) can handle formulae in

CNF only SAT-Solving has seen tremendous progress

over the last years Many high-performance implementations of

SAT-Solvers are available

Page 4: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

3

Standard (Naïve) Encoding is translated to

This results in clauses of length k+1.Worst case ( ): , i.e. exponential number of clauses

!

" k(x1,...,x

n)

!

"M #{1,...,n}|M |= k+1

$i%M

¬xi.

!

n

k +1

"

# $

%

& '

!

k = n /2" #+1

!

O(2n/ n /2)

Page 5: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

4

Encoding Example:≤1(x1,...,x100)Naïve Encoding:

!

(¬x1"¬x2)# (¬x1"¬x3)# (¬x1"¬x4 )# (¬x1"¬x5)#

(¬x1"¬x5)#L# (¬x98 "¬x99)# (¬x98 "¬x100)# (¬x99 "¬x100)

100

2

$

%

& & &

'

(

) ) ) = 4950 clauses

1 2 4 4 4 4 4 4 4 4 4 4 4 3 4 4 4 4 4 4 4 4 4 4 4

New Encoding 1 (LTSEQ): 296 clauses

New Encoding 2 (LTPAR): 669 clauses

[ ≤10(x1,...,x1000): 312176429322332191039274595287040000000 / 20969 / 6950 ]

Page 6: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

5

New Encodings:Based on Hardware Counters

General approach: counting and comparing

counter(unary or binary,sequential or parallel)

comparator

Page 7: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

6

Classification of Counters Unary: (intermediate) results are represented as

unary numbers (e.g., 5 ≅ |||||) Binary: (intermediate) results are represented

as binary numbes (e.g. 5 ≅ 101) Sequential: inputs are summed up one after the

other Parallel: inputs are summed up concurrently

Page 8: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

7

Encoding 1 (LTSEQ):Sequential Unary Counter

si,j: j-th digit of i-th partial sumvi: overflow bit for k-th partial sum

Page 9: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

8

Encoding 1:Conversion to CNF

2nk + n - 3k - 1 clausesk(n-1) auxiliary (encoding) variables

Page 10: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

9

Encoding 2 (LTPAR):Parallel Binary Counter

[Muller & Preparata,1975]

∑n: parallel counter summing up n inputsAi: 1-bit-(full-)adders

(only counter; binary comparator circuit not shown)

Page 11: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

10

Encoding 2:Conversion to CNF

Comparator circuit (recursive def.):

Counter circuit (full adders, half adders not shown):

(km...k0): binary representation of limit value k⊗: clause distribution (A⊗B := {x∪y | x∈A, y∈B } for clause sets A, B)

Page 12: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

11

Encoding requires: full adders, at most half adders, and at most clauses for the comparator.This results in

clauses for the parallel binary counter circuit and

!

n " logn# $"1

!

logn" #

Encoding 2:Conversion to CNF (cont’d)

!

7 n " logn# $"1( ) + 3 logn# $+ logn# $+1!

logn" #+1

!

= 7n " 3 logn# $" 6

!

2n " 2 additional encoding variables.

Page 13: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

12

Comparing Sizes ofDifferent Encodings

[3] Bauilleux, O. and Boufkhad, Y.: Efficient CNF Encoding of BooleanCardinality Constraints, CP’2003

[4] Warners, J.P.: A Linear-Time Transformation of Linear Inequalitiesinto Conjunctive Normal Form. Inf. Proc. Lett. 68 (1998)

Page 14: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

13

Availability & Future Work Generators for both Encodings (in C++)

are available fromhttp://www-sr.informatik.uni-tuebingen.de/

~sinz/CardConstraints

To Do: Experimental evaluation Compare different encodings w.r.t. practical

applicability

Page 15: Towards an Optimal CNF Encoding of Boolean Cardinality ... · CP2005.ppt Author: Carsten Sinz Created Date: 12/19/2005 4:34:27 AM

14

Conclusion Two new clausal encodings for Boolean

cardinality constraints:1. Encoding 1 [seq./unary]: Good for small

values of k, decided by unit propagation.2. Encoding 2 [par./binary]: Encoding with

least known number of clauses. Further (theoretical) result: no encoding

with fewer than n clauses possible.