Class AbstractAgent

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--AbstractAgent
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
PlanningAgent

public abstract class AbstractAgent
extends Thread

This class provides the basic structure for the implementation of agent loops. All implementations of agent loops must be (possibly indirect) subclasses of this class.

Agents can be customized by users of the APLAgent Manager by modifying the agent's parameters via the GUI. The set of parameters of an agent is described by the appropriate subclass of AgentParams. When subclasses of AbstractAgent invoke the constructor of AbstractAgent, they may specify the name of the parameter class that they intend to use. For example:

    private ExampleAgentParams myParams;

    public ExampleAgent() throws Exception
    {     super("ExampleAgentParams");

          // APLAgent Manager creates an instance for us
          myParams=(ExampleAgentParams)getAgentParams();
    }
 
The agent loop is implemented by method agentLoop(). Subclasses of AbstractAgent are expected to define their agent loop. For example:
	 // The agent loop for the planning agent.
	public void agentLoop() throws Exception
	{	ActionSequence plan;
		String goal;

		goal=getObservationsAndGoal();

		// if agent sets goal autonomously, use: getObservations() and showSelectedGoal(goal)

		plan=findPlan(goal);

		performPartOfPlan(plan);

	}
 
Calls to the inference engine should be performed by means of methods computeOneTrajectory() and computeAllTrajectory(). The list of files that are required by these methods can be retrieved by applying method getFiles on fields aFiles (agent files) and dFiles (domain files). For example, a code fragment that computes one plan is:
			MathSet files=new MathSet();
			files.add(tempFile);
			files=files.union(dFiles.getFiles(DomainFiles.ACT_DESC));
			files=files.union(dFiles.getFiles(DomainFiles.PROB_INST));
			files=files.union(dFiles.getFiles(DomainFiles.HIDES));
			files=files.union(aFiles.getFiles(AgentFiles.PLANNING));
			files=files.union(aFiles.getFiles(AgentFiles.HIDES));
			trj=computeOneTrajectory(files,currTime,lastTime);
 


Field Summary
 MathSet actions
          The set of actions defined in the domain.
 AgentFiles aFiles
          This is the collection of A-Prolog files for the reasoning modules of the agent.
 MathSet agentActions
          The set of agent actions defined in the domain.
 int currTime
          The current time step.
 DomainFiles dFiles
          This is the collection of A-Prolog files that describe the domain.
 Engine engine
          Used internally
 MathSet exogenousActions
          The set of exogenous actions defined in the domain.
 MathSet fluents
          The set of fluents defined in the domain.
 MathSet goals
          The set of goals defined in the domain.
 History history
          The current history.
 String tempFile
          The name of the temporary file.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AbstractAgent()
          Constructs an AbstractAgent, with the default set of parameters.
AbstractAgent(String agentParamsClassName)
          Constructs an AbstractAgent, using the parameter class whose name is given.
 
Method Summary
abstract  void agentLoop()
          The agent loop.
 void appendHistory(String tf)
          Appends the current history to the temporary file.
 void appendPlan(String tf, ActionSequence plan, int currTime)
          Appends a plan (i.e., an ActionSequence) to the temporary file, starting from the given time step.
 void appendText(String tf, String lit)
          Appends a string to the temporary file, returned by a newline character.
 void clearTempFile(String tf)
          Deletes the contents of the given temporary file.
 TrajectorySet computeAllTrajectories(MathSet fileList, int currTime, int lastTime)
          Computes all the models of the given list of files, with the given values for A-Prolog parameters currtime and lasttime, and returns the TrajectorySet represented by the models.
 Trajectory computeOneTrajectory(MathSet fileList, int currTime, int lastTime)
          Computes one model of the given list of files, with the given values for A-Prolog parameters currtime and lasttime, and returns the Trajectory contained in the model.
 TrajectorySet findDefinedTrajectories(ActionSequence plan)
          Computes the set of trajectories defined by the given plan.
 AgentParams getAgentParams()
          Returns the set of parameters for the agent, after they have been initialized by the APLAgent Manager.
 void getObservations()
          Gathers the observations about the current time step.
 void getObservations(boolean goalSelection)
          Gathers the observations about the current time step.
 String getObservationsAndGoal()
          Gathers the observations about the current time step.
 void initialize(APLAgentMgr p, AgentFiles af, DomainFiles df, History h, Vector g, File tf, Engine e, AgentParams ap)
          Invoked only by the APLAgent Manager
 void log(String s)
          Appends a line to the Log Window in the APLAgent Manager.
 void performPartOfPlan(ActionSequence plan)
          Performs the first compound action of the given plan.
 void repeatIteration()
          Repeats the last iteration of the agent loop.
 void repeatIterationNoModel()
          Repeats the last iteration of the agent loop.
 void repeatIterationNoPlan()
          Repeats the last iteration of the agent loop.
 void run()
          Invoked only by the APLAgent Manager
 void showSelectedGoal(String goal)
          Updates the GUI in order to show the goal selected by the agent.
 void terminateLoop()
          Terminates the agent loop.
 void terminateLoopNoModel()
          Terminates the agent loop.
 void terminateLoopNoPlan()
          Terminates the agent loop.
 void updateAgentFiles(AgentFiles af)
          Invoked only by the APLAgent Manager
 void updateGoals(Vector g, DomainFiles df)
          Invoked only by the APLAgent Manager
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

