CSCE476/876: Homework 3  (HW3)

Search and Constraint Satisfaction
Assigned:    Wednesday, Feb 9, 2000.
Due dates:   Problems 1--5:  Wednesday, Feb 9, 2000 at the beginning of the class.
                      Problems 6--10: Wednesday, Feb 9, 2000, before 6:00 p.m.
Note:            As much as possible,  please indicate how much time you spend on each problem.



Problems 1 to 5 are paper-and-pencil must be turned in at the beginning of the class.
Problems 6 to 10 are programming exercises and should be turned in using the handin program.
(10 points) Problem 1:  Basic Search Strategies 
(10 points) Problem 2: Search
(10 points) Problem 3: Search
(20 points) Problem 4: Constraint Satisfaction
(20 points) Problem 5: Constraint Satisfaction
(6 Points each) Problem 6 to 10:  Lisp

 
Problem 1:  Basic Search Strategies

Assume you have the following search space.
 
STATE NEXT-STATE COST
A B 4
A C 1
B D 3
B E 8
C C 0
C D 2
C F 6
D C 2
D E 4
E G 2
F G 8
 

Task 1: Draw this search space as a directed graph (i.e., states are nodes and actions are directed arcs, labeled with their costs).

Task 2:  For each of the following, during each cycle of the search algorithm: report which node is expanded, and the content of the queue. Also report the solution path found.

The START STATE is A and the GOAL STATE is G. When multiple nodes tie for their position in OPEN, they should appear in alphabetical order: e.g., after the first cycle of breadth-first search, OPEN should equal {B, C}.
 
Problem 2: AIMA 3.9.

Problem 3: AIMA 3.11 (in pseudo code).

Problem 4:  Constraint Satisfaction (Courtesy of Djamila-Haroud, Swiss Federal Institute of Technology)
Three employees in a small company, Alice, Rob and Ian must contact their respective customers as quickly as possible.  The company has one telephone, one fax and one computer (for email), with independent lines.  Alice needs to contact two customers: one who only has a telephone and the second one has both a telephone and a fax.  Rob must contact a customer who has also has a telephone and a fax.  Ian's customer can be reached by fax or by computer.  Suppose that Alice contacts her customers the one after the other while, during the same time,  Rob and Ian are communicating with their customers.

Problem 5:  Constraint Satisfaction
In class (Jan 26) we have seen how arc-consistency can be applied to binary constraints to reduce the search space.
Task 1: Given a CSP with n variables, each with a domain of size d, and e binary constraints.  What is the worst-case time complexity of arc-consistency?
Task 2:  Suppose now that constraints in our problem are ternary constraints.  Write, in pseudo-code the arc-consistency algorithm and give its worst-case time complexity.
 

SIMPLE LISP PROGRAMMING
(Courtesy of Boi Faltings, Swiss Federal Institute of Technology)
 
Problem 6:  nested fences let
Task 1: Write the function extremities that returns the first and last elements of a list given as argument. Use let to define 2 local variables for the first and respectively the last elements of the list. Hint: use the predefined LISP function last (what is the result returned but this function?).

Task 2: Write a second function  extremities2 that returns the same result without using let.

Problem 7: conditional instruction cond
COND can be thought as a generalization of a sequence of the IF.. THEN.. ELSE statements: CONS allows us to express a set of alternatives

Task 1: Write a function traffic-light to represent the behavior of a driver.  The function takes two arguments: the first one is the state of the traffic light (red, yellow, green) and the second parameter is a Boolean stating whether there is a camera or not at the traffic light (common in Europe!).  This function must return the atom:

WARNING: traffic-light  must not use or.

Task 2:  Write a second function traffic-light-or using or.
 
Problem 8: list processing using dolist
Write a function count-elements that takes two arguments: a list of numbers and a number (bound) and that returns a list of two numbers: the first of which is the number of elements in the list that are strictly less than the bound and the second the number of elements greater than or equal to the bound.  Scroll through the list using dolist.
Hint: use let to store intermediate results.
 
Problem 9: conditional instructions with when et unless
The goal is to write a function that returns the list of squares of the elements of a list given as argument without using  any loops.
Task 1: Write a recursive function list-squarres-unless using unless to test if the end of the list has been reached.
Task 2: Write a second recursive functions list-squares-when using  when to test if the end of the list has been reached
Hint: use cons in both cases.
 
Problem 10: general loop instruction do
Although there is a LISP function to compute exponential  (i.e., expt), you are asked to write a function  my-expt that computes exponential given a number and a positive integer exponent, using the lisp loop construct: do.

Example:
(my-expt 2 4)
-> 16