visidia.simulation.process.agent
Class Agent

java.lang.Object
  extended by visidia.misc.property.PropertyTable
      extended by visidia.simulation.process.agent.Agent
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Runnable
Direct Known Subclasses:
SynchronousAgent

public abstract class Agent
extends PropertyTable
implements java.lang.Runnable

This is the abstract base class representing an agent in visidia. It is the API to be used to implement new agents (extending Agent class).

See Also:
Serialized Form

Field Summary
protected  AgentMover agentMover
          The agent mover.
protected  AgentProcess proc
          The process.
 
Constructor Summary
protected Agent()
          Instantiates a new agent.
 
Method Summary
protected  java.util.Collection agentsOnVertex()
          Returns the collection of agents which are on the destination vertex of current agent.
abstract  java.lang.Object clone()
           
protected  int entryDoor()
          Returns the door from which the agent comes.
 int getArity()
          Gets the arity.
 Vertex getDestinationVertex()
          Gets the destination vertex.
protected  java.lang.Object getEdgeProperty(int door, java.lang.Object key)
          Gets the edge property value.
protected  int getNetSize()
          Gets the net size.
 java.lang.Object getProperty(java.lang.Object key)
          Returns the property value associated with the key.
protected  int getVertexIdentity()
          Gets the identity of vertex on which the agent is located.
protected  java.lang.String getVertexLabel()
          Gets the vertex label.
protected  java.lang.Object getVertexProperty(java.lang.Object key)
          Gets the vertex property value.
protected abstract  void init()
          Initializes the agent.
protected  boolean lockVertexIfPossible()
          If the vertex is already locked, return false and does nothing, else return true and lock the vertex.
protected  void lockVertexProperties()
          Lock vertex properties.
protected  void move()
          Moves the agent.
protected  void moveBack()
          Moves the agent back to the vertex from where it comes.
protected  void moveToDoor(int door)
          Moves agent to door.
 void run()
           
protected  void setAgentMover(java.lang.String name)
          Sets the agent mover.
 void setAgentProcess(AgentProcess proc)
          Sets the agent process.
protected  void setDoorState(EdgeState st, int door)
          Sets the door state.
protected  void setEdgeProperty(int door, java.lang.Object key, java.lang.Object value)
          Sets the edge property.
 java.lang.Object setProperty(java.lang.Object key, java.lang.Object value)
          Sets the property.
 java.lang.Object setProperty(java.lang.Object key, java.lang.Object value, int status)
          Sets the property (key, value).
protected  void setVertexLabel(java.lang.String label)
          Sets the vertex label.
protected  void setVertexProperty(java.lang.Object key, java.lang.Object value)
          Sets the vertex property.
protected  void setVertexProperty(java.lang.Object key, java.lang.Object value, int status)
          Sets the vertex property.
protected  void sleep(int milliseconds)
          Use this method if you want to fall asleep for a given amount of milliseconds.
 java.lang.String toString()
           
protected  void unlockVertexProperties()
          Unlock vertex properties.
protected  boolean vertexPropertiesLocked()
          Return true if the Vertex is locked, otherwise false.
 
Methods inherited from class visidia.misc.property.PropertyTable
containsElement, entrySet, getLockOwner, getPropertyKeys, getVisidiaProperty, isPersistentProperty, locked, lockProperties, removeProperty, resetProperties, setProperties, setVisidiaProperty, unlockProperties
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

proc

protected transient AgentProcess proc
The process.


agentMover

protected AgentMover agentMover
The agent mover.

Constructor Detail

Agent

protected Agent()
Instantiates a new agent.

Method Detail

clone

public abstract java.lang.Object clone()
Overrides:
clone in class PropertyTable

init

protected abstract void init()
Initializes the agent.


agentsOnVertex

protected final java.util.Collection agentsOnVertex()
Returns the collection of agents which are on the destination vertex of current agent.

Returns:
the collection

