|
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
-
Create your work directory for using GSAT.
-
Download hw4.tar from the class code
repository to your work directory.
-
From that same directory, enter the command: tar -xvf hw4.tar
(You may then remove hw4.tar if you wish.)
-
If "." is not in your environment path variable ("echo $path"
to check), you will need to type "./" before each command used.
Using GSAT
-
INPUT. At the start of execution, gsat asks the user for the following
information in the following order:
-
input filename (the knowledge base in CNF format which is described below),
-
assign filename (output file where satisfying truth assignments are given),
-
report filename (output file where execution statistics are reported),
-
limit on the number of variable assignment flips,
-
limit on the number of restarts, and
-
other options.
These are all explained in the GSAT_USERS_GUIDE
but you will likely want the defaults for most entries.
-
OUTPUT. When you run 'gsat', the last thing that the program
spits out at you will be whether or not it found a solution. If it
did, the output will be sent to the assign file you specify above.
The last expression in this file is a list of truth(1)/false(0) assignments
to your variables that is the same as the output from the script.
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:
-
number of variables,
-
number of clauses, and
-
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