Search and Constraint Satisfaction
Assigned: Friday, Feb 11, 2000.
Due dates: WARNING 3 different deadlines.
-
Problems 1 & 2: Friday, Feb 18, 2000 at the beginning of the
class.
-
Problem 3 Tasks 1 and 2: Monday, Feb 21, 2000, before 6:00 p.m.
-
Problem 3 Tasks 3, 4, 5, 6 & 7 (grad only): Monday, February
28, 2000 before 6:00 p.m
Note: As much as possible, please indicate how much
time you spend on each problem.
Problems 1 & 2 are paper-and-pencil must be turned in at the beginning
of the class.
Problem 3 is a programming exercise and should be turned in using the
handin program.
(10 points) Problem 1: Search
(10 points) Problem 2: Admissible heuristic.
(80 points) Problem 3: N-queens in CL
Tasks 1, 2, 3, 4, 5, 6: Systematic search (80 points for undergrads,
40 points for grad students)
Task 7: Hill-climbing search (40 points homework bonus for undergrads,
40 points for grad students)
Problem 1: Search (from AIMA 4.1 with an extra question)
With g(n) being the path length,
-
suppose that we run a greedy search algorithm with h(n) =
- g(n). What sort of search will the greedy search emulate? Explain.
-
suppose that we run a search algorithm with h(n) = g(n).
What sort of search will the greedy search emulate? Explain.
Problem 2: AIMA 4.11a and 4.11b
Problem 3: LISP programming assignment.
The goal of this exercise is to implement a backtrack-search mechanism
in Common Lisp and test basic techniques of Constraint Satisfaction.
It consists of two parts: Tasks 1 to 6 are for both undergrad
and graduate students, and Task 7 is for graduate students only.
Undergraduate students are welcome to implement Task 7 and will receive
the credit as a bonus for the homework component of the final grading.
In this exercise, you need to implement various data structures in Common
Lisp for solving the n-queens problem and implement a backtrack depth-first
search that takes as input an integer n and solves the corresponding n-queens.
We are going to use the following formulation for the n-queens as a
CSP: the variables are the queens Q1, Q2, ..., Qn, one queen per
line of the chessboard. The domain of each variable is the set of n columns
in the line corresponding to the queen. For the queen k, this
set is {(k, 1), (k, 2,), (k, 3), ..., (k, n)}. Two queens attack
each other if they are in the same column, same line or same diagonal
The goal is to find a position for all queens such as queens do not attack
each other.
Tasks:
-
Implement depth-first search with backtracking and back-checking for finding
one solution.
-
Generate one solution for n=1, 3, 4, 5, and 8. Report the solution,
the number of nodes expanded and the number of constraint checks carried
out. A constraint check is counted one every time you check the consistency
of one variable's value against another one.
-
Implement an arc-consistency algorithm (choose AC-3 from Bartak's web page).
Run AC-3 on the 5 n-queen instances we have tested above (i.e.,
n = 1, 3, 4, 5, 8). Report whether or not values have been pruned
and, in any, the number of values pruned.
-
Implement a full look-ahead search mechanism by interleaving each
variable instantiation with consistency filtering carried over all
future variables. (Note: forward checking is a partial look-ahead
schema in which arc-consistency is not checked among all future
variables but only for a future variable against future variables
deeper in the tree.)
-
Generate one solution for n=1, 3, 4, 7, and 8. Report the solution,
the number of nodes expanded and the number of constraint checks carried
out.
-
Modify your final backtrack search to find all solutions.
Report the solutions, the number of nodes expanded and the number of constraint
checks carried out.
-
(AIMA 4.12, but only partially.) Solve the n-queens problem using hill
climbing and hill climbing with random start. Measure the search
cost and percentage of solved problems using randomly generated start states.
Below are some indications to guide you in this task:
-
Input: n, number of queens
-
Create a structure for storing the queens as variables. Use defclass
or defstruct. Each queen must have the following attributes: a unique
identifier generated using the Lisp function (gentemp "QUEEN-" );
a domain to store the set of values; and a current domain to store the
domain as it is being filtered and modified by the search and consistency
checking processes.
-
Write a function to generate the queens and their domains given the input.
-
Create a data structure for the nodes of the search tree with the following
attributes: a unique identifier generated using (gentemp "NODE-"
), a pointer to the CSP variable, an assigned value, a list of children
nodes (not needed really if you are going to find one solution, may be
useful while looping for all solutions, your choice).
-
Write a list function for checking whether two positions on the board (a,
b) and (c, d) threatens each other or not (the function threatens you saw
in HW2 is useful but has a bug, a little one.
-
Any time you backtrack, you need to restore the domains of the future variables
by using the unaltered domains stored in the structure of the CSP variable.
In full look-ahead, before you restart search (after the backtrack step)
you need to filter again the domains of all future variables by checking
against the past variables and by doing arc-consistency over all
future varaibles.
EMACS LISP common commands (this is not a an exhaustive list).
ESC-Control-q |
Indents correctly the lisp expression located at the cursor. |
ESC-Control-x |
Compile a lisp expression in an emacs buffer. |
Control-x Control-f |
Loads a file in an emacs buffer. (Use TAB or SPACE for completion.) |
Control-u Control-c Control-b |
Compiles all lisp expressions in a buffer. |
Control-g |
Breaks a command in emacs. |
Control-] |
Breaks a recursive-edit loop in emacs. |
Control-x Control-s |
Saves an emacs buffer into the corresponding file. |
Control-x k |
Kills an emacs buffer. |
Control-x control-k |
Lists all emacs buffers. |
Control-x 2 |
Horizontally splits an emacs buffer into two areas. |
Control-x 3 |
Vertically splits an emacs buffer into two areas. |
Control-x o |
Moves the cursor from one emacs buffer to another one. |
Control-x 1 |
Replaces currently displayed buffers by one buffer, the one where the
cursor is currently. |
Control-h a |
Help (apropos) for emacs commands. A buffer is displayed listing
all emacs commands containing the entered string. |
Control-h f |
Help (function) for arguments of an emacs function. |
Control-x Control-c |
To exit emacs. |
ESC-Control-f / ESC-Control-b |
Advances a full lisp expression / Goes back a full lisp expression. |
Control-c Control-p |
In a *common-lisp* buffer, brings back (recursively) the previously
evaluated lisp expression. |
Control-c Control-n |
Usually used during a sequence of `Control-c Control-p's.
In a *common-lisp* buffer, brings back (recursively) the next evaluated
lisp expression. |
Control-c ; |
Comments a selected region in a buffer containing a lisp file
(lisp comment mode) |
ESC-- Control-c ; |
Removes comments from the selected region (lisp comment mode) |
ESC-<spacebar> |
Eliminates extra empty space between two words (leaving just one space) |
Composer environment:
Step, trace, and inspect are functions of Common Lisp, and available
on any CL implementation. Check LWH: Chapter 10.
Composer is an enhanced environment for LISP code development that
comes with Allegro Common Lisp of Franz Inc. It has a window-based
inspector, debugger, on-line documentation, profiler, xreference, etc..
To load composer, when your ACL image contains composer, type in a
common-lisp buffer: (require 'composer).
Then type (composer:start-composer) (alternatively, you can start composer
from the menu buttons on top of your xemacs window.)
To inspect a variable var, you can type :wi var (this stands
for window inspect var).
To enter the debugger (once you are in a break loop because of the
some bug), you can type :wde, and a window will appear with the last
instructions.