edu.columbia.cs.coms4701.agent.environments.simple
Class AbstractEnvironment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>

java.lang.Object
  extended by edu.columbia.cs.coms4701.agent.environments.simple.AbstractEnvironment<K,P,A>
All Implemented Interfaces:
Environment<K,P,A>
Direct Known Subclasses:
AbstractGridEnvironment

public abstract class AbstractEnvironment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>
extends java.lang.Object
implements Environment<K,P,A>

An abstract base Environment to take care of most of the dirty work.

Subclasses must implement:

and will probably want to implement:

Version:
0.1

User: aaron Date: Aug 23, 2006 Time: 6:00:10 PM

Author:
aaron@cs

Field Summary
protected  java.util.Collection<A> agents
           
protected  Counter counter
           
protected  java.util.Collection<EnvironmentObject> environmentObjects
           
protected  java.util.Collection<EnvironmentObserver<K,P,A>> environmentObservers
           
 
Constructor Summary
AbstractEnvironment()
           
 
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.
abstract  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()
          Default initialization.
 boolean isDone()
          Returns true when the environment state is done changing.
abstract  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()
          Default first-run initialization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

environmentObjects

protected java.util.Collection<EnvironmentObject> environmentObjects

agents

protected java.util.Collection<A extends Agent<K,P>> agents

counter

protected Counter counter

environmentObservers

protected java.util.Collection<EnvironmentObserver<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>> environmentObservers
Constructor Detail

AbstractEnvironment

public AbstractEnvironment()
Method Detail

isDone

public boolean isDone()
Returns true when the environment state is done changing. Default implementation returns true when there are no live agents.

Specified by:
isDone in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>

perceptsForAgent

public abstract java.util.Set<P> perceptsForAgent(A theAgent)
Returns a set (possibly empty) of percepts for the given agent. Presumably, this method examines the state of environment objects (including the agent itself) to select the appropriate percept. Note that the percept might include the outcome of the agent's most recent action.

Specified by:
perceptsForAgent in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>

addEnvironmentObject

public void addEnvironmentObject(EnvironmentObject theObject)
Adds an EnvironmentObject to the environment. Once added, an object cannot be removed, though note that all EnvironmentObjects support an isAlive() property which might be set to false to indicate that an object is no longer active.

Note that Agents, although they are also environment objects, should be added via the #addAgent() method.

The first Counter added will be used as 'the' counter returned by #getCounter(); any subsequent counters will just be treated as another environment object.

Specified by:
addEnvironmentObject in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>
Parameters:
theObject - the EnvironmentObject to add

addEnvironmentObserver

public 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.

Specified by:
addEnvironmentObserver in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>
Parameters:
theObserver - the EnvironmentObserver to add.

initialSetup

public void initialSetup()
Default initialization. The default version does nothing.

Specified by:
initialSetup in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>

startingToRunSetup

public void startingToRunSetup()
Default first-run initialization. Default version does nothing.

Specified by:
startingToRunSetup in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>

addAgent

public void addAgent(A theAgent)
Adds an Agent to the environment. Note that Agents should be added here, rather than via #addEnvironmentObject.

Specified by:
addAgent in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>

run

public void run()
Repeatedly calls executeStep until isDone is true.

Specified by:
run in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>

executeStep

public void executeStep()
Performs one step of the simulated environment. i.e. a. dynamicChange(), which changes zero or more objects spontaneously b. for 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

Specified by:
executeStep in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>

dynamicChange

public void dynamicChange()
Considers the current state of the environmentObjects, and changes zero or more objects. May be deterministic or stochastic.

All environments should update the state of their Counter object to increment the stepCounter.

Specified by:
dynamicChange in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>

agentDrivenChange

public abstract 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.

This might involve changing the state of the agent, updating a map of locations, and updating a table of performance measures.

Specified by:
agentDrivenChange in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>
Parameters:
theAgent - the agent that just selected an action
theAction - the action selected

getEnvironmentObjects

public java.util.Collection<EnvironmentObject> getEnvironmentObjects()
Returns a collection of all environment objects. This collection defines the state of the environment. Note that in particular implementations, the collection might be ordered.

Specified by:
getEnvironmentObjects in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>

getAgents

public java.util.Collection<A> getAgents()
Returns a collection of all agent objects, which is a (possibly empty) subset of the collection of all objects.

For performance & convenience, an environment implementation might choose to maintain a separate collection of agents, but this method could also just filter the object collection for instances of Agent.

Specified by:
getAgents in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>

getCounter

public 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

Specified by:
getCounter in interface Environment<K extends AgentAction,P extends AgentPercept,A extends Agent<K,P>>