|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>
An environment in which one more agents act.
Note that an environment is parameterized on the particular type of agent it supports. This enables particular implementations to make richer assumptions about the capabilities of agents.
An environment should support the following general model:
initialize with a constructor, supplying any needed parameters
(a default constructor should be offered if at all possible)
Attach EnvironmentObservers, to update GUIs or trace output
(via attachEnvironmentListener)
See EnvironmentObserver for a fuller description of the type of events the environment is expected to generate for the observer.
Add additional agents and/or objects
(via addEnvironmentObject, addAgent. Note that at least one Counter should always be added. And of course it's not very interesting if you don't add any agents.)
Environment objects are JavaBeans, which allows the EnvironmentObservers to receive notifications of each change in their properties.
run()
which, in a general implementation, should
repeat executeStep
until isDone()
returns true
where executeStep
consists of:
dynamicChange()
, which changes zero or more objects spontaneouslyfor agent in agents:
p = perceptsForAgent(agent)
, which returns the set of percepts for the specified agent
given the current state of the objects.
action = agent.nextAction(p)
, which fetches the agent's chosen action
agentDrivenChange(agent,action)
, which changes zero or more objects
Method Summary | |
---|---|
void |
addAgent(A theAgent)
Adds an Agent to the environment. |
void |
addEnvironmentObject(EnvironmentObject theObject)
Adds an EnvironmentObject to the environment. |
void |
addEnvironmentObserver(EnvironmentObserver<K,P,A> theObserver)
Adds an EnvironmentObserver, which will be spun into a separate thread, and receive messages when events happen in the environment. |
void |
agentDrivenChange(A theAgent,
K theAction)
Changes the state of zero or more environment objects, given an agent and the action that the agent selected. |
void |
dynamicChange()
Considers the current state of the environmentObjects, and changes zero or more objects. |
void |
executeStep()
Performs one step of the simulated environment. |
java.util.Collection<A> |
getAgents()
Returns a collection of all agent objects, which is a (possibly empty) subset of the collection of all objects. |
Counter |
getCounter()
getCounter returns the environment's Counter object, which is included in the EnvironmentObjects collection. |
java.util.Collection<EnvironmentObject> |
getEnvironmentObjects()
Returns a collection of all environment objects. |
void |
initialSetup()
Performs any default initialization of the environment. |
boolean |
isDone()
Returns true when the environment state is done changing. |
java.util.Set<P> |
perceptsForAgent(A theAgent)
Returns a set (possibly empty) of percepts for the given agent. |
void |
run()
Repeatedly calls executeStep until isDone is true. |
void |
startingToRunSetup()
Performs initialization of agents, etc. |
Method Detail |
---|
boolean isDone()
java.util.Set<P> perceptsForAgent(A theAgent)
Note that in particular, percept might include the outcome of the agent's most recent action.
void addEnvironmentObject(EnvironmentObject theObject)
theObject
- the EnvironmentObject to addvoid addEnvironmentObserver(EnvironmentObserver<K,P,A> theObserver)
theObserver
- the EnvironmentObserver to add.void initialSetup()
This permits the environment itself to add a default set of objects, given parameters passed in the constructor. This step takes place *after* construction to permit EnvironmentObservers to be added before initialization.
void startingToRunSetup()
void addAgent(A theAgent)
void run()
void executeStep()
void dynamicChange()
void agentDrivenChange(A theAgent, K theAction)
theAgent
- the agent that just selected an actiontheAction
- the action selectedjava.util.Collection<EnvironmentObject> getEnvironmentObjects()
java.util.Collection<A> getAgents()
Counter getCounter()
getCounter returns the environment's Counter object, which is included in the EnvironmentObjects collection.
This method is for convenient access to the counter. Note that particular Counter implementations might support more state than just the counter
The Counter, unlike the agents, can simply be added via the #addEnvironmentObject method.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |