|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--AbstractAgent
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 |
public AgentFiles aFiles
public DomainFiles dFiles
public Engine engine
public History history
public MathSet fluents
public MathSet actions
public MathSet agentActions
public MathSet exogenousActions
public MathSet goals
public int currTime
public String tempFile
Constructor Detail |
public AbstractAgent()
public AbstractAgent(String agentParamsClassName) throws ClassNotFoundException, InstantiationException, IllegalAccessException
agentParamsClassName
- the name of the parameter classMethod Detail |
public void initialize(APLAgentMgr p, AgentFiles af, DomainFiles df, History h, Vector g, File tf, Engine e, AgentParams ap)
public void updateAgentFiles(AgentFiles af)
public void updateGoals(Vector g, DomainFiles df)
public AgentParams getAgentParams()
public void clearTempFile(String tf)
tf
- the name of the temporary filepublic void appendHistory(String tf)
tf
- the name of the temporary filepublic void appendPlan(String tf, ActionSequence plan, int currTime)
tf
- the name of the temporary fileplan
- the plan to be appended to the filecurrTime
- the first time step to be appendedpublic void appendText(String tf, String lit)
tf
- the name of the temporary filelit
- the string to be appendedpublic void log(String s)
s
- the line to be appendedpublic void getObservations(boolean goalSelection) throws Exception
When the method returns, observations can be found in the history field of the AbstractAgent class.
goalSelection
- true if goal selection is allowed; false otherwisepublic void getObservations() throws Exception
When the method returns, observations can be found in the history field of the AbstractAgent class.
public String getObservationsAndGoal() throws Exception
public void showSelectedGoal(String goal)
goal
- the goal selected by the agentpublic void performPartOfPlan(ActionSequence plan) throws Exception
plan
- the plan whose first compoud action must be performedpublic TrajectorySet findDefinedTrajectories(ActionSequence plan) throws Exception
plan
- the plan that defines the trajectoriespublic void terminateLoop() throws TerminateLoopException
public void terminateLoopNoPlan() throws Exception
public void terminateLoopNoModel() throws Exception
public void repeatIterationNoPlan() throws Exception
public void repeatIterationNoModel() throws Exception
public void repeatIteration() throws RepeatIterationException
public Trajectory computeOneTrajectory(MathSet fileList, int currTime, int lastTime) throws Exception
If an error occurs during the execution of the inference engine, repeatIteration() is invoked.
fileList
- the list of file names to be used by the inference enginecurrTime
- the value of A-Prolog parameter currtimelastTime
- the value of A-Prolog parameter lasttimepublic TrajectorySet computeAllTrajectories(MathSet fileList, int currTime, int lastTime) throws Exception
If an error occurs during the execution of the inference engine, repeatIteration() is invoked.
fileList
- the list of file names to be used by the inference enginecurrTime
- the value of A-Prolog parameter currtimelastTime
- the value of A-Prolog parameter lasttimepublic abstract void agentLoop() throws Exception
public void run()
run
in class Thread
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |