540 likes | 634 Views
Programming with Boolean Satisfaction Michael Codish Department of Computer Science Ben Gurion University Beer- Sheva , Israel CP meets CAV - 2012. Joint work with: Vitaly Lagoon, Amit Metodi & Peter Stuckey . I. Its all about solving hard problems.
E N D
Programming with Boolean SatisfactionMichael CodishDepartment of Computer Science Ben Gurion UniversityBeer-Sheva , IsraelCP meets CAV - 2012 Joint work with: Vitaly Lagoon, AmitMetodi& Peter Stuckey
I. Its all about solving hard problems
Solving hard problems(Programming) Theory tells us Problem (hard) • Look for approximations • Look for easier sub-classes direct Practice tells us • Apply heuristics • Try to be clever Solution Theory also tells us • It is all equivalent to SAT
Solving hard problemsvia SAT encodings Problem (hard) CNF encoding direct sat solving hype! Solution SAT ’ing Assignment decoding
Solving hard problemsvia SAT encodings Improved techniques CNF Problem (hard) SAT solvers are getting stronger by the day encoding direct sat solving hype! Solution SAT ’ingAssignm. Emerging tools like “Sugar”, “Bee”, andothers decoding Many success stories
Example: encoding Sudoku cells rows columns boxes “unit clauses” At least = cell (i,j) contains value k At most
Example: solving Sudoku SAT Solver solution
We Can Solve Also More Interesting Problems But, there are also less interesting problems that we cannot solve Eternity II:2 million $ prize unclaimed 17 challenge:$ prize unclaimed 3 months ago ! (Steinbach & Posthoff)
We will always have the phase transition How hard interesting problem instances Problem size We seek better encodings so that our preferred problem instances will be solvable
Solving hard problemsvia SAT encodings tedious; often repetitive; generating millions of clauses This was a great talk…. CNF Problem (hard) encoding “and i have someconclusions” (a few years ago) direct sat solving I have been doing this for the past few years hype! Solution SAT ’ingAssignm. decoding Me:primarily for applications of termination analysis
II. Programming with Boolean Satisfaction (CP meets CAV 2012) CNF Problem (hard) encoding direct sat solving hype! Solution SAT ’ingAssignm. decoding
II. Programming with Boolean Satisfaction mer CNF Problem (hard) encoding Q. What makes a program work better? higher-level languages (optimizing) compilers & tools (p.e.) (what costs) Data Structures / algorithms (understanding it) hardware
Q. What makes a program work better? • SAT encoding mer unit propagation /arc consistency default value (1 or 0) clause / variable ordering Choice of SAT solver • SAT solver hardware
Q. What makes a program work better? • SAT encoding mer higher-level languages • SAT encoding compilers & tools (p.e.) • representation • & modeling Data Structures / algorithms • SAT solver hardware
Outline • Introduction: • Solving hard problems via SAT • Focus on programming with SAT • The need for higher-level languages • Higher low-level Language • (the basics for) A Compiler to CNF • Example: Model Based Diagnosis • Representing Finite Domain Integers • Example: Magic Labels • Conclusion
higher-level language ? Problem (hard) CNF encoding Problem (hard) Constraint Model CNF encoding modeling
higher-level language Finite Domain & Boolean Constraints Subset of FlatZinc The language The compiler Problem (hard) Constraint Model CNF encoding modeling
Example: encoding Sudoku Problem (hard) Constraint Model CNF encoding modeling
user compiler Problem (hard) Constraint Model CNF encoding modeling The CNF per constraint is small & gives context for the bits (word-level) The CNF is large & we have no context for the bits (bit-level)
user compiler Problem (hard) Constraint Model CNF encoding modeling simplification Tools such: SatELite, ReVivAl Based on Unit Propagation and Resolution. remove redundant variable X if the CNF implies X=Y, X= -Y, X=0, X=1 smaller CNF CryptoMiniSAT tries to add “xor clauses”
user compiler Problem (hard) Constraint Model CNF encoding modeling simplification apply constraint simplification (partial evaluation smaller CNF encoding remove redundant variable X if the Constraint implies X=Y, X= -Y, X=0, X=1 smaller Constraint Model even smaller CNF bit-level techniques
Equi-propagation is the process ofinferring equations implied by a “few” constraints. Constraint Model such x can be removed from all constraints. simplification of the form X=L where L is a constant or a literal: X=Y, X= -Y, X=0, X=1 smaller Constraint Model Implemented: complete / adhoc equi-propagation
constraint simplification is word-level (looking at the bits) Constraint ( C2, φ2 ) Constraint ( C3, φ3 ) Constraint ( Cn, φn ) Constraint ( C1, φ1 ) … M = Simplify Boolean techniques (equi-propagation) CSP techniques (partial evaluation) Constraint ( C1, φ1 ) Constraint ( C2, φ2 ) Constraint ( C’3, φ‘3 ) Constraint ( C’n, φ’n) M’ = …
Equi-propagation for Optimized SAT Encoding; • AmitMetodi, Michael Codish, Vitaly Lagoon • and Peter Stuckey; CP 2011
Outline • Introduction: • Solving hard problems via SAT • Focus on programming with SAT • The need for higher-level languages • Higher low-level Language • (the basics for) A Compiler to CNF • Example: Model Based Diagnosis • Representing Finite Domain Integers • Example: Magic Labels • Conclusion
Example:Model Based Diagnosis Observation Full Adder 1 A Z1 D 0 B 0 C 1 Z3 0 E Z2 1 Diagnoses: min-cardinality
Modeling MBD: introduce health variables 1 A Z1 X1 0 D B 0 X2 H1 H2 1 C Z3 A2 0 E H4 O1 Z2 A1 H5 H3 H minimize -H sum( [ -H1, -H2, -H3, -H4, -H5 ] ) ≤ K
Modeling MBD: introduce health variables 1 A Z1 X1 0 D B 0 X2 H1 H2 1 C Z3 A2 0 E H4 O1 Z2 A1 H5 H3 green means “healthy” minimize sum( [ -H1, -H2, -H3, -H4, -H5 ] ) ≤ 1 encoding to SAT isstraighforward Not competitive with other MBD tools standard: Smith 2005
Simplify the encoding 1 A Z1 X1 0 D B 0 X2 H1 H2 1 C Z3 A2 0 E H4 O1 Z2 A1 H5 H3 equi-propagation Z2=-H3 partial evaluation 1 1 1 A1 -H3 0 Z2 0 0 0 H3 -H3 gray means "melted”
Simplify the encoding - I 1 A H1 X1 0 D B 0 X2 H1 H2 1 C Z3 A2 0 E H4 O1 -H3 A1 H5 H3 equi-propagation Z2=-H partial evaluation 1 1 1 A1 -H3 0 Z2 0 0 0 H3 -H3 gray means "melted”
Simplify the encoding - I 1 A H1 X1 0 D B 0 X2 H1 H2 1 C Z3 A2 0 E H4 O1 -H3 A1 H5 H3 equi-propagation Z2=-H partial evaluation 1 1 1 A1 -H3 0 Z2 0 0 0 H3 -H3 gray means "melted”
Simplify the encoding - II 1 A H1 X1 0 D B 0 X2 H1 H2 1 C Z3 A2 0 E H4 O1 -H3 A1 H5 H3 a cone dominator claim: A minimal cardinality diagnosis will always indicate at most one unhealthy gate per “cone”. And wlog it is the “dominator”
Simplify the encoding - II 1 A H1 X1 0 D B 0 X2 H1 H2 1 C Z3 A2 0 E H4 O1 -H3=0 A1 H5 H3 green means “healthy” sum( [ -H1, -H2, 0, 0, -H5 ] ) ≤ K
Simplify the encoding - II 1 A H1 X1 H1=H2 0 D B 0 X2 H1 H2 1 C H1 H1=-H5 A2 0 E H4 O1 -H3=0 A1 H5 H3 No SAT solving; Diagnostics (min-cardinality) found by: preprocessing(cones) partial evaluation equi-propagation sum( [ -H1, -H2, -H5 ] ) ≤ K minimize K H1 =1 sum( [ -H1, -H2, H1 ] ) ≤ K sum( [ -H1, -H1, H1 ] ) ≤ K
Compiling Model-Based Diagnosis to Boolean Satisfaction; • AmitMetodi, Roni Stern, Meir Kalech, • Michael Codish; AAAI 2012 (to appear) • very good experimental results. • overtakes all current MBD systems • finds (for the first time) minimal cardinality diagnosis for the entire standard benchmarks
Outline • Introduction: • Solving hard problems via SAT • Focus on programming with SAT • The need for higher-level languages • Higher low-level Language • (the basics for) A Compiler to CNF • Example: Model Based Diagnosis • Representing Finite Domain Integers • Example: Magic Labels • Conclusion
small Modeling Finite Domain CSP representing numbers (integers) Order encoding xi ↔ (X ≥ i) (X = 3) = [1,1,1,0,0] Binary Unary integer variable X with domain {0,…,d} is represented in bits integer variable X with domain {0,…,d} is represented in bits Direct encoding encode “ordered” encode “exactly-one” xi ↔ (X = i) (X = 3) = [0,0,0,1,0,0]
Why Order Encoding ? • good for representing ranges (Sugar) X 1 0 X ≥ i X < j i j b=c e=f=g a b d c e f g • good for arbitrary sets (Bee) X v u i
Why Order Encoding ? • Lots of equi-propagation The Encoding to SAT needs NO Clauses. It is obtained by unification order encoding
Why Order Encoding ? • Lots of equi-propagation
Implementing Equi-propagation • Using BDD’s. • Can be prohibitive for global constraints. • Complete • Ad-Hoc rules (per constraint type) • Fast, precise in practice • Incomplete • Using SAT (on small groups of constraints) • Not too slow • Complete
Ben-Gurion • Equi-propagation • Encoder BEElanguage BEEcompiler Problem (hard) Constraint Model CNF encoding modeling
bit-blasting constraint simplification CNF Constraint Model encoding choice of representation (default is order encoding) Constraint ( C1, φ1 ) standard techniques (but encoding technique may differ after simplification) partial evaluation equi-propagation decomposition
Example: Magic Labels (VMTL) v4 v4 e34 8 v3 v3 e23 2 e13 3 v1 v1 v2 v2 e12 7 6 1 4 5
simplifying sum constraints bound propagation ? A & B take values {6,7,8} is it a CSP thing? no. it is equi-propagation
simplifying sum constraints e.p. p.e. e.p.
back to the VMTL example v4 v4 e34 8 v3 v3 e23 2 e13 3 v1 v1 v2 v2 e12 7 6 1 4 5
VMTL: Simplifying Constraints could take values 6,7,8 could take values 6,8
Example: Magic Labels (VMTL) 909 clauses 136 Bits 298 clauses 49 Bits
Graph Crossing BIBD MAS Kakuro BEE (BGU equi-propagation encoder) Protein folding N-Queens System Diagnostic Magic Square SCM / MCM QCP / Sudoku Nonograms