Index of /~russell/aima-java/src/aima/agents

[ICO]NameLast modifiedSizeDescription

[PARENTDIR]Parent Directory   -  
[TXT]AIMA.class 2001-01-01 18:19 1.2K 
[TXT]AIMA.java 2001-01-01 18:19 797  
[TXT]Action.class 2001-01-01 18:19 257  
[TXT]Action.java 2001-01-01 18:19 305  
[TXT]Agent.class 2001-01-01 18:19 463  
[TXT]Agent.java 2001-01-01 18:19 413  
[TXT]AgentManager.class 2001-01-01 18:19 470  
[TXT]AgentManager.java 2001-01-01 18:19 446  
[TXT]AgentProgram.class 2001-01-01 18:19 252  
[TXT]AgentProgram.java 2001-01-01 18:19 165  
[TXT]AgentThing.class 2001-01-01 18:19 1.2K 
[TXT]AgentThing.java 2001-01-01 18:19 924  
[TXT]AnAction.class 2001-01-01 18:19 1.0K 
[TXT]AnAction.java 2001-01-01 18:19 532  
[TXT]Dirt.class 2001-01-01 18:19 241  
[   ]Dirt.java 2001-01-01 18:19 56  
[TXT]Environment.class 2001-01-01 18:19 2.8K 
[TXT]Environment.html 2001-01-01 18:19 145  
[TXT]Environment.java 2001-01-01 18:19 2.5K 
[TXT]Grid.html 2001-01-01 18:19 450  
[TXT]GridApplet$1.class 2001-01-01 18:19 1.3K 
[TXT]GridApplet.class 2001-01-01 18:19 1.7K 
[   ]GridApplet.java 2001-01-01 18:19 2.1K 
[TXT]GridComponent.class 2001-01-01 18:19 3.0K 
[TXT]GridComponent.java 2001-01-01 18:19 2.3K 
[TXT]GridDisplay.class 2001-01-01 18:19 3.4K 
[TXT]GridEnvironment.class 2001-01-01 18:19 5.2K 
[   ]GridEnvironment.java 2001-01-01 18:19 5.1K 
[TXT]GridFrame$1.class 2001-01-01 18:19 586  
[TXT]GridFrame$2.class 2001-01-01 18:19 693  
[TXT]GridFrame$3.class 2001-01-01 18:19 625  
[TXT]GridFrame$4.class 2001-01-01 18:19 666  
[TXT]GridFrame.class 2001-01-01 18:19 2.4K 
[TXT]GridFrame.java 2001-01-01 18:19 8.4K 
[TXT]Makefile 2001-01-01 18:19 1.4K 
[TXT]Obstacle.class 2001-01-01 18:19 180  
[   ]Obstacle.java 2001-01-01 18:19 50  
[   ]PACKAGE 2001-01-01 18:19 12  
[TXT]Percept.class 2001-01-01 18:19 178  
[TXT]Percept.java 2001-01-01 18:19 260  
[TXT]Thing.class 2001-01-01 18:19 1.5K 
[TXT]Thing.java 2001-01-01 18:19 913  
[TXT]UnaryPredicate.class 2001-01-01 18:19 234  
[   ]UnaryPredicate.java 2001-01-01 18:19 96  
[TXT]VacuumEnvironment$1...>2001-01-01 18:19 943  
[TXT]VacuumEnvironment.class2001-01-01 18:19 3.0K 
[TXT]VacuumEnvironment.java 2001-01-01 18:19 2.3K 
[TXT]VacuumPercept.class 2001-01-01 18:19 743  
[   ]VacuumPercept.java 2001-01-01 18:19 389  
[TXT]Wall.class 2001-01-01 18:19 269  
[   ]Wall.java 2001-01-01 18:19 76  
[TXT]tmp 2001-01-01 18:19 5.9K 

Package: aima.agent

The aima.agent package defines the basic environment simulator, along with agents and other things that exist in the environment, and a graphical user interface for visualizing the whole process. There are nine main classes defined here:

AgentActionEnvironment
AgentBodyPerceptEnvironmentGUI
AgentProgramEnvironmentEventEnvironmentEventAdapter

We will look at the classes one at a time. But first, let's take a peek at what you need to do to build two different things:

A New Environment:

You need to do the following:
  • If there are new Actions or Percepts, define subclasses for them. (For example, SuckAction in the VacuumEnvironment.)
  • If there are new kinds of Things (including AgentBody), define subclasses for them. (For example, Dirt.)
  • If there are new kinds of things that can happen, define the corresponding EventObjects, and define a EnvironmentEventAdapter.
  • Design the GUI to go with the Environment, if desired. Many of our environments can use the GridEnvironmentGUI as is.

A New Agent Program

Once the environment is in place, this is easy. Make a subclass of AgentProgram (either with an explicit class or an anonymous inner class), and supply an algorithm for computing an action to take. You can determine what actions are legal by looking at the EnvironmentAdapter for this environment. You can then test out your new agent program by calling Environment.run().

Now for the classes:

Class: Agent

The agent object contains two main things: the agent program and the agent body. These are kept as separate objects so that they will be easier to extend separately (you can have separate hierarchies of agent programs and agent bodies). The agent object itself then is mostly a bookkeeping object to hold the program, body, score, and various other things. You should concentrate on the program and the body.

Class: AgentBody

The agent body is a Thing, as is everything else in the environment. (Well, according to the book, we also might want Stuff in the environment. We'll worry about that later.) The agent body has no access to the agent or agent program; its purpose is to react to forces in the environment, and be displayed.

Class: AgentProgram

The agent program determines what the agent does: the program takes a percept and returns an action. AgentProgram is a subclass of JGL's UnaryFunction class. The only method is the execute method. The agent program has no access to the agent body or agent. It is important to keep separate the process of designing an environment from the process of designing an agent program to execute in that environment. The environment designer decides what Things (including agent bodies) are available, and how they interact. Given this, the agent program designer decides how to map from percepts to actions. In some cases, the constructor for a particular agent can create an anonymous inner class for the agent program.

Class: Percept

Percept is an abstract class with no methods or fields; it exists only to be subclassed. The idea is that this is what is available from the environment for the agent to "see".

Class: Action

I think this name is not taken. An action is a representation of what the agent intends to do; the environment will then decide what actually happens. (For example, I could return an action saying run forward at 200 MPH, but the environment would determine that I can't execute that action.) In any environment there will be a set of action classes that are legal; any other actions will be ignored (perhaps with a warning message). When the environment executes an action, it does two things: changes the environment to reflect the result of the action, and for each change, posts a EnvironmentEvent for the benefit of any listeners. Typically, there will be one listener, the EnvironmentGUI.

Class: Environment

The environment keeps track of all the Things in the world (including the agent bodies). The environment is also an event source in the 1.1 Event model. This means we have to do processEvent(new EnvironmentEvent()) whenever something happens. This is handled by ????.

Class: EnvironmentEvent

This a subclass of java.util.EventObject (or possibly java.AWT.AWTEvent). I'm not sure if we want to have subclasses of these, or if we just will have event ids to distinguish the, The two main types of events are ObjectChangedEvent (a wumpus dies, dirt is sucked up, etc.) and ObjectMovedEvent (the agent moves from [1,1] to [2,1]). Possibly also ObjectPickedUp, and ObjectDestroyed.

Class: EnvironmentGUI

The EnvironmentGUI is an event listener in the Java 1.1 Event model. So it needs to call addEnvironmentEventListener, and pass it a new EnvironmentEventAdapter with suitable methods filled in.