CS 327: Artificial Intelligence

Assignment: Vacuum World

Henry the vacuum I discovered Henry at  http://www.henryvac.co.uk/.

Overview

For this assignment, you will develop code for Vacuum-World. Vacuum-World is an environment where a vacuum cleaner agent moves around, vacuuming up pieces of dirt. I have provided the basic framework for Vacuum-World - you will enhance it and extend it.

Setting up

Whenever you start up CLISP to work on this assignment, you should always enter the following first:

(load "/Accounts/courses/cs327/aima/aima.lisp")

This loads the utilities that come with our textbook, Artificial Intelligence: A Modern Approach (AIMA).

Next, you should copy the Vacuum-World code into whichever directory you are doing your Lisp programming. Here is one example:

cp /Accounts/courses/cs327/vacuum/vacuum.lisp ~

The "~" is shorthand for your own home directory.

You can now further copy or modify this program at will.

Getting started

After setting up as above, load the Vacuum-World into CLISP by typing

(load "vacuum.lisp")

You can then run the environment by typing

(run-vacuum 5 7) ; Put whatever numbers here you like

where 5 is the size of the x-axis, and 7 is the size of the y-axis. (Try varying these). You should then see a diagram of Vacuum-World, with the agent indicated by an "A", and dirt indicated by "#". Every time you press the Enter key, the agent will suck up dirt if there is some in the current position, or move forward in the direction in which the agent points. Above the grid, the recent percept list and action taken are shown. The percept list contains three positions:

(bump-sensor dirt-sensor home-sensor)

bump-sensor is T if the agent has just bumped into a wall.
dirt-sensor is T if there is a piece of dirt underneath the agent.
home-sensor is T of the agent is in its home location (bottom left).

If you continue to press Enter, the agent will slide up the left hand side of the room, then back down the left side again until it reaches its home position again. For more information on Vacuum-World, checkout out Problems 2.7-2.12 on page 57 in your text - I've modelled this Vaccum-World closely after the ideas presented there. The performance measurement, for example, is the same as that contained in 2.9.

Your assignment

1. Copy the file "vacuum.lisp" to "vacuum_reflex.lisp". The function choose-action is mostly a simple reflex agent, but not quite. Why? Change the function choose-action so that it obtains a better performance measure, without adding any additional state storage. Why is it impossible, in general, to have a simple reflex agent that returns home when finished and shuts itself off? Is a simple reflex agent the most rational one that can be placed into this environment? Why or why not? Include in the header documentation for vacuum_reflex.lisp an overview description of how your agent approaches the problem, and what parts of code you modified. You should not change anything other than the choose-action function.

2. Can a simple reflex agent with a randomized agent function outperform a simple reflex agent? Describe circumstances where randomization would help improve the performance of your agent in part 1.

3. Copy the file "vacuum.lisp" to "vacuum_state.lisp". Again change the function choose-action (and other aspects of the Lisp code if necessary) to add some form of internal state to the agent so that it performs as close to perfectly rational as you can. You may not, however, change the parameters of choose-action to be anything other than the current percept. Giving the agent a birds-eye view, for example, is against the rules. It may not utilize any variables that exist in the external environment, such as (x,y) location or the like or size of the environment. It can build an internal view, however, based on what it has seen so far. Is the task environment:

Provide one sentence or so for each of the above justifying your answer. Include in the header documentation for vacuum_state.lisp an overview description of how your agent approaches the problem, and what parts of code you modified.

What to turn in

Turn in two Lisp files: vacuum_reflex.lisp, and vacuum_state.lisp. I should be able to test your code by starting CLISP and typing:

> (load "/Accounts/courses/cs327/aima/aima.lisp")

> (load "vacuum_reflex.lisp")  ; similarly with vacuum_state

> (run-vacuum 3 7)  ; or whatever values I choose

You should also turn in a flat file called vacuum.txt, which contains the answers to all questions asked above.

FAQs

Q: How do I get the program to not make me hit Enter after every move?
A: Comment out the function read-line inside the function display-environment.