aFiles

public AgentFiles aFiles
This is the collection of A-Prolog files for the reasoning modules of the agent.

dFiles

public DomainFiles dFiles
This is the collection of A-Prolog files that describe the domain.

engine

public Engine engine
Used internally

history

public History history
The current history.

fluents

public MathSet fluents
The set of fluents defined in the domain.

actions

public MathSet actions
The set of actions defined in the domain. (It is the union of agent actions and exogenous actions.)

agentActions

public MathSet agentActions
The set of agent actions defined in the domain.

exogenousActions

public MathSet exogenousActions
The set of exogenous actions defined in the domain.

goals

public MathSet goals
The set of goals defined in the domain.

currTime

public int currTime
The current time step.

tempFile

public String tempFile
The name of the temporary file. This file can be used by the agent to prepare data that must be fed to the inference engine.
Constructor Detail

AbstractAgent

public AbstractAgent()
Constructs an AbstractAgent, with the default set of parameters.

AbstractAgent

public AbstractAgent(String agentParamsClassName)
              throws ClassNotFoundException,
                     InstantiationException,
                     IllegalAccessException
Constructs an AbstractAgent, using the parameter class whose name is given.
Parameters:
agentParamsClassName - the name of the parameter class
Method Detail

initialize

public void initialize(APLAgentMgr p,
                       AgentFiles af,
                       DomainFiles df,
                       History h,
                       Vector g,
                       File tf,
                       Engine e,
                       AgentParams ap)
Invoked only by the APLAgent Manager

updateAgentFiles

public void updateAgentFiles(AgentFiles af)
Invoked only by the APLAgent Manager

updateGoals

public void updateGoals(Vector g,
                        DomainFiles df)
Invoked only by the APLAgent Manager

getAgentParams

public AgentParams getAgentParams()
Returns the set of parameters for the agent, after they have been initialized by the APLAgent Manager.
Returns:
the set of parameters for the agent

clearTempFile

public void clearTempFile(String tf)
Deletes the contents of the given temporary file.
Parameters:
tf - the name of the temporary file

appendHistory

public void appendHistory(String tf)
Appends the current history to the temporary file.
Parameters:
tf - the name of the temporary file

appendPlan

public void appendPlan(String tf,
                       ActionSequence plan,
                       int currTime)
Appends a plan (i.e., an ActionSequence) to the temporary file, starting from the given time step.
Parameters:
tf - the name of the temporary file
plan - the plan to be appended to the file
currTime - the first time step to be appended

appendText

public void appendText(String tf,
                       String lit)
Appends a string to the temporary file, returned by a newline character.
Parameters:
tf - the name of the temporary file
lit - the string to be appended

log

public void log(String s)
Appends a line to the Log Window in the APLAgent Manager.
Parameters:
s - the line to be appended

getObservations

public void getObservations(boolean goalSelection)
                     throws Exception
Gathers the observations about the current time step. This is the method that agent loops are expected to invoke for the observation-gathering step. Goal selection by the user can be either enabled or disabled, depending on whether the agent is able to pick goals autonomously.

When the method returns, observations can be found in the history field of the AbstractAgent class.

