On Agents
Using the AIMA Lisp Code
Objectives
- Run more complicated Lisp Code
- Create agents and run them in the vacuum-cleaner micro-environment.
Our AI text introduces the vacuum-cleaner micro-environment as follows:
- PERCEPTS: In the vacumm-cleaner world, each vacuum-cleaner agent
gets a three-element percept vector on each turn. The first element is a touch
sensor in front of the agent which is 1 when the vacuum-cleaner bumps into
something and NIL otherwise. The second is from a photosensor under the vacuum-cleaner
that is used to sense whether or not dirt is there, and the third is from
an infrared sensor that detects when the agent is in its home location.
- ACTIONS: In the vacumm-cleaner world, each vacuum-cleaner agent
may choose among five possible actions: go forward, turn right, turn left,
vacuum dirt, and turn off.
- GOALS: The goal for each vacumm-cleaner is to clean up and go
home. This is measured with the performance measure tha awards 100 points
for each piece of dirt vacuumed up, subtracts 1 point for each action, and
subtracts 1000 points if it is not in the home location when it turns itself
off.
- ENVIRONMENT: The vacumm-cleaner world consists of a grid of squares
some of which have obstacles such as walls, others have dirt, and still others
are open. In the display, "#" represents an obstacle such as a wall and "*"
represents dirt.
This assignment must be completed individually.
Your textbook authors have created agents, including the vacuum-cleaner
agent, that you can run based upon the examples given in the text. A great deal
of Lisp code is necessary to build up both the agent and the environment, so
we would like to download this code and set it up to run on each of our individual
computers.
- First, you will need to download the code from AIMA
Lisp Code.
- Then unzip these files into a folder on your hard drive.
- Edit the file "aima.lisp" and change the value of the parameter
*aima-root* on line 9 to reflect the location of the files. For a Windows
file system, we will have something like "c:\\aima\\". Note that
we have to use double backslashes, because backslashes are treated specially
in Common Lisp strings. Next copy this file into the program directory of
Allegro Lisp, so the Allegro Lisp interpreter can find the files you want.
- Next, start Allegro Lisp and enter the following into the command line:
(load "aima.lisp")
(aima-load 'name)
Note that you will get some error messages about certain built-in functions
being redefined. This is because these functions are desined to run in a variety
of Lisp environments, including older environments. You can treat these errors
as warnings and just push return at each of these messages. (Note: We should
be able to turn this flag off, but I haven't yet figured out how.)
- You should now be ready to run the agent simulations.
After loading all of the code,
try the following functions:
- (RUN-ENVIRONMENT (MAKE-VACUUM-WORLD :MAX-STEPS 10))
; Here you may vary or even omit the max-steps parameter.
; This run uses the default random-vacuum-agent who is
; a fairly stupid agent: ignoring its percept and choosing a random action.
; Note that the agent's perfomance is measured with the above perfomance measure.
- (RUN-ENVIRONMENT (MAKE-VACUUM-WORLD :CSPEC '((AT ALL (P 0.9 DIRT))) :MAX-STEPS
10))
; You can change the probability of dirt in each cell using
; the optional :CSPEC (Custom SPECification) keyword.
- (RUN-ENVIRONMENT (MAKE-VACUUM-WORLD :STREAM NIL :MAX-STEPS 100))
; The optional :STREAM parameter allows you to
; run the exact same code but does so without the display.
- (RUN-ENVIRONMENT (MAKE-VACUUM-WORLD :ASPEC '(REACTIVE-VACUUM-AGENT) :MAX-STEPS
40))
; The ASPEC (Agent SPECificaton) optional parameter changes which agent you
run.
; The REACTIVE-VACUUM-AGENT is a slightly smarter reactive agent.
- (AGENT-TRIALS 'MAKE-VACUUM-WORLD '(REACTIVE-VACUUM-AGENT RANDOM-VACUUM-AGENT)
:N 10)
; AGENT-TRIALS runs multiple agents together using the performance measure
given above. ; Try it several times to see how they do.
Next, look through the Lisp code files and see if you can find where:
- The default agent is defined.
- The environment is set-up.
- The performance measure is defined.