Programming with Boolean Satisfaction Michael Codish Department of - - PowerPoint PPT Presentation

programming with boolean satisfaction michael codish
SMART_READER_LITE
LIVE PREVIEW

Programming with Boolean Satisfaction Michael Codish Department of - - PowerPoint PPT Presentation

Programming with Boolean Satisfaction Michael Codish Department of Computer Science Ben Gurion University Beer-Sheva , Israel Joint work with: Vitaly Lagoon, Amit Metodi & Peter Stuckey CP meets CAV - 2012 I. Its all about solving hard


slide-1
SLIDE 1

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
slide-2
SLIDE 2

Its all about solving hard problems

I.

slide-3
SLIDE 3

Solving hard problems

(Programming)

Problem

(hard)

Solution

direct

  • Look for approximations
  • Look for easier sub-classes
  • Apply heuristics
  • Try to be clever

Theory tells us Practice tells us Theory also tells us

  • It is all equivalent to SAT
slide-4
SLIDE 4

Solving hard problems via SAT encodings

Problem

(hard)

Solution

direct

CNF SAT ’ing Assignment

encoding decoding sat solving

hype!

slide-5
SLIDE 5

Solving hard problems via SAT encodings

Problem (hard) Solution direct CNF SAT ’ing Assignm. encoding decoding sat solving

SAT solvers are getting stronger by the day

Improved techniques Many success stories

Emerging tools like “Sugar”, “Bee”, and

  • thers

hype!

slide-6
SLIDE 6

Example: encoding Sudoku

= cell (i,j)

contains value k

cells rows columns boxes “unit clauses”

At least At most

slide-7
SLIDE 7

Example: solving Sudoku

SAT Solver

solution

slide-8
SLIDE 8

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)

slide-9
SLIDE 9

We will always have the phase transition

How hard Problem size

We seek better encodings so that our preferred problem instances will be solvable

interesting problem instances

slide-10
SLIDE 10

Solving hard problems via SAT encodings

Problem (hard) Solution direct CNF SAT ’ing Assignm. encoding decoding sat solving

hype! This was a great talk…. (a few years ago) I have been doing this for the past few years Me: primarily for applications

  • f termination analysis

“and i have some conclusions”

tedious; often repetitive; generating millions of clauses

slide-11
SLIDE 11 Problem (hard) Solution direct CNF SAT ’ing Assignm. encoding decoding sat solving

hype! Programming with Boolean Satisfaction (CP meets CAV 2012)

II.

slide-12
SLIDE 12 Problem (hard) CNF encoding

Programming with Boolean Satisfaction

II.

  • Q. What makes a

program work better?

higher-level languages Data Structures / algorithms compilers & tools (p.e.) hardware

slide-13
SLIDE 13
  • Q. What makes a

program work better?

hardware

unit propagation /arc consistency default value (1 or 0) clause / variable ordering Choice of SAT solver

slide-14
SLIDE 14
  • Q. What makes a

program work better?

Data Structures / algorithms hardware compilers & tools (p.e.)

higher-level languages

slide-15
SLIDE 15

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
slide-16
SLIDE 16

Problem

(hard)

CNF

encoding

higher-level language ?

Problem

(hard)

CNF

encoding

Constraint Model

modeling

slide-17
SLIDE 17

higher-level language

Problem

(hard)

CNF

encoding

Constraint Model

modeling

Finite Domain & Boolean Constraints The compiler Subset of FlatZinc

slide-18
SLIDE 18

Example: encoding Sudoku

Problem

(hard)

CNF

encoding

Constraint Model

modeling

slide-19
SLIDE 19

Problem

(hard)

CNF

encoding

Constraint Model

modeling user compiler The CNF is large & we have no context for the bits (bit-level) The CNF per constraint is small & gives context for the bits (word-level)

slide-20
SLIDE 20

Problem

(hard)

CNF

encoding

Constraint Model

modeling user compiler

simplification smaller

CNF

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

CryptoMiniSAT tries to add “xor clauses”
slide-21
SLIDE 21

Problem

(hard)

CNF

encoding

Constraint Model

modeling user compiler simplification

smaller

