Satisfiability and SAT Solvers CS 270 Math Foundations
Satisfiability and SAT Solvers CS 270 Math Foundations of CS Jeremy Johnson
Conjunctive Normal Form s x 0 x 1 f 0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 1 2
Conversion to CNF Define CNF(expr) Input: expr is a Boolean Expression in NNF Output: an equivalent Boolean Expression in CNF Conjunction of clauses (disjunction of literals) Algorithm is analogous (dual) to DNF. Instead of distributing and over or, distribute or over and
Distribute Or over And 1. E (F 1 F 2) º (E F 1) (E F 2) E F 1 F 2 2. (E 1 E 2) F º (E 1 F) (E 2 F) E F 1 E F 2
Satisfiability v A formula is satisfiable if there is an assignment to the variables that make the formula true v A formula is unsatisfiable if all assignments to variables eval to false v A formula is falsifiable if there is an assignment to the variables that make the formula false v A formula is valid if all assignments to variables eval to true (a valid formula is a theorem or tautology)
Satisfiability v Checking to see if a formula f is satisfiable can be done by searching a truth table for a true entry v Exponential in the number of variables v Does not appear to be a polynomial time algorithm (satisfiability is NP-complete) v There are efficient satisfiability checkers that work well on many practical problems v Checking whether f is satisfiable can be done by checking if f is not valid v An assignment that evaluates to false provides a counter example to validity
DNF vs CNF v It is easy to determine if a boolean expression in DNF is satisfiable but difficult to determine if it is valid v It is easy to determine if a boolean expression in CNF is valid but difficult to determine if it is satisfiable v It is possible to convert any boolean expression to DNF or CNF; however, there can be exponential blowup
Exponential Blowup v Converting the following expression shows that an exponential increase in the size of the DNF form of a boolean expression is possible v (x 1 y 1) (xn yn) v (x 1 xn) (y 1 yn)
Exponential Blowup v (x 1 y 1) (x 2 y 2) v ((x 1 y 1) x 2) ((x 1 y 1) y 2) v (x 1 x 2) (y 1 x 2) (x 1 y 2) (y 1 y 2)
Exponential Blowup v (x 1 y 1) (x 2 y 2) (x 3 y 3) v (((x 1 y 1) (x 2 y 2)) x 3 ) v (((x 1 y 1) (x 2 y 2)) y 3 ) v ((x 1 x 2) (y 1 x 2) (x 1 y 2) (y 1 y 2)) x 3 v ((x 1 x 2) (y 1 x 2) (x 1 y 2) (y 1 y 2)) y 3 v (x 1 x 2 x 3 ) (y 1 x 2 x 3 ) (x 1 y 2 x 3 ) (y 1 y 2 x 3 ) v (x 1 x 2 y 3 ) (y 1 x 2 y 3 ) (x 1 y 2 y 3 ) (y 1 y 2 y 3)
SAT Solvers v Input expected in CNF v Using DIMACS format v One clause per line delimited by 0 v Variables encoded by integers, not variable encoded by negating integer v We will use Mini. SAT (minisat. se)
Mini. SAT Example v (x 1 | -x 5 | x 4) & (-x 1 | x 5 | x 3 | x 4) & (-x 3 | x 4). v DIMACS format v (c = comment, “p cnf” = SAT problem in CNF) c SAT problem in CNF with 5 variables and 3 clauses p cnf 5 3 1 -5 4 0 -1 5 3 4 0 -3 -4 0
Mini. SAT Example v (x 1 | -x 5 | x 4) & (-x 1 | x 5 | x 3 | x 4) & (-x 3 | x 4). This is Mini. Sat 2. 0 beta ==============[ Problem Statistics ]========= | | | Number of variables: 5 | | Number of clauses: 3 | | Parsing time: 0. 00 s | …. SATISFIABLE v -1 -2 -3 -4 -5 0
Avionics Application v Aircraft controlled by (real time) software applications (navigation, control, obstacle detection, obstacle avoidance …) v Applications run on computers in different cabinets v 500 apps v 20 cabinets v Apps 1, 2 and 3 must run in separate cabinets v Problem: Find assignment of apps to cabinets that satisfies constraints
Corresponding SAT problem
Constaints in CNF
DIMACS Format
Avionics Example
Avionics Example p cnf 50 25 c clauses for valid map forall a exists c AC^c_a 1 2 3 4 5 0 6 7 8 9 10 0 11 12 13 14 15 0 16 17 18 19 20 0 21 22 23 24 25 0 26 27 28 29 30 0 31 32 33 34 35 0 36 37 38 39 40 0 41 42 43 44 45 0 46 47 48 49 50 0
Avionics Example c constaints ~AC^c_1 + ~AC^c_2 and ~AC^c_1 + ~AC^c_3 -1 -6 0 -1 -11 0 -2 -7 0 -2 -12 0 -3 -8 0 -3 -13 0 -4 -9 0 -4 -14 0 -5 -10 0 -5 -15 0 c constraint ~AC^c_2 + ~AC^c_3 -6 -11 0 -7 -12 0 -8 -13 0 -9 -14 0 -15 0
Avionics Example [jjohnson@tux 64 -12 Programs]$. /Mini. Sat_v 1. 14_linux aircraft assignment =================[MINISAT]================== | Conflicts | ORIGINAL | LEARNT | Progress | | | Clauses Literals | Limit Clauses Literals Lit/Cl | | ======================================= | 0 | 25 80 | 8 0 0 nan | 0. 000 % | ======================================= restarts : 1 conflicts : 0 (nan /sec) decisions : 39 (inf /sec) propagations : 50 (inf /sec) conflict literals : 0 ( nan % deleted) Memory used : 1. 67 MB CPU time : 0 s SATISFIABLE
Avionics Assignment SAT -1 -2 3 -4 -5 -6 7 -8 -9 -10 11 -12 -13 -14 -15 16 -17 -18 -19 -20 21 -22 -23 -24 -25 26 -27 -28 -29 -30 31 -32 -33 -34 -35 36 -37 -38 -39 -40 41 -42 -43 -44 -45 46 -47 -48 -49 -50 0 True indicator variables: 3 = 5*0 + 3 => AC(1, 3) 7 = 5*1 + 2 => AC(2, 2) 11 = 5*2 + 1 => AC(3, 1) 16 = 5*3+1 => AC(4, 1) 21 = 5*4+1 => AC(5, 1) 26 = 5*5=1 => AC(6, 1) 31 = 5*6+1 => AC(7, 1) 36 = 5*7+1 => AC(8, 1) 41 = 5*8 + 1 => AC(9, 1) 46 = 5*9+1 => AC(10, 1)
DPLL Algorithm v Tries to incrementally build a satisfying assignment A: V {T, F} (partial assignment) for a formula in CNF v A is grown by either v Deducing a truth value for a literal v Whenever all literals except one are F then the remaining literal must be T (unit propagation) v Guessing a truth value v Backtrack when guess (leads to inconsistency) is wrong
DPLL Example Operation Assign Formula
DPLL Example Operation Deduce Assign 1 Formula
DPLL Example Operation Deduce Assign 1 Formula
DPLL Example Operation Deduce Guess Assign 1 Formula
DPLL Example Operation Deduce Assign Formula 1 Deduce Guess Deduce Inconsistency
DPLL Example Operation Deduce 1 Assign Formula 1 Guess 3 Deduce 4 Undo 3 Backtrack
DPLL Example Operation Deduce 1 Assign Formula 1 Guess 3 Deduce 4 Undo 3 Assignment found
- Slides: 30