SAT Search

PSU CS 441/541 Homework 2
Due before class Monday, October 16

In this assignment, you will construct a solver for Boolean Satisfiability problems using the Davis-Putnam algorithm. Recall from class that the Davis-Putnam algorithm is a simple depth-first search of the ``binding space'' of variables in a propositional logic formula.

Given a propositional logic formula in CNF, that is, a conjunction of disjunctive clauses such as

    (x or y or not z) and
    (not x or y or not z) and
    (not y or z) and
    (not x)
the Davis-Putnam algorithm finds a satisfying assignment, a binding of each variable in the formula to true or false, such that the whole formula is true. The algorithm proceeds as follows:
  1. If no variables are unbound:
    1. If the assignment is satisfying, return true.
    2. Return false.
  2. Select an unbound variable v.
  3. Bind v to true, then attempt to bind the remaining unbound variables by Davis-Putnam. If a satisfying assignment is found, return true.
  4. Bind v to false, then attempt to bind the remaining unbound variables by Davis-Putnam. If a satisfying assignment is found, return true.
  5. Return false.
(Recall that there is an obvious optimization: if any clause ever becomes unsatisfiable---all atoms are false---there is no point in continuing to bind variables.)

Your program may be written in the language of your choice. (Let me know if you're planning on something other than C, C++, or Java), but should compile and run on the department UNIX machines. The input to the program will be as follows:

  1. A line consisting of the letter "p", followed by the word "cnf", the number of variables and number of clauses.
  2. A line for each clause, consisting of the integer variable names of each variable in the clause. Negated atoms will be represented by negated integers.
For example, the example above might be encoded as
  p cnf 3 4
  1 2 -3
  -1 2 -3
  -2 3
  -1
If the input is unsatisfiable, the output will be a line of the form "s cnf 0" followed by the number of variables and number of clauses. Otherwise, the output will be a satisfying assignment, consisting of
  1. A line of the form "s cnf 1" followed by the number of variables and number of clauses
  2. A line for each variable name, with a minus in front of any variable whose binding is false.
For example, the previous input might yield an output of
  s cnf 1 3 4
  -1
  2
  3
Only one satisfying assignment should be produced. Note that this input/output format is the DIMACS CNF format described in detail in a DIMACS Satisfiability Suggested Format document. No more than 10000 clauses or variables need be accepted.

BONUS: Convert the formulae of your previous assignment to propositions in CNF, and then feed it to your solver. What do you get?

BONUS: What techniques can you use to speed up the solver?


Homework should be submitted by e-mail to <cs541@cs.pdx.edu>. The words "CS441/541 HW2" should appear somewhere in the subject line. The homework submission should be a computer program giving the requested input-to-output mapping. It will be manually scanned for readability and approach, then automatically graded by validating it against a set of reasonable test cases. Remember, if I can't understand your submission, I can't give you credit for it.