getArity

public final int getArity()
Gets the arity.

Returns:
the arity

sleep

protected final void sleep(int milliseconds)
Use this method if you want to fall asleep for a given amount of milliseconds.

Parameters:
milliseconds - the number of milliseconds

getNetSize

protected final int getNetSize()
Gets the net size. Provided for convenience, since an agent is not supposed to know graph global information.

Returns:
the net size

getProperty

public final java.lang.Object getProperty(java.lang.Object key)
Returns the property value associated with the key. If the key can't be found, returns null.

Parameters:
key - the key
Returns:
the property value

setProperty

public final java.lang.Object setProperty(java.lang.Object key,
                                          java.lang.Object value,
                                          int status)
Sets the property (key, value).

Parameters:
key - the key
value - the value
status - the status
Returns:
the previous property value of the specified key in this hashtable, or if it did not have one.

setProperty

public final java.lang.Object setProperty(java.lang.Object key,
                                          java.lang.Object value)
Sets the property.

Parameters:
key - the key
value - the value
Returns:
the previous property value of the specified key in this hashtable, or null if it did not have one.

getVertexProperty

protected final java.lang.Object getVertexProperty(java.lang.Object key)
Gets the vertex property value.

Parameters:
key - the key
Returns:
the vertex property value

setVertexProperty

protected final void setVertexProperty(java.lang.Object key,
                                       java.lang.Object value,
                                       int status)
Sets the vertex property.

Parameters:
key - the key
value - the value
status - the status

setVertexProperty

protected final void setVertexProperty(java.lang.Object key,
                                       java.lang.Object value)
Sets the vertex property.

Parameters:
key - the key
value - the value

getVertexIdentity

protected final int getVertexIdentity()
Gets the identity of vertex on which the agent is located.

Returns:
the vertex identity

getVertexLabel

protected final java.lang.String getVertexLabel()
Gets the vertex label.

Returns:
the vertex label

setVertexLabel

protected final void setVertexLabel(java.lang.String label)
Sets the vertex label.

Parameters:
label - the new vertex label

lockVertexProperties

protected final void lockVertexProperties()
Lock vertex properties.


unlockVertexProperties

protected final void unlockVertexProperties()
Unlock vertex properties.


vertexPropertiesLocked

protected final boolean vertexPropertiesLocked()
Return true if the Vertex is locked, otherwise false.

See Also:
lockVertexProperties()

lockVertexIfPossible

protected final boolean lockVertexIfPossible()
If the vertex is already locked, return false and does nothing, else return true and lock the vertex.


getEdgeProperty

protected final java.lang.Object getEdgeProperty(int door,
                                                 java.lang.Object key)
Gets the edge property value.

Parameters:
door - the door
key - the key
Returns:
the edge property value

setEdgeProperty

protected final void setEdgeProperty(int door,
                                     java.lang.Object key,
                                     java.lang.Object value)
Sets the edge property.

Parameters:
door - the door
key - the key
value - the value

setDoorState

protected final void setDoorState(EdgeState st,
                                  int door)
Sets the door state.

Parameters:
st - the new state
door - the door

move

protected final void move()
Moves the agent.


moveBack

protected final void moveBack()
Moves the agent back to the vertex from where it comes.


moveToDoor

protected final void moveToDoor(int door)
Moves agent to door.

Parameters:
door - the door

entryDoor

protected final int entryDoor()
Returns the door from which the agent comes.

Returns:
the door

setAgentMover

protected final void setAgentMover(java.lang.String name)
Sets the agent mover.

Parameters:
name - the new agent mover

getDestinationVertex

public final Vertex getDestinationVertex()
Gets the destination vertex.

Returns:
the destination vertex

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setAgentProcess

public final void setAgentProcess(AgentProcess proc)
Sets the agent process.

Parameters:
proc - the new agent process

run

public final void run()
Specified by:
run in interface java.lang.Runnable