edu.iastate.jrelm.core
Class BasicLearnerManager

java.lang.Object
  extended by edu.iastate.jrelm.core.BasicLearnerManager

public class BasicLearnerManager
extends java.lang.Object

Manages the collection of ReinforcementLearners in a simulation. Responsible for communicating parameter settings from a settings editor to individual leaners.

Author:
Charles Gieseler

Nested Class Summary
static class BasicLearnerManager.RegistrationEvent
           
static interface BasicLearnerManager.RegistrationListener
           
 
Field Summary
protected  java.util.Hashtable<java.lang.Class,java.util.Vector<JReLMAgent>> agentGrouping
           
protected  java.util.Hashtable<java.lang.String,JReLMAgent> agentTable
           
protected  int anonLearnersCount
           
protected  java.util.ArrayList<BasicLearnerManager.RegistrationListener> listenerList
           
protected  BasicSettingsEditor settings
           
 
Constructor Summary
BasicLearnerManager()
           
BasicLearnerManager(java.util.ArrayList<JReLMAgent> agentList)
           
BasicLearnerManager(ReinforcementLearner[] learnerList)
           
 
Method Summary
 void addRegistrationListener(BasicLearnerManager.RegistrationListener listener)
           
 JReLMAgent getAgent(java.lang.String agentID)
          Retrieve an agent with the given ID.
 java.util.Hashtable<java.lang.Class,java.util.Vector<JReLMAgent>> getAgentGrouping()
          Retrieves a grouping of agents classified according to the class of their learners.
 java.util.ArrayList<java.lang.String> getAgentIDList()
          Get a list of the String identifiers for all registered agents.
 java.util.Hashtable<java.lang.String,JReLMAgent> getAgentRegistery()
          Retrieve the whole agent registery.
 java.util.Vector<JReLMAgent> getGroup(java.lang.Class learnerClass)
          Retrieves a group of agents that all use the same reinforcement learning algorithm as indicated by the given class of ReinforcementLearner.
protected  void groupAgent(JReLMAgent agent)
          Agents are grouped according to their learning algorithm as indicated by the type of RLParameters their learner uses.
protected  void init()
           
 java.lang.String isRegistered(JReLMAgent agent)
           
 java.lang.String isRegistered(ReinforcementLearner learner)
          Check to see if a given ReinforcementLearner is already regisitered with this manager.
protected  void notifyListeners(java.lang.String[] ids, BasicLearnerManager.RegistrationEvent event)
           
 void printAgentGroups()
           
 boolean register(java.util.Collection<JReLMAgent> agents)
          Register a batch of JReLMAgents given as a Collection.
 boolean register(JReLMAgent agent)
          Register a single JReLMAgent.
 java.lang.String register(ReinforcementLearner learner)
          Register a bare ReinforcementLearner without a given ID.
 boolean register(java.lang.String id, ReinforcementLearner learner)
          Register a ReinforcementLearner under a given id
protected  void ungroupAgent(JReLMAgent agent)
          Agents are grouped according to their learning algorithm as indicated by the type of RLParameters their learner uses.
 boolean unregister(JReLMAgent agent)
           
 boolean unregister(ReinforcementLearner learner)
          Attempts to unregister the given ReinforcementLearner.
 boolean unregister(java.lang.String id)
           
 boolean updateSettings(java.lang.Class learnerType, RLParameters params)
          Update the settings for all agents in the algortithm group indicated by the given Class of ReinforcementLearner.
 boolean updateSettings(java.lang.String id, RLParameters params)
          Update the learning parameter settings for the agent specified by 'id'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

settings

protected BasicSettingsEditor settings

agentTable

protected java.util.Hashtable<java.lang.String,JReLMAgent> agentTable

agentGrouping

protected java.util.Hashtable<java.lang.Class,java.util.Vector<JReLMAgent>> agentGrouping

anonLearnersCount

protected int anonLearnersCount

listenerList

protected java.util.ArrayList<BasicLearnerManager.RegistrationListener> listenerList
Constructor Detail

BasicLearnerManager

public BasicLearnerManager()

BasicLearnerManager

public BasicLearnerManager(ReinforcementLearner[] learnerList)

BasicLearnerManager

public BasicLearnerManager(java.util.ArrayList<JReLMAgent> agentList)
Method Detail

init

protected void init()

isRegistered

public java.lang.String isRegistered(ReinforcementLearner learner)
Check to see if a given ReinforcementLearner is already regisitered with this manager. If it is, then this will return the String id that it is currently regisitered under. Otherwise, it will return null.


isRegistered

public java.lang.String isRegistered(JReLMAgent agent)

register

