se.liu.ida.critiquer.resources
Class Agent

java.lang.Object
  extended by se.liu.ida.critiquer.resources.Agent
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Ambulance, DefaultAgent, Helicopter, Leader, PoliceUnit, RadarTruck, UAVAgent

public abstract class Agent
extends Object
implements Serializable

Agents are a part of and perform activities. They are added and removed via the Resource View.

In order for an agent to be considered suitable for an activity is should put the appropriate entries into the fitnessMap class field.

Also, in order to calculate how long it takes for an agent to perform an activity, the missionContributionCalculators map is used to look up procedures that calculate the time it takes an agent to perform some unit of work on an activity. Moreover, performing an operation may have side-effects which are modelled by having a HashMap as an argument to a AgentContributionCalculator that may be modified by the agent while performing some action.

It is not intended that a single "use" of an agent solves a task, since it may be impossible for an agent to complete a task on its own or it may be more appropriate if the agent performs only a small part of it. As it is right now, the agent reports some number on how long it takes to perform (possibly only a part of) the mission and the activity is responsible for accumulating this information into some overall time for the mission as a whole.

See Also:
Serialized Form

Field Summary
protected  AgentSimulationState agentSimulationState
           
static Agent dummyAgent
          Placeholder agent to be used when the side-effects of using an agent is desirable and the most convenient way is to have a placeholder agent
protected static HashMap<Class,HashMap<Class,Suitability>> fitnessMap
           
 HashMap<Class,AgentContributionCalculator> missionContributionCalculators
           
 String name
           
 
Constructor Summary
Agent(Agent parent, String name)
           
Agent(String name)
           
 
Method Summary
 void addAgentChangedListener(AgentParameter parameter)
           
 void addChild(Agent child)
           
<T> void
addParameter(ParameterInAgent<T> param)
           
 boolean equals(Object o)
          Compare agents with respect to their names
 ArrayList<Activity> getActivitiesForAgent()
           
 AgentSimulationState getAgentSimulationState()
           
 ArrayList<Agent> getChildren()
           
 AgentLabel getLabel(AgentParameter param)
           
 JPanel getPanel()
           
<C> ParameterInAgent<C>
getParamByClassAndName(Class<C> c, AgentParameterName name)
           
 Agent getParent()
           
 ImageIcon getPicture()
           
static Suitability getSuitability(Agent agent, Activity activity)
          Should agents or constraints be responsible for knowing which agent is suitable for which task?
 Color getTimeLineColor()
           
 int hashCode()
          Use the name for hash value
 void initAgentSimulationState(SimulationEngine engine)
           
protected  void initPanel()
          Take all user-visible parameters of this agent and add them to the panel
 void notifyAgentChangedListeners()
          Notify AgentParameters containing this agent that it has changed some property
<T extends Activity>
long
perform(Class<T> activityClass, T activity, HashMap<Activity.Properties,Integer> activityAttributes)
          Perform activity of class activityClass by dispatching to the appropriate procedure.
 void removeAgentChangedListener(AgentParameter parameter)
           
 void setPicture(ImageIcon picture)
           
 void setPictureFromName(String fileName)
          Create an image baased on a filename pointing to the resource directory.
 void setTimeLineColor(Color timeLineColor)
           
 String toString()
          Returns the name of this agent
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

dummyAgent

public static Agent dummyAgent
Placeholder agent to be used when the side-effects of using an agent is desirable and the most convenient way is to have a placeholder agent


fitnessMap

protected static HashMap<Class,HashMap<Class,Suitability>> fitnessMap

missionContributionCalculators

public HashMap<Class,AgentContributionCalculator> missionContributionCalculators

name

public String name

agentSimulationState

protected transient AgentSimulationState agentSimulationState
Constructor Detail

Agent

public Agent(String name)
Parameters:
name -

Agent

public Agent(Agent parent,
             String name)
Parameters:
parent - is supposed to be an organizational unit that contains this agent, null if not applicable
name -
Method Detail

addParameter

public <T> void addParameter(ParameterInAgent<T> param)

getParamByClassAndName

public <C> ParameterInAgent<C> getParamByClassAndName(Class<C> c,
                                                      AgentParameterName name)

toString

public String toString()
Returns the name of this agent

Overrides:
toString in class Object
See Also:
Object.toString()

initPanel

protected void initPanel()
Take all user-visible parameters of this agent and add them to the panel


getActivitiesForAgent

public ArrayList<Activity> getActivitiesForAgent()

initAgentSimulationState

public void initAgentSimulationState(SimulationEngine engine)

getAgentSimulationState

public AgentSimulationState getAgentSimulationState()

equals

public boolean equals(Object o)
Compare agents with respect to their names

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Use the name for hash value

Overrides:
hashCode in class Object
See Also:
Object.hashCode()

addChild

public void addChild(Agent child)

getLabel

public AgentLabel getLabel(AgentParameter param)

getSuitability

public static Suitability getSuitability(Agent agent,
                                         Activity activity)
Should agents or constraints be responsible for knowing which agent is suitable for which task? Right now we require agents to provide this information. It could easily be lifted to a GUI instead, if that's really preferable.


perform

public <T extends Activity> long perform(Class<T> activityClass,
                                         T activity,
                                         HashMap<Activity.Properties,Integer> activityAttributes)
             throws UnsupportedOperationException
Perform activity of class activityClass by dispatching to the appropriate procedure. When we "perform" a mission, we may modify some attributes that were set in the activityAttributes map. For now, there is no good "standard" way of finding out which attributes are present and how they should be modified, but the idea is that the agents and activities in a scenario are developed in tandem with good knowledge of each other. In the standard scenario, the StandardAgentParameterFactory knows of the attributes in activities in the standard scenario package. These attributes reflect properties of the activity, not the agent.

Throws:
UnsupportedOperationException

getTimeLineColor

public Color getTimeLineColor()
Returns:
Returns the timeLineColor.

setTimeLineColor

public void setTimeLineColor(Color timeLineColor)
Parameters:
timeLineColor - The timeLineColor to set.

getChildren

public ArrayList<Agent> getChildren()
Returns:
Returns the children.

getParent

public Agent getParent()
Returns:
Returns the parent.

getPanel

public JPanel getPanel()
Returns:
Returns the panel.

addAgentChangedListener

public void addAgentChangedListener(AgentParameter parameter)

removeAgentChangedListener

public void removeAgentChangedListener(AgentParameter parameter)

notifyAgentChangedListeners

public void notifyAgentChangedListeners()
Notify AgentParameters containing this agent that it has changed some property


getPicture

public ImageIcon getPicture()
Returns:
Returns the picture.

setPicture

public void setPicture(ImageIcon picture)
Parameters:
picture - The picture to set.

setPictureFromName

public void setPictureFromName(String fileName)
Create an image baased on a filename pointing to the resource directory.

Parameters:
fileName -