CS 371
Introduction to Artificial Intelligence
GSAT Users Guide


GSAT is a blindingly fast program written by Bart Selman and Henry Kautz of AT&T Bell Labs for solving satisfiability problems in propositional logic.  It takes a sentence in conjunctive normal form (CNF) and tries to find a model that satisfies the sentence.  You get to use this program on your homework to both see automated logic in action and to save yourself from having to find a model by hand.

Installation

  1. Create your work directory for using GSAT.
  2. Download hw4.tar from the class code repository to your work directory.
  3. From that same directory, enter the command: tar -xvf hw4.tar  (You may then remove hw4.tar if you wish.)
  4. If "." is not in your environment path variable ("echo $path" to check), you will need to type "./" before each command used.

Using GSAT

Conjunctive Normal Form (CNF) Input Files

Before starting to write a CNF input file, it's helpful to see what one looks like.   To generate a random 3CNF input file test.cnf with 6 variables and 5 clauses, enter the command "makewff -cnf 3 100 400 > test.cnf".  Look at its contents with the command "more test.cnf".  You should see something of the form (with different numbers):

c seed= 2061313515
p cnf 5 6
3 -2 4 0
-1 -3 4 0
-1 3 -5 0
2 5 4 0
-1 5 3 0
2 4 -3 0

A line beginning with "c" is a comment.  A line beginning with "p" give important information to gsat: number of variables and number of clauses.  Each of the following lines is a clause.  Variables are represented as numbers 1 ... n. "0" denotes "end of clause".  "-" denotes a negative literal.  Thus, if we set A=1, B=2, etc., the file above represents the CNF formula

(C or not B or D) and (not A or not C or D) and (not A or C or not E) and (B or E or D) and (not A or E or C) and (B or D or not C)

To create your own input file, you can start by writing out your known formulas in a list (with logical "and" implicit between list entries).  At this stage it's probably easiest to use letters or words which easily correspond in your mind to the things they represent.  Then manipulate the symbols until they are in CNF form (e.g. using deMorgan's Law).  Then, replace numbers consistently for each symbol and make the syntactic adjustments necessary to have the clausal form shown above.  Finally, count variables and clauses and add the "p" line at the beginning of the file.  It's easy to make mistakes here, so it's important to save your work in stages to prevent having to redo things.

Note that this process can be automated.  You can write or use existing tools to do this translation if you wish, but this is not required or expected.

Using gtime

gtime is a script by Samar Mehta which takes as arguments:
  1. number of variables,
  2. number of clauses, and
  3. number of runs.
The script calls makewff to generate random problems and then calls gsat to solve them.  gtime then compiles and reports statistics from these runs.

(c) 2000 Todd Neller