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,SingleGoalExecutionManager
-
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) booleancancelActionLearning(Symbol actor, Predicate newAction) voidCancel all goals currently found in the activeGoals colectionvoidCancel all goals currently found in either the pending or active Goals collectionsbooleancancelGoal(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 activevoidCancel all goals currently found in the pendingGoals collectionbooleancancelPendingGoalsByIndices(Predicate indicesPred) Cancels the upcoming pending goals at the supplied indices (Predicate in the form and(index1,index2,...))voidbooleancancelScheduledGoalsByIndices(Predicate indicesPred) Cancels the upcoming scheduled goals at the supplied indices (Predicate in the form and(index1,index2,...))cancelSystemGoals(Symbol agentTeam) Cancels a subset of active goals for the supplied agentTeam and all of its children.voidchangeLearningExecution(Symbol actor, Symbol status) voidconfigPruningMechanism(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) booleanendActionLearning(Symbol actor, Predicate newAction) voidEnds the frozen status for the supplied agent/teamprotected booleanexecuteGoal(Goal goal) Attempts to create an ActionInterpreter and begin execution of the supplied goal, checking action/state constraintsforgetTaughtAction(Predicate actionSignature) void'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.protected AgentTeamgetAgentTeam(Symbol name) getCurrentGoal(Symbol actor, int index) Get the n-th most recently submitted goal.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.longgetGoalPriority(long gid) Query the priority of a particular goal.getGoalPriorityTier(long gid) Query the priority tier of 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 listgetNextGoal(Symbol agent) getNextScheduledExecutionDate(long goalId) Get Date of next scheduled goal execution.getPastGoal(long gid) Get the goal for a particular past goal ID.Get a copied list of the previously executed goalsgetPendingGoal(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.getScheduledGoal(long goalId) Get ScheduledGoal instance with goal ID.Get a copied list of all scheduled goals which have either yet to be submitted, or are currently executing.getScheduledGoals(Symbol agentTeam) Get a copied list of all scheduled goals which have either yet to be submitted, or are currently executing for the supplied agentTeamGet main state machine.getSystemGoals(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.booleanhasGreaterPriority(long goalId, PriorityTier priorityTier, long priority) Compare the priority of the supplied goal against the supplied priority/priorityTier valuesprotected voidinit(StateMachine sm, RootContext rootContext, Collection<String> groups) voidinterruptWaitForLearningStateUpdate(Symbol agent, Predicate actionSignature) voidinterruptWaitForNextGoalStatusUpdate(long gid) booleanisLearnedAction(Predicate actionSignature) 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) loadLearnedActions(boolean addToDB) 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) booleanpauseActionLearning(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) booleanresumeActionLearning(Symbol actor, Predicate newAction) booleanresumeGoal(long gid) Search all goal collections and resume the goal with the supplied goal id if foundresumeSystemGoals(Symbol agentTeam) Resumes a subset of suspended goals for the supplied agentTeam and all of its children.voidsetActionLearningGuiFlag(boolean flag) voidsetGoalManagerNotifier(GoalManagerNotifier notifier) voidsetLearnedActionsFile(String filename) voidsetScheduledGoalsFile(String filename) protected booleanshouldSupersede(Goal newGoal, Set<Goal> activeGoals) voidshutdown()Shutdown this ExecutionManager.submitGoal(Goal g) 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 foundsuspendSystemGoals(Symbol agentTeam) Suspends a subset of an agentTeam's active goals.protected 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 foundbooleanupdateScheduledGoal(long goalId, Predicate update) Modify existing scheduled goal based on update predicate.voidwaitForActionLearningStart(Symbol actor, Predicate newAction) protected voidwaitForGoalStatus(Goal goal, GoalStatus status) Convenience method to wait until a particular goal has a particular goal status.booleanwaitForLearningStateUpdate(Symbol agent, Predicate actionSignature) waitForNextGoalStatusUpdate(long gid, long timeout) Wait until a particular goal has its goal status updated to any new value.waitForNextGoalStatusUpdate(long gid, long timeout, GoalStatus startStatus) protected GoalStatuswaitForNextGoalStatusUpdate(Goal goal, long timeout, GoalStatus startStatus) Wait until a particular goal has its goal status updated to any new value.void
-
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
-
getNextScheduledExecutionDate
Get Date of next scheduled goal execution. Returns null if goalId is for a non-scheduled goal, or if scheduled goal will not execute again.- Parameters:
goalId- scheduled goal ID- Returns:
- Date or null
-
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 goal- Returns:
- true if goal was added
-
interruptWaitForNextGoalStatusUpdate
public void interruptWaitForNextGoalStatusUpdate(long gid) -
waitForNextGoalStatusUpdate
Wait until a particular goal has its goal status updated to any new value.- Parameters:
gid- goal IDtimeout- time to wait in milliseconds- Returns:
- The GoalStatus after the soonest update occurred or the timeout duration elapsed without an update
-
waitForNextGoalStatusUpdate
-
waitForNextGoalStatusUpdate
Wait until a particular goal has its goal status updated to any new value.- Parameters:
goal-timeout-- Returns:
- The GoalStatus after the soonest update occurred or the timeout duration elapsed without an update
-
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 -
cancelPendingGoalsByIndices
Cancels the upcoming pending goals at the supplied indices (Predicate in the form and(index1,index2,...)) -
cancelScheduledGoalsByIndices
Cancels the upcoming scheduled goals at the supplied indices (Predicate in the form and(index1,index2,...)) -
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
-
suspendSystemGoals
-
suspendSystemGoals
Suspends a subset of an agentTeam's active goals. This method ignores goals with PriorityTier SKIPPENDING and scheduled goals. In order to accommodate some practical agent configurations with input methods' addressees, this method can act on the supplied agent or a single descendant which has an active goal. If multiple team members have disjoint active goals, this method will fail and return null.- Parameters:
agentTeam-- Returns:
- the suspended goals' ids or null.
-
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
-
resumeSystemGoals
-
resumeSystemGoals
Resumes a subset of suspended goals for the supplied agentTeam and all of its children. This method ignores goals with PriorityTier SKIPPENDING and scheduled goals. In order to accommodate some practical agent configurations with input methods' addressees, this method can act on the supplied agent or a single descendant which has an active goal. If multiple team members have disjoint active goals, this method will fail.- Parameters:
agentTeam-- Returns:
- the resumed goals' ids
-
getCurrentGoals
- Returns:
- A copied list of all current, pending, active, and scheduled 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
-
cancelPendingGoals
public void cancelPendingGoals()Cancel all goals currently found in the pendingGoals collection -
cancelCurrentGoals
public void cancelCurrentGoals()Cancel all goals currently found in either the pending or active Goals collections -
cancelActiveGoals
public void cancelActiveGoals()Cancel all goals currently found in the activeGoals colection -
cancelSystemGoals
-
cancelScheduledGoals
public void cancelScheduledGoals() -
cancelSystemGoals
Cancels a subset of active goals for the supplied agentTeam and all of its children. This method ignores goals with PriorityTier SKIPPENDING and scheduled goals. In order to accommodate some practical agent configurations with input methods' addressees, this method can act on the supplied agent or a single descendant which has an active goal. If multiple team members have disjoint active goals, this method will fail.- Parameters:
agentTeam-- Returns:
- the canceled goals' ids
-
getSystemGoals
-
getSystemGoals
-
getNextGoal
-
getNextGoal
-
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
-
getScheduledGoals
Get a copied list of all scheduled goals which have either yet to be submitted, or are currently executing.- Returns:
- shallow copy of scheduled goals
-
getScheduledGoals
Get a copied list of all scheduled goals which have either yet to be submitted, or are currently executing for the supplied agentTeam- Returns:
- shallow copy of scheduled goals
-
getScheduledGoal
Get ScheduledGoal instance with goal ID.- Parameters:
goalId- scheduled goal ID- Returns:
- ScheduledGoal or null
-
getPastGoal
Get the goal for a particular past goal ID.- Parameters:
gid- goal id.- Returns:
- the goal corresponding to the ID.
-
getGoalStatus
Query the GoalStatus of a particular goal.- Parameters:
gid- the ID of the goal to check on- Returns:
- GoalStatus object indicating the status
-
getGoalPriorityTier
Query the priority tier of a particular goal.- Parameters:
gid- the ID of the goal to check on- Returns:
- PriorityTier object indicating the priority tier
-
getGoalPriority
public long getGoalPriority(long gid) Query the priority of a particular goal.- Parameters:
gid- the ID of the goal to check on- Returns:
- long indicating the priority value
-
hasGreaterPriority
Compare the priority of the supplied goal against the supplied priority/priorityTier values -
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
-
updateScheduledGoal
Modify existing scheduled goal based on update predicate.- Parameters:
goalId- ID of scheduled goalupdate- update predicate- Returns:
- if update was successful
-
waitForActionLearningStart
-
learnAction
-
resumeActionLearning
-
endActionLearning
-
pauseActionLearning
-
cancelActionLearning
-
resumeActionLearning
-
endActionLearning
-
pauseActionLearning
-
cancelActionLearning
-
getLearningStatus
-
changeLearningExecution
-
modifyAction
-
forgetTaughtAction
-
loadLearnedActions
-
getLearnedActions
-
isLearnedAction
-
waitForLearningStateUpdate
-
interruptWaitForLearningStateUpdate
-
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 -
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.- Returns:
-
getRootContext
-
setActionLearningGuiFlag
public void setActionLearningGuiFlag(boolean flag) -
setScheduledGoalsFile
-
setGoalManagerNotifier
-
setLearnedActionsFile
-
getLearnedActionsFile
-
getActionLearningGuiFlag
public boolean getActionLearningGuiFlag() -
writeScheduledGoalsToFile
public void writeScheduledGoalsToFile() -
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
-