CNF

apply constraint simplification (partial evaluation 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

slide-22
SLIDE 22
  • f the form X=L where L

is a constant or a literal: X=Y, X= -Y, X=0, X=1

Constraint Model

simplification

smaller Constraint Model

Equi-propagation is the process

  • f inferring equations implied

by a “few” constraints.

Implemented: complete / adhoc equi-propagation

such x can be removed from all constraints.

slide-23
SLIDE 23

constraint simplification is word-level (looking at the bits)

Constraint ( C1, φ1 )

M =

Constraint ( C1, φ1 ) Constraint ( C’3, φ‘3 ) Constraint ( C’n, φ’n )

M’ =

Simplify CSP techniques (partial evaluation) Boolean techniques (equi-propagation)

Constraint ( C2, φ2 ) Constraint ( C3, φ3 ) Constraint ( Cn, φn ) Constraint ( C2, φ2 )

slide-24
SLIDE 24

Equi-propagation for Optimized SAT Encoding;

Amit Metodi, Michael Codish, Vitaly Lagoon and Peter Stuckey; CP 2011

slide-25
SLIDE 25

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
slide-26
SLIDE 26

1 Diagnoses: A B C D E

Z1 Z2 Z3

1 1

Full Adder

Example: Model Based Diagnosis

min-cardinality
slide-27
SLIDE 27

1 A B C D E

X1 X2 A2 A1 O1 Z1 Z2 Z3

1

Modeling MBD: introduce health variables

H1 H2 H3 H4 H5

sum( [ -H1, -H2, -H3, -H4, -H5 ] ) ≤ K

H
  • H
slide-28
SLIDE 28

1 A B C D E

X1 X2 A2 A1 O1 Z1 Z2 Z3

1

Modeling MBD: introduce health variables

H1 H2 H3 H4 H5

sum( [ -H1, -H2, -H3, -H4, -H5 ] ) ≤ 1

green means “healthy”

encoding to SAT is straighforward standard: Smith 2005 Not competitive with other MBD tools

slide-29
SLIDE 29

1 A B C D E

X1 X2 A2 A1 O1 Z1 Z2 Z3

1

Simplify the encoding

H1 H2 H3 H4 H5 H3 1 1 1
  • H3

gray means "melted”

Z2

partial evaluation equi-propagation Z2=-H3

A1
  • H3
slide-30
SLIDE 30

1 A B C D E

X1 X2 A2 A1 O1 Z3

1

Simplify the encoding - I

H1 H2 H3 H4 H5 H3 1 1 1
  • H3

gray means "melted”

Z2

partial evaluation equi-propagation Z2=-H

A1
  • H3
  • H3
H1
slide-31
SLIDE 31

1 A B C D E

X1 X2 A2 A1 O1 Z3

1

Simplify the encoding - I

H1 H2 H3 H4 H5 H3 1 1 1
  • H3

gray means "melted”

Z2

partial evaluation equi-propagation Z2=-H

A1
  • H3
  • H3
H1
slide-32
SLIDE 32

1 A B C D E

X1 X2 A2 A1 O1 Z3

1

Simplify the encoding - II

H1 H2 H3 H4 H5
  • H3
H1

claim: A minimal cardinality diagnosis will always indicate at most one unhealthy gate per “cone”. And wlog it is the “dominator”

dominator

slide-33
SLIDE 33

1 A B C D E

X1 X2 A2 A1 O1 Z3

1

Simplify the encoding - II

H1 H2 H3 H4 H5
  • H3=0
H1

green means “healthy”

sum( [ -H1, -H2, 0, 0, -H5 ] ) ≤ K

slide-34
SLIDE 34

1 A B C D E

X1 X2 A2 A1 O1

1

Simplify the encoding - II

H1 H2 H3 H4 H5
  • H3=0
H1

sum( [ -H1, -H2, -H5 ] ) ≤ K

H1 H1=-H5

sum( [ -H1, -H2, H1 ] ) ≤ K

H1=H2

sum( [ -H1, -H1, H1 ] ) ≤ K

No SAT solving; Diagnostics (min-cardinality) found by: preprocessing(cones) partial evaluation equi-propagation

slide-35
SLIDE 35

Compiling Model-Based Diagnosis to Boolean Satisfaction;

Amit Metodi, Roni Stern, Meir Kalech, Michael Codish; AAAI 2012 (to appear)

very good experimental results.

  • vertakes all current MBD systems

finds (for the first time) minimal cardinality diagnosis for the entire standard benchmarks

slide-36
SLIDE 36

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
slide-37
SLIDE 37

Modeling Finite Domain CSP

representing numbers (integers) Binary Unary Order encoding

xi ↔ (X ≥ i) (X = 3) = [1,1,1,0,0]

Direct encoding

xi ↔ (X = i) (X = 3) = [0,0,0,1,0,0] integer variable X with domain {0,…,d} is represented in bits integer variable X with domain {0,…,d} is represented in bits

slide-38
SLIDE 38

Why Order Encoding ? X

i j X ≥ i X < j 1  good for representing ranges (Sugar)

X

u v

i  good for arbitrary sets (Bee) a b c d e f g

b=c e=f=g

slide-39
SLIDE 39
  • rder encoding

Why Order Encoding ?

 Lots of equi-propagation The Encoding to SAT needs NO

  • Clauses. It is obtained by unification
slide-40
SLIDE 40

Why Order Encoding ?

 Lots of equi-propagation

slide-41
SLIDE 41

Implementing Equi-propagation

1. Using BDD’s.

  • Can be prohibitive for global constraints.
  • Complete
  • 2. Ad-Hoc rules (per constraint type)
  • Fast, precise in practice
  • Incomplete
  • 3. Using SAT (on small groups of constraints)
  • Not too slow
  • Complete
slide-42
SLIDE 42

Ben-Gurion

Equi-propagation Encoder

Problem

(hard)

CNF

encoding

Constraint Model

modeling BEE compiler

slide-43
SLIDE 43

CNF Constraint Model

encoding bit-blasting constraint simplification

choice of representation

(default is order encoding)

Constraint ( C1, φ1 )

partial evaluation equi-propagation decomposition standard techniques (but encoding technique may differ after simplification)

slide-44
SLIDE 44

Example: Magic Labels (VMTL)

v1 v2 v3 v4 e12 e23 e13 e34 v1 v2 v3 v4 7 2 3 8 4 5 1 6

slide-45
SLIDE 45

simplifying sum constraints

bound propagation ?

A & B take values {6,7,8}

is it a CSP thing?

  • no. it is equi-propagation
slide-46
SLIDE 46

simplifying sum constraints

e.p. p.e.

e.p .
slide-47
SLIDE 47

back to the VMTL example

v1 v2 v3 v4 e12 e23 e13 e34 v1 v2 v3 v4 7 2 3 8 4 5 1 6

slide-48
SLIDE 48

could take values 6,8 could take values 6,7,8

VMTL: Simplifying Constraints

slide-49
SLIDE 49

Example: Magic Labels (VMTL)

909 clauses 136 Bits 298 clauses 49 Bits

slide-50
SLIDE 50 Kakuro QCP / Sudoku BIBD Nonograms Graph Crossing N-Queens Magic Square MAS SCM / MCM System Diagnostic Protein folding
slide-51
SLIDE 51

Compiling Finite Domain Constraints to SAT with Bee (tool paper & release);

Amit Metodi and Michael Codish; ICLP 2012

slide-52
SLIDE 52

Implementation

Currently we use CryptoMiniSAT (or MiniSAT) The compiler is written in Prolog (SWI) (equating Boolean variables using unification) SAT, BDD and Adhoc rules to implement E.P.

slide-53
SLIDE 53

Where now?

  • applications
  • implementation
  • complete equi-propagation (on chunks)
  • how to implement it
  • how to decide where to apply it
slide-54
SLIDE 54

Conclusions

New Emerging Paradigm where we program with SAT (or SMT) solvers; High”er-level (constraint based) language to aid in the encoding lets us focus on the modeling The notion of E.P. captures many standard CSP techniques and more. Making the CNF smaller is not the real goal; It is more about restricting the search space by identifying equalities that must hold