elge.agent
Class Agent

java.lang.Object
  |
  +--elge.agent.Agent
Direct Known Subclasses:
AgentContainer

public class Agent
extends Object

Agent is a very base class for this environment (Later maybe an interface). Other entities are subclasses of this class.

Agent is defined with its own life cycle invoked with method life(). The method runs 3 standartd other methods, sense(), memorize() and chooseAction(). To modify the agent behavior, override these methods.

ELGE GUI uses beans standarts to determine properties, so every method pair with get and set prefix will make the parameter available in the GUI.

Author:
Pavol Žibrita

Field Summary
protected  Situation actualSituation
          actualSituation is used to store the Situation that has the agent sensed in his life cycle.
protected  Agency agency
          Agency is the agency from parent, or only for this agent.
protected static Class agencyClass
          What agency is the agent using.
protected static Hashtable agentClassCounter
          Use to generate unique ID's for diferent agent classes.
protected  long id
          The ID of agent.
protected  String name
          Name of the agent.
protected  boolean registered
          this is agent's internal state variable to know, it the agent has already be registred in the agency.
 
Constructor Summary
Agent()
          Creates a new instance of Agent
Agent(Agency agency)
          Creates agent with agency
Agent(String name)
          Creates agent with name name
Agent(String name, Agency agency)
          Creates agent with name and agency
 
Method Summary
 Situation ask(Agent to, String message, Object params)
          like ask(java.lang.String) but tries to ask a specific agent agent
 Situation ask(String message)
          ask is the method to comunicate to other agents.
 Situation ask(String message, Object params)
          As ask, but with some inner Context - params.
static Agency createDefaultAgency()
          Creates a default agency from the agencyClass
static long createUniqueID(Class cls)
          Used to create uniqe ID's for agent instances, but as it is not realy needed, other part of system uses this method.
 Agency getAgency()
          Return agency.
 String getFullName()
          This method should be used to fully identify the agent in the system.
 long getID()
          id of the agent.
 String getName()
          Returns name of the agent.
protected  void chooseAction()
          The last method that is called for the life cycle of agent.
 void init()
          This method performs initializing of the agent.
 void life()
          This method performs the agent life cycle.
 void life(int times)
          Like life, instead the life is called times times.
protected  void memorize()
          Second method for the life cycle of agent.
 void restart()
          This method performs restarting the agent.
protected  void sense()
          First method for the agent life cycle.
 void setAgency(Agency agency)
          Sets the agency for this agent and also calls register agent on it.
 void setAgency(Agent agent)
          this mehotd calls setAgency for the param agent, and sets it the agency of this agent.
 void setAgency(Enumeration agents)
          Like setAgency(elge.agent.Agency) but for enumeration of agents
 void setID(long id)
          sets the id for the agent.
 void setName(String name)
          Sets the name for the agent.
 String toString()
          Converts the agento to string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

agency

protected Agency agency
Agency is the agency from parent, or only for this agent.


actualSituation

protected Situation actualSituation
actualSituation is used to store the Situation that has the agent sensed in his life cycle.

See Also:
sense()

registered

protected boolean registered
this is agent's internal state variable to know, it the agent has already be registred in the agency.


name

protected String name
Name of the agent. Very common thing that every agent should be named. No restriction is to this vriable.


id

protected long id
The ID of agent. It is good for system to recognize the agent's also by the ID, if thier names are equal.

See Also:
getFullName()

agencyClass

protected static Class agencyClass
What agency is the agent using.


agentClassCounter

protected static Hashtable agentClassCounter
Use to generate unique ID's for diferent agent classes.

Constructor Detail

Agent

public Agent()
Creates a new instance of Agent


Agent

public Agent(String name)
Creates agent with name name

Parameters:
name - name of the agent

Agent

public Agent(Agency agency)
Creates agent with agency

Parameters:
agency - the agency to use to comunicate

Agent

public Agent(String name,
             Agency agency)
Creates agent with name and agency

Parameters:
name - name of the agent
agency - agency for comunication
Method Detail

createUniqueID

public static long createUniqueID(Class cls)
Used to create uniqe ID's for agent instances, but as it is not realy needed, other part of system uses this method.

Parameters:
cls - class for which to get next id.
Returns:
returns next available ID for the agent.
See Also:
getID(), setID(long)

createDefaultAgency

public static Agency createDefaultAgency()
Creates a default agency from the agencyClass

Returns:
instance of Agency if it can be created.

setAgency

public void setAgency(Agency agency)
Sets the agency for this agent and also calls register agent on it. If it was registred before, it unregistres first from the old agency.

Parameters:
agency - set agency to the agent.
See Also:
Agency.register(elge.agent.Agent)

setName

public void setName(String name)
Sets the name for the agent.

Parameters:
name - name of the agent

getName

public String getName()
Returns name of the agent.

Returns:
name of the agent.

getFullName

public String getFullName()
This method should be used to fully identify the agent in the system.

Returns:
returns full name of the agent which for agent class is 'name.id'

getID

public long getID()
id of the agent.

Returns:
returns the id of agent
See Also:
setID(long), getFullName()

setID

public void setID(long id)
sets the id for the agent.

Parameters:
id - id to set for this agent.
See Also:
getID(), getFullName()

setAgency

public void setAgency(Agent agent)
this mehotd calls setAgency for the param agent, and sets it the agency of this agent.

Parameters:
agent - agent to set the agency,

setAgency

public void setAgency(Enumeration agents)
Like setAgency(elge.agent.Agency) but for enumeration of agents

Parameters:
agents - Enumeration of agents..
Throws:
ClassCastException - if enumeration contains noninstances of class Agent

getAgency

public Agency getAgency()
Return agency. Note, that this can be used in the GUI model.

Returns:
returns actual agency or null if not set.

sense

protected void sense()
First method for the agent life cycle.


memorize

protected void memorize()
Second method for the life cycle of agent.


chooseAction

protected void chooseAction()
The last method that is called for the life cycle of agent.


life

public void life()
This method performs the agent life cycle. Calls the sense, memorize and chooseAction methods.


restart

public void restart()
This method performs restarting the agent. It should restart what wver it needs, like some counter, memory and so. A brand new simulation should be runned with it !


init

public void init()
This method performs initializing of the agent. This method is called every time agent is added to the world or when the init of the world is called.


life

public void life(int times)
Like life, instead the life is called times times. make some thread agent? :)

Parameters:
times - how many times to call the life cycle.

ask

public Situation ask(String message)
ask is the method to comunicate to other agents. The Situation (alias Context) is returned as result for the action message. The ask calls the agency methods.

Parameters:
message - message ident string
Returns:
returns Situation as result to the action.
See Also:
Agency

ask

public Situation ask(String message,
                     Object params)
As ask, but with some inner Context - params.

Parameters:
message - action to choose.
params - context in the action is executed.
Returns:
returns the Situation acording the action..

ask

public Situation ask(Agent to,
                     String message,
                     Object params)
like ask(java.lang.String) but tries to ask a specific agent agent

Parameters:
to - agent to ask the message
message - message ident string
params - some parameters
Returns:
answer as Situaion from the asked agent

toString

public String toString()
Converts the agento to string.

Overrides:
toString in class Object
Returns:
returns the name of the agent, calls getFullName()