Satisfiability

This program generates random instances of the 3SAT problem for n variables which are then solved by exhaustive search. Please click on the number of variables you want to look at. Below will then occur some sample instances of the satisfiability problem including all assignments to the variables which satisfy them.

Tasks
The tasks are to increase the speed of the exhaustive search and to implement the resolution algoirhtm from the lecture.
  1. Optimization
    The current function "satisfyopt(n,clauseall,clauseneg)" is identical with the nonoptimized version. The variable "n" is the number of variables, the variables "clauseall" and "clauseneg" are arrays of numbers representing a clause. To understand the coding, one has to view upon the numbers in binary form and to write them from lower bits to higher bits instead of the usual way from higher bits to lower ones. Here an example stating that Clause[2] is not x[0] or x[3] or not x[4]:
      Variable    Decimal Number  Binary from low to high  Meaning: which variables
      clauseall[2]     25         10011000                 x[0], x[3], x[4] occur
      clauseneg[2]     17         10001000                 x[0], x[4] negated 
    In general, if the bit i is 1 in clauseall[j] then this means that x[i] occurs in the Clause[j]. Furthermore, if bit i is also set in clauseneg[j] then this means that not "x[i]" but its negation ("neg x[i]") occurs in Clause[j]. The implemented function downcounts a variable a in steps one from the starting solution to the last possible value which is 0. In the case that a clause is not satisfied, this downcounting might be speeded up and this might be an key idea to spead up the whole function. It might be useful to precompute some information before entering the loop as well in order to speed up the operations inside the loop. Having done this, the resulting function should perform well for 20 variables without a warning that a script causes the page to run slowly.

  2. Resolution
    The parameters for the function "resolve(n,clauseall,clauseneg)" are the same as in the previous function, so please refer to there for the these parameters and the coding. Furthermore, the algorithm is described in detail on Slide 28 of Lecture 7 (ps; pdf). As this algorithm is polynomial and not exponential for 2SAT, it should be able to handle quite large 2SAT instances fast. The return values of the function should be 0 if the set of clauses is not satisfiable, 1 if the set of clauses formula is satisfiable and 2 if the output of the function should be ignored since it is not yet ready for testing.
When editing the first function, it might be good to test it while editing so that changes to not make the function incorrect. This can be done by clicking the button "Testing Off" to get the value "Testing On" on the button and then to use the first three rows of small instances of 4 to 9 variables to test the function. It gives a notice when the number of solutions found does not coincide. Similarly one can test the implemented resolution algorithm. If the tests run fine, one can try to run the algorithm on the larger instances which can be started by clicking the buttons right to the "Testing Off"/"Testing On" button.


Testing can be made on and off by clicking the corresponding button below.