Parameters:
goalSelection - true if goal selection is allowed; false otherwise

getObservations

public void getObservations()
                     throws Exception
Gathers the observations about the current time step. This is the method that agent loops are expected to invoke for the observation-gathering step. Goal selection by the user is not allowed, which means that the agent is expected to be able to pick goals autonomously.

When the method returns, observations can be found in the history field of the AbstractAgent class.


getObservationsAndGoal

public String getObservationsAndGoal()
                              throws Exception
Gathers the observations about the current time step. This is the method that agent loops are expected to invoke for the observation-gathering step. The user is also expected to select the agent's goal, which is returned by the method. When the method returns, observations can be found in the history field of the AbstractAgent class.
Returns:
the agent's goal

showSelectedGoal

public void showSelectedGoal(String goal)
Updates the GUI in order to show the goal selected by the agent.
Parameters:
goal - the goal selected by the agent

performPartOfPlan

public void performPartOfPlan(ActionSequence plan)
                       throws Exception
Performs the first compound action of the given plan. This is the method that agent loops are expected to invoke for the plan-execution step.
Parameters:
plan - the plan whose first compoud action must be performed

findDefinedTrajectories

public TrajectorySet findDefinedTrajectories(ActionSequence plan)
                                      throws Exception
Computes the set of trajectories defined by the given plan.
Parameters:
plan - the plan that defines the trajectories
Returns:
a TrajectorySet containing the trajectories defined by the plan

terminateLoop

public void terminateLoop()
                   throws TerminateLoopException
Terminates the agent loop. This method will cause the agent to abort the current step of the agent loop and halt execution.

terminateLoopNoPlan

public void terminateLoopNoPlan()
                         throws Exception
Terminates the agent loop. This method will cause the agent to abort the current step of the agent loop and halt execution. A dialog will be displayed, saying that no plans were returned by the inference engine.

terminateLoopNoModel

public void terminateLoopNoModel()
                          throws Exception
Terminates the agent loop. This method will cause the agent to abort the current step of the agent loop and halt execution. A dialog will be displayed, saying that no models were returned by the inference engine.

repeatIterationNoPlan

public void repeatIterationNoPlan()
                           throws Exception
Repeats the last iteration of the agent loop. This method will cause the agent to abort the current step of the agent loop and to go back to the first step of the loop. The current time step is not increased. A dialog will be displayed, saying that no plans were returned by the inference engine.

repeatIterationNoModel

public void repeatIterationNoModel()
                            throws Exception
Repeats the last iteration of the agent loop. This method will cause the agent to abort the current step of the agent loop and to go back to the first step of the loop. The current time step is not increased. A dialog will be displayed, saying that no models were returned by the inference engine.

repeatIteration

public void repeatIteration()
                     throws RepeatIterationException
Repeats the last iteration of the agent loop. This method will cause the agent to abort the current step of the agent loop and to go back to the first step of the loop. The current time step is not increased.

computeOneTrajectory

public Trajectory computeOneTrajectory(MathSet fileList,
                                       int currTime,
                                       int lastTime)
                                throws Exception
Computes one model of the given list of files, with the given values for A-Prolog parameters currtime and lasttime, and returns the Trajectory contained in the model.

If an error occurs during the execution of the inference engine, repeatIteration() is invoked.

Parameters:
fileList - the list of file names to be used by the inference engine
currTime - the value of A-Prolog parameter currtime
lastTime - the value of A-Prolog parameter lasttime
Returns:
the Trajectory contained in the model

computeAllTrajectories

public TrajectorySet computeAllTrajectories(MathSet fileList,
                                            int currTime,
                                            int lastTime)
                                     throws Exception
Computes all the models of the given list of files, with the given values for A-Prolog parameters currtime and lasttime, and returns the TrajectorySet represented by the models.

If an error occurs during the execution of the inference engine, repeatIteration() is invoked.

Parameters:
fileList - the list of file names to be used by the inference engine
currTime - the value of A-Prolog parameter currtime
lastTime - the value of A-Prolog parameter lasttime
Returns:
the TrajectorySet represented by the models

agentLoop

public abstract void agentLoop()
                        throws Exception
The agent loop. This is the method that implementations of the agent loop must define.

run

public void run()
Invoked only by the APLAgent Manager
Overrides:
run in class Thread