CS530 WalkSat Assignment (Due November 9, 1999)

  1. Implement the WalkSat algorithm. I recommend the following data structures to support efficient updating. Each clause and each variable is represented by an integer which is used to index various arrays.

    Your top-level function should be

    (defun walksat (clauses ntrials nflips)
      ...)
    
    It should accept input in the form
    (((not a) (not b)) (a b) (c (not d) e))
    
    which means there are three clauses:
    -a or -b
    a or b
    c or -d or e
    
    It should return a truth assignment in the form
    ((a . 0) (b . 1) (c . 1) (d . 0) (e . 0))
    

    CommonLisp supports arrays as follows:

    The syntax for multidimensional arrays is somewhat more complex (you won't need them for this assignment):

    ;; create a 10 by 20 by 10 array
    (setf *3da* (make-array '(10 20 10)
                            :element-type 'fixnum :initial-element 0))
    
    ;; access the element with indexes 0 5 1.
    (aref *3da* 0 5 1)
    ;; change its value
    (setf (aref *3da* 0 5 1) -10)
    
    ;; Code can be written to handle arrays with an unknown number of dimensions
    ;; Let a be an array with an unknown number of dimensions
    ;; Let indexes be a list with the appropriate number of indexes
    ;; To access an element:
    (apply #'aref a indexes)
    ;; To modify an element
    (setf (apply #'aref a indexes) -10)
    

  2. Reduce (i.e., convert) the map coloring problem into a SAT problem and solve it with WalkSat. (Explain your reduction and print out the SAT problem.) Show your solution.

  3. Generate some random 3SAT problems as follows. Let N be the number of variables and C be the number of clauses. It turns out that the ratio C/N determines the level of difficulty of the problems. For N fixed at 20, generate 50 random 3SAT problems for each value of C/N from 1 to 10 and compute the median execution time of these 50 problems. Plot the results. Use N as the value of NTrials and 5N as the value of NFlips.
Turn in your source listing and the answers to the problems.