![]() |
Assignment 2 Due 5:00 PM, Thursday, Sept. 27th Department of Computer Science | ![]() |
tree-search as discussed in class.
Here is assign2-start.lisp, a lisp file
containing the tree-search code and an example
application on the shortest path problem from Graham's book.
When you load assign2-start.lisp you will see
CL-USER(163): :ld assign2-start ; Loading /s/parsons/e/fac/anderson/cs440/development/assign2-start.lisp Example map search. Map is ((A B C D Z) (B E F) (C G H) (D I J) (E K Z)) Path from A to Z is (A B E Z). Example robot searches. World is 5x5. Path from (1 1) to (4 4) is ((1 1) (1 2) (1 3) (1 4) (2 4) (3 4) (4 4)). Path from (3 2) to (1 4) is ((3 2) (3 3) (3 4) (2 4) (1 4)).
pathproblem4 by modify
pathproblem3 so that the shortest path is found. Explain
how you did this.
robot-xy-diagonal that does this. The
only change needed will be in the successors code. You
must generate successors in the order N, NE, E, SE, S, SW, W, then NW,
so that our automatic grading function will detect the correct answer.
robot-xy-commands by first copying robot-xy-diagonal
then modifying it so what it returns is not a list of locations, but a
list of directions: N, NE, E, SE, S, SW, W, or NW.
assign2-start.lisp file using the function names
specified above in each item, so make sure your lisp files runs the
tests correctly when we load your lisp file. We will also test your
functions with several other calls to your functions.
Now for the harder steps. You are going to solve a search problem
very much like Exercise 3.16 in our Russell & Norvig book for which
the next number in a sequence is predicted by searching for and
finding a mathematical expression that correctly generates the given
sequence. For example, the next number in the sequence 2, 4, 6 is 8.
An expression of the form that meets the specification in Exercise
3.16 is (+ (+ (+ 1 N) N) 1) . Your predict
function must return two values, using the values
function. Your result should look like this:
CL-USER(6): (predict '(2 4 6)) (LAMBDA (N) (IGNORE-ERRORS (+ (+ (+ 1 N) N) 1))) 8Details of this problem and clues to its solution will be discussed in class. Use the
tree-search function from above.
Warning: Do not try to predict anything to complex.
Your code will never stop. Don't forget to use control-C
control-C in emacs to terminate execution of your lisp
function.
Do and answer the following items.
all-ways-to-replace-atoms that returns a list of all
expressions possible from all allowed ways of replacing terms in a
given expression. For example,
CL-USER(66): (print (all-ways-to-replace-atoms '(- n 1))) ((- (+ N 1) 1) (- (+ N N) 1) (- (- N 1) 1) (- (- 1 N) 1) (- (- N N) 1) (- (- N N) 1) (- (* N N) 1) (- (/ 1 N) 1) (- (/ N N) 1) (- (/ N N) 1) (- (EXPT N N) 1) (- (EXPT N N) 1) (- N (+ 1 1)) (- N (+ 1 N)) (- N (- 1 1)) (- N (- 1 1)) (- N (- 1 N)) (- N (- N 1)) (- N (* 1 N)) (- N (/ 1 1)) (- N (/ 1 N)) (- N (/ N 1)) (- N (EXPT 1 N)) (- N (EXPT N 1)))
print was called to force lisp to print the entire list.
Ways to generate this will be discussed in class. You will be
calling this function from your successors code for this
problem.
You must generate the list of successors
in the same order as the example above shows so our automatic answer
checking function will detect the correct answer.
predict that solves the
prediction problem using a breadth-first search. predict
must return two values using the values function. The
first value must be the lambda function that is evaluated for a given
value of N to produce the corresponding value in the sequence. The
second value returned is the predicted next value in the sequence.
do-predict-problem that
calls predict and produces output exactly like this (and
returns nil):
CL-USER(69): (do-predict-problem '(2 4 6)) The next value in sequence (2 4 6) is 8 using function (LAMBDA (N) (IGNORE-ERRORS (+ (+ (+ 1 N) N) 1))) NIL
#| and following it with
|#
robot-xy-diagonal,
rerun the same search problems you had run before and compare your new
answers to your old ones. Are the resulting paths any different?
Why?
assignment2.lisp and electronically check it in
when you are ready.
We will be automatically checking the values returned by your
functions. The lisp code we
will use to do this is available
here and will produce the following output, assuming you have
already loaded your assignment2.lisp file.
The actual tests we perform will be different than the ones shown above.
CL-USER(101): :ld assign2-answer :ld assign2-answer ; Loading ; /s/bach/a/class/cs440/public_html/assignments-answers/assign2-answer.lisp CL-USER(102): :ld assign2-answer-checker ; Loading ; /s/bach/a/class/cs440/public_html/assignments-answers/assign2-answer-checker.lisp (PATHPROBLEM4 'A 'Z BIGMAP) evals to (A Z) ----------Problem 1 is Correct (ROBOT-XY-DIAGONAL '(3 2) '(1 4) 5) evals to ((3 2) (2 3) (1 4)) ----------Problem 2 is Correct (ROBOT-XY-COMMANDS '(3 1) '(1 4) 5) evals to (N NW NW) ----------Problem 3 is Correct (ALL-WAYS-TO-REPLACE-ATOMS 'A) evals to ((+ A 1) (+ A N) (- A 1) (- 1 A) (- A N) (- N A) (* A N) (/ 1 A) (/ A N) (/ N A) (EXPT A N) (EXPT N A)) ----------Problem 4A is Correct (ALL-WAYS-TO-REPLACE-ATOMS '(+ A B)) evals to ((+ (+ A 1) B) (+ (+ A N) B) (+ (- A 1) B) (+ (- 1 A) B) (+ (- A N) B) (+ (- N A) B) (+ (* A N) B) (+ (/ 1 A) B) (+ (/ A N) B) (+ (/ N A) B) (+ (EXPT A N) B) (+ (EXPT N A) B) (+ A (+ B 1)) (+ A (+ B N)) (+ A (- B 1)) (+ A (- 1 B)) (+ A (- B N)) (+ A (- N B)) (+ A (* B N)) (+ A (/ 1 B)) (+ A (/ B N)) (+ A (/ N B)) (+ A (EXPT B N)) (+ A (EXPT N B))) ----------Problem 4B is Correct (ALL-WAYS-TO-REPLACE-ATOMS '(- N 1)) evals to ((- (+ N 1) 1) (- (+ N N) 1) (- (- N 1) 1) (- (- 1 N) 1) (- (- N N) 1) (- (- N N) 1) (- (* N N) 1) (- (/ 1 N) 1) (- (/ N N) 1) (- (/ N N) 1) (- (EXPT N N) 1) (- (EXPT N N) 1) (- N (+ 1 1)) (- N (+ 1 N)) (- N (- 1 1)) (- N (- 1 1)) (- N (- 1 N)) (- N (- N 1)) (- N (* 1 N)) (- N (/ 1 1)) (- N (/ 1 N)) (- N (/ N 1)) (- N (EXPT 1 N)) (- N (EXPT N 1))) ----------Problem 4C is Correct (SECOND (LIST (LAMBDA (N) (IGNORE-ERRORS (+ 1 N))) 4)) evals to 4 ----------Problem 5 is Correct Problem 6.: The next value in sequence (2 3 4) is 5 using function (LAMBDA (N) (IGNORE-ERRORS (+ (+ 1 N) 1))) CL-USER(103):The
all-ways-to-replace-atoms in Problems 4a and 4b is
called with arguments that will not appear in your predictions
problems. They are included here just to clearly demonstrate the
order in which expressions should be generated by your code.