In addition to the assignments, this section has links to excerpts of code, documentation, and downloads used to complete the assignments.
- Homework 1a
- Homework 1b
- Homework 1c
- Homework 2a
- Homework 3 (PDF)
- Homework 3 Solutions (PDF)
In addition to the assignments, this section has links to excerpts of code, documentation, and downloads used to complete the assignments.
One major challenge in logic-based AI is the difficulty of solving the satisfiability problem (usually referred to as SAT). For this assignment, we will ask you to implement two different SAT solvers, commonly known as DPLL and WALKSAT, run your solvers on some test programs, and analyze the performance of the algorithms.
SAT instances are simply statements in propositional logic, written in conjunctive normal form (CNF). CNF sentences consist of variables, literals, and clauses. In the grammar for this assignment, a variable is a single, case-sensitive character (e.g. “Q”) and a literal is a variable or its negation (“Q” or “~Q”). In a CNF sentence, a clause consists of a disjunction of literals (“Z v ~B v X”). A sentence is a conjunction of clauses, for example:
(A v C v ~B) ^ (Z) ^ (~E v X v Y v W)
A satisfying assignment to a SAT instance is an assignment of truth values to variables that makes the CNF sentence true. If such assignment exists for a SAT instance, we say that the SAT instance is satisfiable. The problem of determining whether or not a particular SAT instance is satisfiable is NP-complete and thus cannot generally be solved efficiently. For a sentence of n variables, it will take O(2_n_) operations to discover an assignment in the worst case - equivalent to checking every possible assignment. Many interesting AI problems are NP-complete or harder, which leads us to consider approximate methods of solution, or exact methods that have good average case running times.
Reading: Russell & Norvig, Chapters 4,6 (Search, Propositional Logic)
We will be providing some handy Java® classes that you can use for this assignment. We have tested it with the Java 1.3 JVM, though it should work on any Java 2 JVM (Java 1.2 and higher). We will be distributing compiled classes and source file packaged as a JAR (Java ARchive) file, as well as posting the Javadoc documentation for the classes. You should not need to look at the source to use the classes, but you can expand the jar file if you need it.
The jar file for this assignment is PL.jar, which contains a package for parsing and representing sentences of propositional logic in CNF. The documentation for these classes is also available. You will need to include this JAR file in your CLASSPATH, and you will probably want to import the package with the statement import techniques.PL.*; before the class definitions.
To parse a String or a File, use the parse methods of techniques.PL.CNF. The parser will only parse CNF sentences, so be sure you are entering them correctly.
To generate a random 3-SAT instance, you can either call CNF.randInstance() or use the CNF.main() method via the command-line.
If you are new to Java, it might be useful to look at the Java® Resources page before you get too involved with your coding. You are, of course, free to use another programming language. If you are not using Java, you will need to create a your own internal representation for a CNF boolean sentence. You will need to parse the CNF sentences given in our format, as well as create a CNF sentence generator for the experiment detailed below.
For this assignment, we present the following SAT instances in text files. Your code should be able to solve these in reasonable time.
Debugging Cases:
Test Cases:
Davis, Putnam, Logemann and Loveland (DPLL)
This algorithm is popularly known as DPLL and is one of the most widely used methods of solving satisfiability problems exactly. By “exactly” we mean that DPLL is guaranteed either to find a satisfying assignment if one exists or terminate and report that none exists. Therefore, it still runs in exponential time in the worse case.
Reading: Cook and Mitchell, “Finding Hard Instances of the Satisfiability Problem: A Survey.”
The crucial sections of this paper are 1-2.1, which explain notation and the DPLL algorithm. Also read Section 3 closely, it discusses the mathematical properties that distinguish hard SAT problems from easy ones.
GSAT & WALKSAT
GSAT and WALKSAT are stochastic algorithms. In order to speed up the search for a true assignment, they pick random locations in the space of possible assignments and make limited, local searches from those locations. As a result, they might be able to find a solution to a problem that would take too long to solve using DPLL’s complete, global search. But because they do not cover the entire search space, there is no guarantee that GSAT or WALKSAT will find a solution to every problem, even if one exists. Therefore, these algorithms can never determine if a sentence is unsatisfiable. Algorithms are frequently categorized as sound or complete. A sound algorithm guarantees that any answer it returns is correct, but does not necessarily return an answer to every problem. A complete algorithm, on the other hand, will always return an answer. DPLL is complete and sound, while GSAT and WALKSAT are sound, but not complete.
Optional Reading: Selman and Kautz, “Domain-Independent Extensions to GSAT: Solving Large Structured Satisfiability Problems.”
Optional Reading: Selman, Kautz, and Cohen, “Local Search Strategies for Satisfiability Testing.”
The WALKSAT algorithm evolved from the GSAT algorithm. The first paper has an early exploration of some extensions to GSAT, including “GSAT with Random Walk.” The second paper has the actual WALKSAT algorithm, and a brief explanation of its development.
For each algorithm, turn in the following:
Note:
**Bonus Challenge:**Who couldn’t get no satisfaction?
You may work in teams of two, handing in a single write-up.
(10/3) A new JAR file has been posted. The only difference is that it includes a class
techniques.solvers.DPLL
that you can use as your SAT solver (though you are encouraged to use your own from part a). This jarfile supercedes the previous one and you should remove
PL.jar
from your
CLASSPATH
.
(10/2) Converting from a first-order logic sentence to our FOL grammar (clarification of Figure 3)
first-order logic: Ax, y. foo(x) -> bar(y) v Ez. ~equals(x,z)
our FOL grammar format:
all x all y foo(x) -> bar(y) v exists z ~Equals(x,z)
Important Clarifications:
you should create an axiom that defines what it means to be a well-connected set of rails (i.e., that it’s possible to move from each rail to each other rail)
then, having asserted well-connectedness, list the actual assignment returned for the “connects” relation: this relation represents the track layout found by your SAT solver.
Answers to Some Common Questions:
“Deadlocked” refers to the whole situation: a situation is deadlocked if both trains can not move. If at least one train has a move available, then we do not consider that situation to be deadlocked.
Your solution to the deadlock questions cannot involve:
changing the non-determinism of the world dynamics. a question was asked if it was ok for each train to have a plan of action, and to broadcast that plan. that makes the dynamics deterministic, and it would mean the other trains would know what to avoid. this is not really the spirit of the question, since it’s not allowable to have…
knowledge about the next situation (i.e. “peeking” into the future). your solutions must involve only what is known about the _current_ situation. try to think about whether an additional relation on the trains would “break symmetry” in a way that avoids deadlock.
removing the “Safe"ness of the situations S1 and S2.
Running out of memory:
you may have gotten “out of memory” errors during the process of changing the FOL sentence into a CNF sentence. this is not a bug in the code, and it’s probably not the ‘fault’ of any individual axiom in your FOL sentence. it’s just the nature of exponential growth: converting a sentence from FOL to PL and then to CNF grows exponentially bad with the number of propositions. exponential growth is bad news; if you didn’t believe that before, you should now!
that said, it _is_ possible to do the assignment within the standard memory constraints of the JVM (128 MB). if you are running out of memory, try looking at the following things in your set of axioms:
do you have any axioms that are redundant, or duplicating the work of other axioms? some people made their definition of “legal” to do the work of both “legal” and of enforcing the world dynamics. a little parsimony goes a long way.
do you have statements that say something like “all s” when simply instantiating the statement for S1 would do?
do you have any axioms left over from previous questions in the assignment that are no longer needed?
there is really no guaranteed method for avoiding memory problems; if you have trouble with it, you’ll just need to play around with your sentences until they get small enough.
Please note that the axioms you come up with should assume as little as possible about the arrangement of rails or number of trains; they should be generally applicable to any world with any number of trains and rails. One of the grading criteria will be the generality of your axioms.
zChaff
zChaff is a very efficient implementation of the complete SAT solver, Chaff. zChaff takes sentences in CNF form and produces an assignment, if one exists.
More information about zChaff can be found at the zChaff homepage.
Information on the standard DIMACS CNF format can be found here. Here is ;one example ;of a CNF sentence in the DIMACS format, and here is ;another example.
To get zChaff, download one of the following files:
Instructions | Tested On | |
zChaff binary for Linux |
|
RedHat Linux 6.2, Debian GNU/Linux 2.4.9, Mandrake 8.0 |
zChaff binary for Solaris |
|
Athena |
zChaff C++ source code |
|
Compiles and runs on Debian GNU/Linux 2.4.9 and Mandrake 8.0, but not on RedHat 6.2. Requires libstdc++-libc6.1-2.so.3 |
What remains is to turn sentences in our CNF format into DIMACS format, and to turn zChaff’s assignments into Interpretations for the original sentences.
We have written routines to do the two conversions as part of the ; techniques.PL.CNF class.
Here is how you can use the routines:
In your program, convert the CNF sentence into a DIMACS-format sentence, and record the mapping of CNF variable names to DIMACS variable names:
At the command line (or with a system call), run zChaff on the DIMACS file
mysentence.dimacs >! mysentence.zchaff
In your program, convert the zChaff output into an Interpretation for the original CNF sentence. ;Note that the Interpretation will be null
if zChaff did not find an assignment.
About the jarfile:
The jarfile contains both compiled classes and source files. To use it, you can either put it in your class path and type java RRPC.Checker
. Or, on MacOS X and Windows with JDK you can just double-click the jarfile and the checker will launch.
If you are saving/loading the proofs as you work on them, you should be sure to Output Proof the proof as well as saving them. Output Proof will write the proof in a human-readable format.
About blocks.txt:
The file has been updated to correct the swapped arguments in the
clear
axiom. (This bug should not have actually affected your ability to do the proof, but it’s fixed now.)
There were two versions of the “on” predicate: one with two arguments, and one with three. (This meant that you could not use resolution on the two different versions. However, it really didn’t cause any problems because you did not need to do resolution across the two different versions to do the proof.) This has now been corrected.
The extra credit version, blocks_extracredit.txt, has only one version of “on”: the three argument version. It also contains a different version of the “move” axiom, with an additional predicate.
Your proofs, using the Output Proof command
For each proof, please also:
Provide a brief (not more than a paragraph) proof sketch
Point out any key resolution steps in your proof
For the extra credit, in addition the proof, explain why the solution depends on having an axiom that explicitly mentions
clear(x)
after moving
x
(even though the solution to question 3 didn’t depend on such a thing).
In this project, you will implement Bayes net learning. That is, you will write a program that will read in some data and come up with a Bayesian network that best matches the data. Reading and understanding Nilsson’s Chapter 20, section 1 is necessary for doing this assignment.
This assignment is broken up into parts that will take you step-by-step through building a program for Bayes net learning.
Please read through this whole assignment and make sure you understand everything you’re asked to do. Then, design and implement a data structure for a Bayes net, taking into account what you’ll have to do with the data structure.
In this part, you are given the structure of a network and need to compute the conditional probability tables (CPTs). For this assignment, we will assume that there is no missing data, so this is just a matter of counting. For parts 1 and 2, simply use the raw counts (just as Nilsson does).
Your Tasks:
Pretend that you have the network already defined for you. That is, you already know the network structure and the conditional probability tables. How would you know whether it is a good network? This first part is about computing the score of a given network so that you can compare different networks.
We can compute the score of a network in any way we want, but a good scoring metric would take into account two things: (1) probability of the data given the network; (2) complexity of the network. For part 2, please use the scoring metric in Nilsson’s chapter.
Your Tasks:
Now you have the tools for searching through the space of network structures. However, like many other search problems, exhaustive search through the space of all possible network structures is not practical. In Part 4, you will need to implement some kind of greedy search, and as you should know by now, if you are not doing exhaustive search, your result will depend on how you choose the starting point. So in this part, you will think about how to choose an initial network. Possible candidates for an initial network are:
Note that any network you choose (here and also throughout your search) cannot have directed cycles. Also note, from this point on, you may use bayesian correction if your network has some probability 0 events.
Your Tasks:
Given the initial network in Part 3, implement a local greedy search to find a locally optimal network. (as described in Nilsson’s Chapter).
Your Tasks:
In this part, you will do two experiments: one with Part 2, and another with either Part 3 or Part 4.
Your Tasks: