Class TACAgent

java.lang.Object
  extended by se.sics.tasim.aw.Agent
      extended by TACAgent
All Implemented Interfaces:
se.sics.tasim.aw.TimeListener

public class TACAgent
extends se.sics.tasim.aw.Agent
implements se.sics.tasim.aw.TimeListener

The main agent class. Each day, messages from the server are received and processed. The agent's information is updated, the managers perform their tasks, the information is updated again with the results, and then messages are sent to the server.


Field Summary
private  DailyActions actions
          the messages to be sent by the agent at the end of the day
private  AgentInfo agentInfo
          stores the agent's state
private  java.lang.String agentName
          the agent's name
private  boolean debugMode
           
private  InterfaceDemandManager demandManager
          the demand manager object
private  java.util.Hashtable managers
          stores manager classes by name to allow reuse
private  GameSettings settings
          the game parameters sent at the beginning of the game
private  InterfaceSupplyManager supplyManager
          the supply manager object
private  java.io.PrintStream textLog
          where to write any output
private  DailyInfo todaysInfo
          the information received at the beginning of the day
 
Fields inherited from class se.sics.tasim.aw.Agent
ADMIN, COORDINATOR
 
Constructor Summary
TACAgent()
           
TACAgent(java.lang.String name)
          The constructor for debug mode.
 
Method Summary
 void eveningUpdate(DailyActions actions)
          Update agent with actions performed that day.
private  java.lang.Object getManager(java.lang.String name)
          Return a manager object based on the class name.
private  java.lang.String getNextLine(java.io.BufferedReader f)
           
protected  void messageReceived(se.sics.tasim.aw.Message message)
          A method of the Agent superclass, called with each message received from the server, either at the start of the game or the beginning of each day.
 void morningUpdate(DailyInfo todaysInfo)
          Update agent with information received at the start of the day.
 void nextTimeUnit(int date)
           
private  void processStartInfo(se.sics.tasim.props.StartInfo info)
          Handles the information we are given at the start of the game.
private  void readConfig()
          Reads in the agent parameters (such as manager classes) from the config file with name [agentName]Config.txt
private  void sendMessages()
          Sends all of the messages generated today.
 void setGameSettings(GameSettings settings)
          Sets the game settings.
protected  void simulationFinished()
          A method of the Agent superclass, called when the game ends.
protected  void simulationSetup()
          A method of the Agent superclass, called when the agent starts.
 void simulationStopped()
          A method of the Agent superclass, called when the game ends.
 void startDay()
          The method that performs each day's tasks.
 
Methods inherited from class se.sics.tasim.aw.Agent
addTimeListener, getAddress, getName, getNextID, getServerTime, removeTimeListener, sendMessage, sendMessage, sendMessages, sendToRole
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugMode

private boolean debugMode

todaysInfo

private DailyInfo todaysInfo
the information received at the beginning of the day


settings

private GameSettings settings
the game parameters sent at the beginning of the game


agentInfo

private AgentInfo agentInfo
stores the agent's state


actions

private DailyActions actions
the messages to be sent by the agent at the end of the day


textLog

private java.io.PrintStream textLog
where to write any output


agentName

private java.lang.String agentName
the agent's name


managers

private java.util.Hashtable managers
stores manager classes by name to allow reuse


demandManager

private InterfaceDemandManager demandManager
the demand manager object


supplyManager

private InterfaceSupplyManager supplyManager
the supply manager object

Constructor Detail

TACAgent

public TACAgent(java.lang.String name)
The constructor for debug mode.

Parameters:
name - the name the agent ran as (e.g., Dummy3)

TACAgent

public TACAgent()
         throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

nextTimeUnit

public void nextTimeUnit(int date)
Specified by:
nextTimeUnit in interface se.sics.tasim.aw.TimeListener

getNextLine

private java.lang.String getNextLine(java.io.BufferedReader f)
                              throws java.lang.Exception
Throws:
java.lang.Exception

getManager

private java.lang.Object getManager(java.lang.String name)
                             throws java.lang.Exception
Return a manager object based on the class name. If a manager of that class already exists, the existing object is returned (this way, a single object may implement multiple managers.

Parameters:
name - the class name
Returns:
a manager object
Throws:
java.lang.Exception

simulationSetup

protected void simulationSetup()
A method of the Agent superclass, called when the agent starts.

Specified by:
simulationSetup in class se.sics.tasim.aw.Agent

readConfig

private void readConfig()
Reads in the agent parameters (such as manager classes) from the config file with name [agentName]Config.txt


simulationFinished

protected void simulationFinished()
A method of the Agent superclass, called when the game ends.

Specified by:
simulationFinished in class se.sics.tasim.aw.Agent

messageReceived

protected void messageReceived(se.sics.tasim.aw.Message message)
A method of the Agent superclass, called with each message received from the server, either at the start of the game or the beginning of each day.

Specified by:
messageReceived in class se.sics.tasim.aw.Agent

startDay

public void startDay()
              throws java.lang.Exception
The method that performs each day's tasks.

Throws:
java.lang.Exception

sendMessages

private void sendMessages()
Sends all of the messages generated today.


processStartInfo

private void processStartInfo(se.sics.tasim.props.StartInfo info)
Handles the information we are given at the start of the game.

Parameters:
info - starting info (BOM, catalog, etc.)

simulationStopped

public void simulationStopped()
A method of the Agent superclass, called when the game ends.

Overrides:
simulationStopped in class se.sics.tasim.aw.Agent

morningUpdate

public void morningUpdate(DailyInfo todaysInfo)
Update agent with information received at the start of the day.

Parameters:
todaysInfo - all messages received

eveningUpdate

public void eveningUpdate(DailyActions actions)
Update agent with actions performed that day.

Parameters:
actions - all outgoing messages

setGameSettings

public void setGameSettings(GameSettings settings)
Sets the game settings.

Parameters:
settings -