public java.lang.String register(ReinforcementLearner learner)
Register a bare ReinforcementLearner without a given ID. This learner to be registered under a generated generic ID. The ID will be returned upon successul registration.

Parameters:
learner - - the bare learner to register
Returns:
the auto-generated ID for this leaner. If the learner is already registered, returns the existing ID assigined to this anonymous learner. Returns null if the learner is not registered successfully.

register

public boolean register(java.lang.String id,
                        ReinforcementLearner learner)
Register a ReinforcementLearner under a given id

Parameters:
id - - the String indentifier that the learner will be registered under.
learner -
Returns:
true if the learner was successfully registered, false if a the learner has already been registered or another learner is registered under the given id.

register

public boolean register(JReLMAgent agent)
Register a single JReLMAgent. The agent will be registered under it's given ID (JReLMAgent.getID()).

Parameters:
agent - - the agent to register
Returns:
true if the agent was successfully registered, false if a the agent has already been registered or another agent is already registered under the same ID.

register

public boolean register(java.util.Collection<JReLMAgent> agents)
Register a batch of JReLMAgents given as a Collection. Each agent will be registered under it's given ID (JReLMAgent.getID()).

Parameters:
agents -
Returns:
true if all agents were successfully registered, false if one or more agents were already registered or another agent is already registered under the same ID.

unregister

public boolean unregister(ReinforcementLearner learner)
Attempts to unregister the given ReinforcementLearner.

Parameters:
learner - - remove this ReinforcementLearner from the registry
Returns:
true if the learner was successfully unregistered. False if the learner was not found in the registery.

unregister

public boolean unregister(JReLMAgent agent)

unregister

public boolean unregister(java.lang.String id)

groupAgent

protected void groupAgent(JReLMAgent agent)
Agents are grouped according to their learning algorithm as indicated by the type of RLParameters their learner uses. This method places the given agent in the appropriate algorithm group.


ungroupAgent

protected void ungroupAgent(JReLMAgent agent)
Agents are grouped according to their learning algorithm as indicated by the type of RLParameters their learner uses. This method removes the given agent from the algorithm group it is currently associated with.


updateSettings

public boolean updateSettings(java.lang.String id,
                              RLParameters params)
Update the learning parameter settings for the agent specified by 'id'.

Parameters:
id - - the String identifier for the desired agent
Returns:
true if the settings were accepted by the agent's learner. False if the RLParameters given were incompatible with the agent's learner.

updateSettings

public boolean updateSettings(java.lang.Class learnerType,
                              RLParameters params)
Update the settings for all agents in the algortithm group indicated by the given Class of ReinforcementLearner. The given RLParameters must be compatible the indicated ReinforcementLearner type.

Parameters:
learnerType - - Class of ReinforcementLearner indicating which group of agents should receive these settings
params - - the new learning parameter settings to use for all agents in the group
Returns:
true if the given parameters have been accepted by all agents in the group. False if the parameter settings were rejected by any agent in the group.

getAgent

public JReLMAgent getAgent(java.lang.String agentID)
Retrieve an agent with the given ID. If no such agent is registered, then null is returned.

Parameters:
agentID - - the ID of the desired agent
Returns:
an agent with the given ID or null if no such agent has been registered.

getAgentIDList

public java.util.ArrayList<java.lang.String> getAgentIDList()
Get a list of the String identifiers for all registered agents.

Returns:
an ArrayList containing the String IDs of all registered agents.

getAgentRegistery

public java.util.Hashtable<java.lang.String,JReLMAgent> getAgentRegistery()
Retrieve the whole agent registery. Registry is returned as a Hashtable associating String IDs with JReLMAgents.

Returns:
the Hashtable JReLMAgent registry

getGroup

public java.util.Vector<JReLMAgent> getGroup(java.lang.Class learnerClass)
Retrieves a group of agents that all use the same reinforcement learning algorithm as indicated by the given class of ReinforcementLearner.

Parameters:
learnerClass -
Returns:

getAgentGrouping

public java.util.Hashtable<java.lang.Class,java.util.Vector<JReLMAgent>> getAgentGrouping()
Retrieves a grouping of agents classified according to the class of their learners. The grouping is returned as a Hashtable keyed on Class objects representing the class of learners. Values in the Hashtable are groups of JReLMAgents stored as Vectors.

Returns:
a collection of groups of agents.

printAgentGroups

public void printAgentGroups()

addRegistrationListener

public void addRegistrationListener(BasicLearnerManager.RegistrationListener listener)

notifyListeners

protected void notifyListeners(java.lang.String[] ids,
                               BasicLearnerManager.RegistrationEvent event)