180 likes | 511 Views
Perfect Hashing and CNF Encodings of Cardinality Constraints. Yael Ben-Haim Alexander Ivrii Oded Margalit Arie Matsliah SAT 2012. IBM Research - Haifa. Talk outline. Introduction to cardinality constraints and their encodings. Definition of perfect hash families.
E N D
Perfect Hashing and CNF Encodings of Cardinality Constraints Yael Ben-Haim Alexander Ivrii Oded Margalit Arie Matsliah SAT 2012 IBM Research - Haifa
Talk outline • Introduction to cardinality constraints and their encodings. • Definition of perfect hash families. • New encodings for the “at most k” constraint based on perfect hash families • An encoding that preserves arc consistency under unit propagation. • A “hybrid” encoding that partially preserves arc consistency under unit propagation. • Encoding the “at least k” constraint.
Cardinality constraints • Let be Boolean variables. • A cardinality constraint is of the form“at most / at least / exactly k out of are TRUE”, i.e., in the at most case: • Cardinality constraints are common in many problems • In constraint programming. • In formal verification. • MAXSAT and other optimization problems.
Cardinality constraints (cont.) • Handling of cardinality constraints • Treat them as linear inequalities or Pseudo-Boolean constraints. • Enhance a SAT solver. • Encode to CNF and run with a regular SAT solver.
Definition of encoding • A CNF encoding of a cardinality constraint is a formula F on the variables and the auxiliary variables such that: • SAT before remains SAT after:Every assignment to with at most k TRUEs,can be extended to an assignment on that satisfies F. • UNSAT before remains UNSAT after:for any assignment to with more than k TRUEs,there is no extension to such that F is satisfied.
Properties of efficient encodings • An efficient encoding encodes problems with cardinality constraints to CNF formulas that can be quickly solved by a SAT solver. • Typically, an efficient encoding has the following properties: • Few clauses. • Few auxiliary variables. • If a partial assignment on assigns TRUE to exactly k variables, then unit propagation assigns FALSE to all other Xs. In this case, we say that the encoding preserves arc consistency under unit propagation.
Example: the naïve encoding • The naïve encoding of the constraint : • Properties: • clauses. • 0 auxiliary variables. • Arc consistency is preserved under unit propagation.
Known and new encodings • An encoding that does not preserve arc consistency under unit propagation • Parallel counter [Sin05] • An encoding that partially preserves arc consistency under unit propagation • Hybrid PHF – new • Encodings that preserve arc consistency under unit propagation • Naïve • Sequential counter [Sin05] • Cardinality networks [ANOR09] • PHF – new
Perfect hashing • Perfect hash families are known and well studied combinatorial structures. • A handful of applications • Database management. • Group testing algorithms. • Cryptography: secret sharing, key distribution patterns. • We will use PHFs as ingredients of our encodings.
An (n,l,r,m) perfect hash family is a collection of functions Each function maps to such that (9,3,3,4) for every subset S of , of size ,there is a function such that
Encodings based on perfect hash families • Task: encode the constraint • Ingredient: an (n,k+1,r,m) perfect hash family • Encoding steps: after the example.
Encodings based on perfect hash families • Assuming that we have an (n,l=k+1,r,m) perfect hash family • Encoding steps: for each • Introduce r auxiliary variables • Add clauses for all • Encode the constraint using the sequential counter encoding. • A reduction • From one cardinality constraint on n variables • To a set of implication clausesand several cardinality constraints on r variables
Encodings based on perfect hash families • It remains to choose the underlying perfect hash family. • A handful of constructions, striving to minimize m (the number of hash functions) • Random and explicit. • For various ranges of the parameters. • Related to error correcting codes, combinatorial designs, Latin squares and orthogonal arrays, and more. • For , random constructions yield perfect hash families with
Known and new encodings • An encoding that does not preserve arc consistency under unit propagation • Parallel counter [Sin05] • An encoding that partially preserves arc consistency under unit propagation • Hybrid PHF – new • Encodings that preserve arc consistency under unit propagation • Naïve • Sequential counter [Sin05] • Cardinality networks [ANOR09] • PHF – new
Hybrid encodings • Ingredient: a collection of m hash functions not necessarily forming a perfect hash family. • Encoding steps • Encode to CNF using some encoding. AND IN ADDITION • Follow the same encoding steps as for perfect hash families: introduce auxiliary variables, add implication clauses, encode m “at most k constraints” on r variables. • For a choice of a nearly perfect hash family, we obtain a nearly perfect consistency preservation: for most of k-triplets of Xs, if a partial assignment sets them to TRUE then unit propagation will assign FALSE to all other Xs.
At least constraints • Our encodings (as well as others) are designed to be efficient when k is small relative to n. • An approach saying that the “at least k constraint” is equivalent to the “at most n-k constraint” will not work for small k. • We designed a sequential counter encoding for the “at least k constraint” with clauses and auxiliary variables. • We designed a PHF encoding for the “at least k constraint” with clauses and auxiliary variables. • Number of clauses is small but their length is not constant.
Summary • Our contribution • A new encoding of cardinality constraints to CNF based on perfect hash families. • A new hybrid encoding. • Similar encodings for the “at least k constraint”. • Empirical results. • Take home message • Use combinatorial structures (e.g. block designs or error-correcting codes) as building blocks in encodings of constraints to CNF.