Package edu.tufts.hrilab.action.manager
Class ExecutionManager
java.lang.Object
edu.tufts.hrilab.action.manager.ExecutionManager
- All Implemented Interfaces:
ActionListener
- Direct Known Subclasses:
QueueExecutionManager
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enum 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.GoalComparator
Comparison method determining the order goals get placed into the pendingGoals queue.protected final Object
protected final TreeSet<PendingGoal>
A collection of all the goals currently waiting to be executedprotected final Lock
protected final Object
protected Symbol
Root AgentTeam in the hierarchy -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Cleans up references to completed actions/goals.void
protected Goal
Transfers the highest priority goal from the pending collection which has all required resources available to activeprotected void
Activate as many pending goals as possible in order of priority while avoiding resource conflictsvoid
Add ActionListener to list to be notified of ActionInterpreter and StepExecution eventsprotected void
addPendingGoal
(Goal g, ExecutionType execType) Adds a pending goal with default priority.protected void
addPendingGoal
(Goal g, ExecutionType execType, long priority) Adds a pending goal with default priority tier, but overridden value.protected void
addPendingGoal
(Goal g, ExecutionType execType, long priority, PriorityTier priorityTier) Add the goal to the pool of goals being considered by this execution manager.boolean
cancelGoal
(long gid) Search both pending and active goal collections and cancel the goal with the supplied goal id if foundboolean
checkIgnoreTentativeAccept
(Predicate goalPred) Call ignoreTentativeAccept if service is present in the systemvoid
configPruningMechanism
(boolean pruneData, long pastHistoryLength) configure the pruning mechanismprotected boolean
Indicates whether the supplied goal consumed any resources during execution.static ExecutionManager
createInstance
(Class<ExecutionManager> instanceType, StateMachine sm, RootContext rootContext, String priorityFile, Collection<String> groups) void
CallsendFreeze(Symbol)
for selfvoid
Ends the frozen status for the supplied agent/teamprotected boolean
executeGoal
(Goal goal, ExecutionType executionType) Attempts to create an ActionInterpreter and begin execution of the supplied goal, checking action/state constraintsvoid
freeze()
Callsfreeze(Symbol)
for the root AgentTeam in the hierarchyvoid
'Freezes' a team or agent and blocks until unfrozen.getActionStatus
(long gid) Query the ActionStatus of the action (i.e., root context for this goal) being executed in pursuit of the specified goal.getActiveGoal
(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.getActiveGoalStatus
(long gid) Query the GoalStatus of a particular goal.protected AgentTeam
getAgentTeam
(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.getLockedResourceNames
(Set<Resource> requiredResources) Returns the list of resource names which are locked from the supplied listGet a copied list of the previously executed goalsgetPastGoals
(Goal queryGoal) Get a list of all past goals matching the goalPredicate query.Get a copied list of the currently managed pending goals waiting to begin execution.long
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 in order to execute 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.protected Symbol
protected void
handleConflictingLowerPriorityGoal
(Goal g, Set<Resource> necessaryResources) Determines what is done to an added pending goal when resources are not available to execute the action.protected void
init
(StateMachine sm, RootContext rootContext, String priorityFile, 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 void
joinOnPendingGoal
(long gid) Wait indefinitely for the matching pending goal to have its condition notified.protected void
notifyUIActiveGoalUpdated
(Goal g, GoalStatus status, ExecutionManager.UpdateType updateType) protected void
notifyUIPendingGoalUpdated
(Goal g, int index, ExecutionManager.UpdateType updateType) protected void
onActiveGoalUpdated
(Goal g, GoalStatus status, ExecutionManager.UpdateType updateType) Callback triggered when an active goal's status has been updated.protected void
onPendingGoalUpdated
(Goal g, int index, ExecutionManager.UpdateType updateType) Callback triggered when a pending goal's status has been updatedvoid
protected boolean
resourceConflictInPending
(Set<Resource> requiredResources, int maxIndex) Returns a boolean indicating whether any goal up to maxIndex in the pending collection has a resource conflict with the supplied set.boolean
resumeGoal
(long gid) Search all goal collections and resume the goal with the supplied goal id if foundprotected boolean
shouldSupersede
(Goal newGoal, Set<Goal> activeGoals) void
showEditor
(String path) Display a GUI for this goal managervoid
shutdown()
Shutdown this ExecutionManager.void
stepComplete
(Context step) void
stepStarted
(Context step) submitGoal
(Goal g) Deprecated.submitGoal
(Goal g, ExecutionType execType) CallssubmitGoal(Goal, ExecutionType, long, PriorityTier)
with the default valuessubmitGoal
(Goal g, ExecutionType execType, long priority) CallssubmitGoal(Goal, ExecutionType, long, PriorityTier)
with the default valuessubmitGoal
(Goal g, ExecutionType execType, long priority, PriorityTier priorityTier) Submits the goal the execution manager usingaddPendingGoal(Goal, ExecutionType, long, PriorityTier)
.CallssubmitGoal(Goal, ExecutionType, long, PriorityTier)
with the default valuessubmitGoal
(Predicate g, ExecutionType executionType) CallssubmitGoal(Goal, ExecutionType, long, PriorityTier)
with the default valuessubmitGoal
(Predicate g, ExecutionType execType, long priority) CallssubmitGoal(Goal, ExecutionType, long, PriorityTier)
with the default valuessubmitGoal
(Predicate g, ExecutionType execType, long priority, PriorityTier priorityTier) CallssubmitGoal(Goal, ExecutionType, long, PriorityTier)
with the default valuessubmitGoal
(Predicate g, Predicate metric) long
submitGoal
(Predicate g, Symbol priorityTierSymbol) submitGoalContext
(Goal g, Context context) Entry point to submit a context tree to be executedprotected void
Interrupt execution of the provided active goals and push them back to the pending collection, replacing them with execution of a new goal.boolean
suspendGoal
(long gid) Search all goal collections and suspend the goal with the supplied goal id if foundprotected void
transferGoalToActive
(Goal goal) Transfer a goal from pending goals to active goals, and start execution of the goal.protected void
transferGoalToPastGoals
(Goal goal) Searches for the supplied goal in the pending and active goal collections, moving it to pastGoals and performing the relevant bookkeeping if found
-
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
protected void init(StateMachine sm, RootContext rootContext, String priorityFile, Collection<String> groups) -
createInstance
public static ExecutionManager createInstance(Class<ExecutionManager> instanceType, StateMachine sm, RootContext rootContext, String priorityFile, Collection<String> groups) - Parameters:
instanceType
- ExecutionManager class or subclass to be usedsm
- state machine for root contextrootContext
- base context at the root of all executionpriorityFile
- the path to the file starting from config.action.manager.priority containing goal priority informationgroups
- 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. -
activateValidPendingGoals
protected void activateValidPendingGoals()Activate as many pending goals as possible in order of priority while avoiding resource conflicts -
activateNextValidPendingGoal
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 in order to execute the supplied goal. -
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 addednecessaryResources
- the required resources which are unavailable
-
getPriorityTierForGoal
-
getPriorityForGoal
-
submitGoal
-
submitGoal
Deprecated. -
submitGoal
CallssubmitGoal(Goal, ExecutionType, long, PriorityTier)
with the default values -
submitGoal
CallssubmitGoal(Goal, ExecutionType, long, PriorityTier)
with the default values -
submitGoal
-
submitGoal
CallssubmitGoal(Goal, ExecutionType, long, PriorityTier)
with the default values -
submitGoal
CallssubmitGoal(Goal, ExecutionType, long, PriorityTier)
with the default values -
submitGoal
CallssubmitGoal(Goal, ExecutionType, long, PriorityTier)
with the default values -
submitGoal
public Goal submitGoal(Predicate g, ExecutionType execType, long priority, PriorityTier priorityTier) CallssubmitGoal(Goal, ExecutionType, long, PriorityTier)
with the default values -
submitGoal
Submits the goal the execution manager usingaddPendingGoal(Goal, ExecutionType, long, PriorityTier)
. This goal will be added to the pool of goals under consideration by the execution manager- 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
-
actionComplete
Cleans up references to completed actions/goals. Also resets the slice time now that there is one less action. Remove a script interpreter from the goal manager.- Specified by:
actionComplete
in interfaceActionListener
- Parameters:
ai
- the AI to remove
-
actionStarted
- Specified by:
actionStarted
in interfaceActionListener
-
stepComplete
- Specified by:
stepComplete
in interfaceActionListener
-
stepStarted
- Specified by:
stepStarted
in interfaceActionListener
-
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. -
addPendingGoal
Adds a pending goal with default priority. SeeaddPendingGoal(Goal, ExecutionType, long, PriorityTier)
-
addPendingGoal
Adds a pending goal with default priority tier, but overridden value. SeeaddPendingGoal(Goal, ExecutionType, long, PriorityTier)
-
addPendingGoal
protected void addPendingGoal(Goal g, ExecutionType execType, long priority, PriorityTier priorityTier) Add the goal to the pool of goals being considered by this 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 submitted goalexecType
- the execution type of the submitted goalpriority
- priority value of the provided goalpriorityTier
- priority tier of the provided goal
-
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
-
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 PendingGoals
-
getPastGoals
Get a copied list of the previously executed goals- Returns:
- list of Goals
-
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
-
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
-
getActiveGoalStatus
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
-
freeze
public void freeze()Callsfreeze(Symbol)
for the root AgentTeam in the hierarchy -
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
public void endFreeze()CallsendFreeze(Symbol)
for self -
endFreeze
Ends the frozen status for the supplied agent/team -
checkIgnoreTentativeAccept
Call ignoreTentativeAccept if service is present in the system -
notifyUIActiveGoalUpdated
protected void notifyUIActiveGoalUpdated(Goal g, GoalStatus status, ExecutionManager.UpdateType updateType) -
notifyUIPendingGoalUpdated
protected void notifyUIPendingGoalUpdated(Goal g, int index, ExecutionManager.UpdateType updateType) -
addAIListener
Add ActionListener to list to be notified of ActionInterpreter and StepExecution events- Parameters:
al
- listener to be added
-
getUntypedSymbol
-
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() -
showEditor
Display a GUI for this goal manager -
getStateMachine
-
getRootContext
-
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- Parameters:
g
- the goalcontext
- the context tree which will be executed- Returns:
- the context which will be executed first
-