Package edu.tufts.hrilab.action.manager
Class ExecutionManager
java.lang.Object
edu.tufts.hrilab.action.manager.ExecutionManager
- All Implemented Interfaces:
GoalListener
- Direct Known Subclasses:
QueueExecutionManager
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnum used alongside goal notification updates to indicate whether the goal was added, removed, or already present in the relevant collection -
Field Summary
FieldsModifier and TypeFieldDescriptionTeam/Agent hierarchy information (transitive)Tree of AgentTeam Objects - contains all active goals spread throughout the hierarchyprotected edu.tufts.hrilab.action.manager.ExecutionManager.GoalComparatorComparison method determining the order goals get placed into the pendingGoals queue.protected final Objectprotected final TreeSet<PendingGoal>A collection of all the goals currently waiting to be executedprotected final Lockprotected final Objectprotected SymbolRoot AgentTeam in the hierarchy -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intactivateNextValidPendingGoal(int startSearchIndex) Transfers the highest priority goal from the pending collection which has all required resources available to activeprotected voidActivate as many pending goals as possible in order of priority while avoiding resource conflictsvoidAdd ActionListener to list to be notified of ActionInterpreter and StepExecution eventsbooleancancelActionLearning(Symbol actor, Predicate newAction) voidvoidvoidbooleancancelGoal(long gid) Search both pending and active goal collections and cancel the goal with the supplied goal id if foundbooleancancelPendingGoalByIndex(int index) Remove a pending goal based on index before it is transferred to activevoidchangeLearningExecution(Symbol actor, Symbol status) booleancheckIgnoreTentativeAccept(Predicate goalPred) Call ignoreTentativeAccept if service is present in the systemvoidconfigPruningMechanism(boolean pruneData, long pastHistoryLength) configure the pruning mechanismprotected booleanIndicates whether the supplied goal consumed any resources during execution.static ExecutionManagercreateInstance(Class<ExecutionManager> instanceType, StateMachine sm, RootContext rootContext, Collection<String> groups) booleanendActionLearning(Symbol actor, Predicate newAction) voidEnds the frozen status for the supplied agent/teamprotected booleanexecuteGoal(Goal goal, ExecutionType executionType) Attempts to create an ActionInterpreter and begin execution of the supplied goal, checking action/state constraintsvoid'Freezes' a team or agent and blocks until unfrozen.booleangetActionStatus(long gid) Query the ActionStatus of the action (i.e., root context for this goal) being executed in pursuit of the specified goal.getActiveGoal(long gid) Get an active goalgetActiveGoal(Symbol actor, int index) Get the n-th most recently started, currently running, goal.Get a copied list of the goals currently undergoing execution.getActiveGoals(Goal queryGoal) Get a list of the currently running goals matching the goalPredicate query.protected AgentTeamgetAgentTeam(Symbol name) getAllGoals(Goal queryGoal) Get a list of all pending, active, and past goals matching the goalPredicate query.getCurrentGoal(Symbol actor, int index) Get the n-th most recently submitted goal.getCurrentGoals(Goal queryGoal) Get a list of all current pending and/or active goals matching the goalPredicate query.getDescendants(Symbol agentTeam) Returns the names of the supplied agentTeam and all its children in the hierarchygetGoal(long gid) Get the goal for a particular goal ID.getGoalFailConditions(long gid) Get failure condition for a particular goal.getGoalStatus(long gid) Query the GoalStatus of a particular goal.getHeldResourcesForGoal(Goal goal) Returns the set of all Resources that will be held by the supplied goal during its execution.getLearningStatus(Symbol actor) getLockedResourceNames(Set<Resource> requiredResources) Returns the list of resource names which are locked from the supplied listgetNextGoalPredicate(Symbol agent) getPastGoal(long gid) Get the goal for a particular past goal ID.Get a copied list of the previously executed goalsgetPastGoals(Goal queryGoal) Get a list of all past goals matching the goalPredicate query.getPendingGoal(long gid) Get a pending goalGet a copied list of the currently managed pending goals waiting to begin execution.getRelevantAgents(Symbol agentTeam) Returns the set of AgentTeam(names) whose execution may be affected by a change in task for the supplied AgentTeam.Returns the set of all Resources required to be available during execution of the supplied goal.getResourceConflictingActiveGoals(Set<Resource> requiredResources) Return the set of all currently active goals which are occupying some subset of the supplied resource set.Get main state machine.getSystemGoalsPredicates(Symbol actor) voidgoalStatusChanged(GoalInfo info) Notify EM of goal status changes, so goal can be properly managed (e.g., moved to past goals).protected voidDetermines what is done to an added pending goal when resources are not available to execute the action.protected voidinit(StateMachine sm, RootContext rootContext, Collection<String> groups) joinOnGoal(long gid) Wait indefinitely for the goal to have terminal goal status.joinOnGoal(long gid, long millis) Wait (up to specified milliseconds) for the goal to have terminal goal status.protected voidjoinOnPendingGoal(long gid) Wait indefinitely for the matching pending goal to have its condition notified.booleanlearnAction(Symbol actor, Predicate newAction) voidmodifyAction(Symbol actor, Predicate action, Predicate modification, Predicate location) protected voidonActiveGoalUpdated(Goal g, GoalStatus status, ExecutionManager.UpdateType updateType) Callback triggered when an active goal's status has been updated.protected voidonPendingGoalUpdated(Goal g, int index, ExecutionManager.UpdateType updateType) Callback triggered when a pending goal's status has been updatedbooleanpauseActionLearning(Symbol actor, Predicate newAction) voidprotected booleanresourceConflictInPending(Goal g, int maxIndex) Returns a boolean indicating whether any goal up to maxIndex in the pending collection has a resource conflict with the supplied set.booleanresumeActionLearning(Symbol actor, Predicate newAction) booleanresumeGoal(long gid) Search all goal collections and resume the goal with the supplied goal id if foundvoidsetActionLearningGuiFlag(boolean flag) protected booleanshouldSupersede(Goal newGoal, Set<Goal> activeGoals) voidshutdown()Shutdown this ExecutionManager.submitGoal(Goal g, ExecutionType execType) Submits the goal the execution manager usingaddPendingGoal(PendingGoal).submitGoalContext(Goal g, Context context) Entry point to submit a context tree to be executed TODO: Should this be implemented by each subclass? - probably this is only used in PA right now and explicitly for SIMULATE_PERFORMANCE exec typesprotected voidsupersedeGoals(Goal newGoal, Set<Goal> activeGoals) Interrupt execution of the provided active goals and push them back to the pending collection, replacing them with execution of a new goal.booleansuspendGoal(long gid) Search all goal collections and suspend the goal with the supplied goal id if foundprotected voidtransferGoalToActive(Goal goal) Transfer a goal from pending goals to active goals, and start execution of the goal.protected voidtransferGoalToPastGoals(Goal goal) Searches for the supplied goal in the pending and active goal collections, moving it to pastGoals and performing the relevant bookkeeping if foundvoidwaitForActionLearningStart(Symbol actor, Predicate newAction) protected voidwaitForGoalStatus(Goal goal, GoalStatus status) Convenience method to wait until a particular goal has a particular goal status.
-
Field Details
-
goalComparator
protected edu.tufts.hrilab.action.manager.ExecutionManager.GoalComparator goalComparatorComparison method determining the order goals get placed into the pendingGoals queue. -
agentHierarchy
Team/Agent hierarchy information (transitive) -
rootAgent
Root AgentTeam in the hierarchy -
agentTeams
Tree of AgentTeam Objects - contains all active goals spread throughout the hierarchy -
resourceLock
-
goalsLock
-
pendingGoals
A collection of all the goals currently waiting to be executed -
pendingGoalsLock
-
-
Constructor Details
-
ExecutionManager
public ExecutionManager()
-
-
Method Details
-
init
-
createInstance
public static ExecutionManager createInstance(Class<ExecutionManager> instanceType, StateMachine sm, RootContext rootContext, Collection<String> groups) - Parameters:
instanceType- ExecutionManager class or subclass to be usedsm- state machine for root contextrootContext- base context at the root of all executiongroups- DIARC group constraints used to register this EM and its class instances that are registered with TRADE (e.g., ActionLearning)- Returns:
- ExecutionManager instance
-
getRelevantAgents
Returns the set of AgentTeam(names) whose execution may be affected by a change in task for the supplied AgentTeam. Practically, this returns the supplied agentTeam, its children, and all direct ancestors in the hierarchy -
getDescendants
Returns the names of the supplied agentTeam and all its children in the hierarchy -
resourceConflictInPending
Returns a boolean indicating whether any goal up to maxIndex in the pending collection has a resource conflict with the supplied set. A resource conflict occurs between two goals if one goal holds a resource during execution which the other goal either also needs to hold or requires to be available. Two goals with only overlapping required resources can coexist. -
activateValidPendingGoals
protected void activateValidPendingGoals()Activate as many pending goals as possible in order of priority while avoiding resource conflicts -
activateNextValidPendingGoal
protected int activateNextValidPendingGoal(int startSearchIndex) Transfers the highest priority goal from the pending collection which has all required resources available to active- Returns:
- the goal which was transferred to active for execution. If no such valid goal existed, returns null.
-
consumedResources
Indicates whether the supplied goal consumed any resources during execution. Used on goal completion to determine whether a check should be made for new goals to be submitted as a result of completion- Parameters:
g-- Returns:
- true if the completion of the supplied goal freed up any resources, false otherwise
-
getResourceConflictingActiveGoals
Return the set of all currently active goals which are occupying some subset of the supplied resource set. -
getLockedResourceNames
Returns the list of resource names which are locked from the supplied list -
getRequiredResourcesForGoal
Returns the set of all Resources required to be available during execution of the supplied goal. -
getHeldResourcesForGoal
Returns the set of all Resources that will be held by the supplied goal during its execution. -
onActiveGoalUpdated
protected void onActiveGoalUpdated(Goal g, GoalStatus status, ExecutionManager.UpdateType updateType) Callback triggered when an active goal's status has been updated.- Parameters:
g- the goal whose status has been updatedstatus- the new statusupdateType- indicates whether the active goal was newly added, already existed, or removed
-
onPendingGoalUpdated
Callback triggered when a pending goal's status has been updated- Parameters:
g- the goal whose status has been updatedindex- the index of the goal in the pendingGoals collection updateType indicates whether the active goal was newly added, already existed, or removed
-
handleConflictingLowerPriorityGoal
Determines what is done to an added pending goal when resources are not available to execute the action.- Parameters:
g- the goal that was added
-
submitGoal
Submits the goal the execution manager usingaddPendingGoal(PendingGoal). This goal will be added to the pool of goals under consideration by the execution manager. When and if execution of the provided goal occurs is subject to the ExecutionManager implementation. Generally, higher priority goals will be executed first.- Parameters:
g- the goal to be added- Returns:
- The duplicate goal if present, otherwise the newly submitted goal
-
joinOnGoal
Wait indefinitely for the goal to have terminal goal status.- Parameters:
gid- goal ID- Returns:
- GoalStatus of the goal
-
joinOnGoal
Wait (up to specified milliseconds) for the goal to have terminal goal status.- Parameters:
gid- goal IDmillis- maximum time to wait for terminal status- Returns:
- GoalStatus of the goal (may not be a terminal status)
-
shouldSupersede
- Parameters:
newGoal- new goal in questionactiveGoals- list of currently active goals to compare against- Returns:
- a boolean indicating whether the new goal's execution should take priority over all supplied active goals
-
supersedeGoals
Interrupt execution of the provided active goals and push them back to the pending collection, replacing them with execution of a new goal.- Parameters:
newGoal- the new goal to be executed after interruptionactiveGoals- a list of currently active goals to be pushed back to pending
-
transferGoalToActive
Transfer a goal from pending goals to active goals, and start execution of the goal. Note that the goal is not guaranteed to be in the active goals when this method returns. If the goal fails, for instance, the goal will automatically be moved to the past goals.- Parameters:
goal- the goal to transfer and execute
-
executeGoal
Attempts to create an ActionInterpreter and begin execution of the supplied goal, checking action/state constraints- Parameters:
goal- the goalexecutionType- goal type (act, simulation, ...)- Returns:
- true if goal was added
-
waitForGoalStatus
Convenience method to wait until a particular goal has a particular goal status. This relies on the GoalListener callback.- Parameters:
goal-status-
-
goalStatusChanged
Notify EM of goal status changes, so goal can be properly managed (e.g., moved to past goals).- Specified by:
goalStatusChangedin interfaceGoalListener- Parameters:
info- GoalInfo of the goal with changed status
-
transferGoalToPastGoals
Searches for the supplied goal in the pending and active goal collections, moving it to pastGoals and performing the relevant bookkeeping if found -
joinOnPendingGoal
protected void joinOnPendingGoal(long gid) Wait indefinitely for the matching pending goal to have its condition notified. Returns immediately if the goal is not found or pending. -
cancelGoal
public boolean cancelGoal(long gid) Search both pending and active goal collections and cancel the goal with the supplied goal id if found- Parameters:
gid-- Returns:
- boolean indicating whether the goal was found in one of the collections or not
-
cancelPendingGoalByIndex
public boolean cancelPendingGoalByIndex(int index) Remove a pending goal based on index before it is transferred to active -
suspendGoal
public boolean suspendGoal(long gid) Search all goal collections and suspend the goal with the supplied goal id if found- Parameters:
gid-- Returns:
- true if the goal was found and had an active status, otherwise false
-
resumeGoal
public boolean resumeGoal(long gid) Search all goal collections and resume the goal with the supplied goal id if found- Parameters:
gid-- Returns:
- true if the goal was found and had an active status, otherwise false
-
getCurrentGoals
- Returns:
- A copied list of all current pending and active goals
-
getActiveGoals
Get a copied list of the goals currently undergoing execution.- Returns:
- list of Goals
-
getPendingGoals
Get a copied list of the currently managed pending goals waiting to begin execution.- Returns:
- list of Goals
-
getPastGoals
Get a copied list of the previously executed goals- Returns:
- list of Goals
-
cancelAllPendingGoals
public void cancelAllPendingGoals() -
cancelAllCurrentGoals
public void cancelAllCurrentGoals() -
cancelAllActiveGoals
public void cancelAllActiveGoals() -
getPendingGoalsPredicates
-
getSystemGoalsPredicates
-
getSystemGoalsPredicates
-
getNextGoalPredicate
-
getNextGoalPredicate
-
getGoal
Get the goal for a particular goal ID. This checks pending, current, and past goals.- Parameters:
gid- goal id.- Returns:
- the goal corresponding to the ID.
-
getCurrentGoal
Get the n-th most recently submitted goal. 0 = most recently started goal, 1 = 2nd most recently started goal, etc.- Parameters:
actor- actor to consider currently running goals for (can be null, meaning all actors)index- into the currently running goals- Returns:
- n-th most recently start goal, or null if no n-th goal is being executed
-
getActiveGoal
Get the n-th most recently started, currently running, goal. 0 = most recently started goal, 1 = 2nd most recently started goal, etc.- Parameters:
actor- actor to consider currently running goals for (can be null, meaning all actors)index- into the currently running goals- Returns:
- n-th most recently start goal, or null if no n-th goal is being executed
-
getActiveGoal
Get an active goal- Parameters:
gid- goal id- Returns:
- the goal
-
getPendingGoal
Get a pending goal- Parameters:
gid- goal id- Returns:
- the goal
-
getPastGoal
Get the goal for a particular past goal ID.- Parameters:
gid- goal id.- Returns:
- the goal corresponding to the ID.
-
getActiveGoals
Get a list of the currently running goals matching the goalPredicate query.- Returns:
- goals with matching goalPredicate, or null if no matching goal found
-
getPastGoals
Get a list of all past goals matching the goalPredicate query.- Returns:
- goals with matching goalPredicate, or null if no matching goal found
-
getCurrentGoals
Get a list of all current pending and/or active goals matching the goalPredicate query.- Returns:
- goals with matching goalPredicate, or null if no matching goal found
-
getAllGoals
Get a list of all pending, active, and past goals matching the goalPredicate query.- Returns:
- goals with matching goalPredicate, or null if no matching goal found
-
getGoalStatus
Query the GoalStatus of a particular goal.- Parameters:
gid- the ID of the goal to check on- Returns:
- GoalStatus object indicating the status
-
getActionStatus
Query the ActionStatus of the action (i.e., root context for this goal) being executed in pursuit of the specified goal.- Parameters:
gid- the ID of the goal to check on- Returns:
- ActionStatus enum indicating the status
-
getGoalFailConditions
Get failure condition for a particular goal.- Parameters:
gid- the ID of the goal to check on- Returns:
- a list of Predicates describing the failure
-
waitForActionLearningStart
-
learnAction
-
resumeActionLearning
-
endActionLearning
-
pauseActionLearning
-
cancelActionLearning
-
getLearningStatus
-
changeLearningExecution
-
modifyAction
-
freeze
'Freezes' a team or agent and blocks until unfrozen. A frozen agent will have all current goals suspended and will not be able to begin execution of any new ones. Similarly, all members of a frozen team will be frozen. -
endFreeze
Ends the frozen status for the supplied agent/team -
checkIgnoreTentativeAccept
Call ignoreTentativeAccept if service is present in the system -
addAIListener
Add ActionListener to list to be notified of ActionInterpreter and StepExecution events- Parameters:
al- listener to be added
-
getAgentTeam
-
configPruningMechanism
public void configPruningMechanism(boolean pruneData, long pastHistoryLength) configure the pruning mechanism- Parameters:
pruneData- denotes if the goal manager should prune past goalspastHistoryLength- denotes length of time to keep past goals
-
pruneOldData
public void pruneOldData() -
getStateMachine
Get main state machine. NOTE: the @TRADEService should be removed once there's a cleaner way to get a plan for a goal without submitting a goal for execution. This is used in asl in a few places.- Returns:
-
getRootContext
-
setActionLearningGuiFlag
public void setActionLearningGuiFlag(boolean flag) -
getActionLearningGuiFlag
public boolean getActionLearningGuiFlag() -
shutdown
public void shutdown()Shutdown this ExecutionManager. All currently managed goals are canceled, ending the ActionInterpreter. Note: the goals are automagically moved to the pastGoals list by the ActionListener mechanism. -
submitGoalContext
Entry point to submit a context tree to be executed TODO: Should this be implemented by each subclass? - probably this is only used in PA right now and explicitly for SIMULATE_PERFORMANCE exec types- Parameters:
g- the goalcontext- the context tree which will be executed- Returns:
- the context which will be executed first
-