Class ExplanationFirstSearch
- All Implemented Interfaces:
Worker.Getter<Result<CompiledAction>>
progression
search that requires every action in a plan to be explained before it will consider
adding additional actions to the plan. Specifically, every action in a plan
must be explained for every consenting
character except the character
associated with the plan before more actions can be added to a plan.
When an action is added to a plan expanded, branches are created for each of
the action's consenting characters to explain why they would take that
action. The search prioritizes
branches with deeper epistemic
depth, meaning that a node's branches will be visited before the node
itself. By the time the trunk is visited, if it has not been explained for
all characters except the node's
character, then some attempt to explain the action for one of its characters
must have failed, and the plan can be removed from consideration.
- Author:
- Stephen G. Ware
-
Field Summary
Fields inherited from class ProgressionSearch
actions, cost, explanationPruning, heuristic, problem, queue, spaceFields inherited from class Search
authorTemporalLimit, characterTemporalLimit, epistemicLimit, searchLimit, spaceLimit, timeLimit -
Constructor Summary
ConstructorsConstructorDescriptionExplanationFirstSearch(CompiledProblem problem, ProgressionCost cost, ProgressionCost heuristic, EventTree<CompiledAction> actions, ProgressionSpace<?> space, long searchLimit, long spaceLimit, long timeLimit, int authorTemporalLimit, int characterTemporalLimit, int epistemicLimit, boolean explanationPruning) Constructs a new explanation-first progression search. -
Method Summary
Modifier and TypeMethodDescriptionprotected <N> doublecompare(edu.uky.cs.nil.sabre.prog.SearchNode<N> node1, edu.uky.cs.nil.sabre.prog.SearchNode<N> node2) Defines the priority in whichsearch nodesshould be visited.protected <N> booleanprune(edu.uky.cs.nil.sabre.prog.SearchNode<N> node) Determines whether asearch nodeshould be pruned (that is, not visited).voidSets the initial state of the world from which a solutionplanmust be executable.protected voidsetStatus(Worker.Status status, Progress<CompiledAction> progress) toString()protected voidupdateStatus(Worker.Status status, Progress<CompiledAction> progress) Updates the status during asearch.protected <N> booleanvisit(edu.uky.cs.nil.sabre.prog.SearchNode<N> node) Performs one iteration of the search on the givensearch node.Methods inherited from class ProgressionSearch
expand, expand, explain, getGenerated, getGoal, getStart, getVisited, push, run, setGoal, toString
-
Constructor Details
-
ExplanationFirstSearch
public ExplanationFirstSearch(CompiledProblem problem, ProgressionCost cost, ProgressionCost heuristic, EventTree<CompiledAction> actions, ProgressionSpace<?> space, long searchLimit, long spaceLimit, long timeLimit, int authorTemporalLimit, int characterTemporalLimit, int epistemicLimit, boolean explanationPruning) Constructs a new explanation-first progression search.- Parameters:
problem- the compiled problem to be solvedcost- a function to measure the cost of a plan so farheuristic- a function to estimate the cost of making a plan into a solutionactions- an event tree of all actions that can be taken during searchspace- the model of states that will be searchedsearchLimit- the max number of nodes that can be visitedspaceLimit- the max number of nodes that can be generatedtimeLimit- the max number of milliseconds a search can takeauthorTemporalLimit- the max number of actions in the main plancharacterTemporalLimit- the max number of actions a character can imagine when trying to explain its actionsepistemicLimit- the max depth in a character's theory of mind to searchexplanationPruning- whether the search should stop exploring a branch once its root has been explained
-
-
Method Details
-
toString
- Overrides:
toStringin classProgressionSearch
-
setStart
Description copied from class:SearchSets the initial state of the world from which a solutionplanmust be executable. This method resets this search object, meaning it should discard its internal state, should start over (from the newly set initial state) the next timeSearch.get(Status)is called, and may reset counters such asthe number of nodes visited.- Overrides:
setStartin classProgressionSearch- Parameters:
state- the new initial state of the world before planning begins
-
setStatus
Description copied from class:ProgressionSearchSets the message and parameters of thestatusthat will be updated during thesearch. This method will be called once at the beginning of a new search, and the status will be periodically updated viaProgressionSearch.updateStatus(Status, Progress).- Overrides:
setStatusin classProgressionSearch- Parameters:
status- the status object whose message and parameters will be setprogress- the progress object for the search that is just starting
-
updateStatus
Description copied from class:ProgressionSearchUpdates the status during asearch. This method will be called after visiting each node during the search, but only afterProgressionSearch.setStatus(Status, Progress)has been called once for this search.- Overrides:
updateStatusin classProgressionSearch- Parameters:
status- the status object to updateprogress- the progress object for the current search
-
prune
protected <N> boolean prune(edu.uky.cs.nil.sabre.prog.SearchNode<N> node) Determines whether asearch nodeshould be pruned (that is, not visited). This method is called beforeProgressionSearch.visit(SearchNode), and it it returns true, the node will not be visited.By default, this method returns true only when
explanation pruningis on, the node'sepistemic depthis greater than 0, and the given node'srootisexplained.During explanation-first search, any node which has not been explained for all of its
consenting charactersexcept forthe node's characterwill be pruned. When a node is expanded, all of its branches are also added to the queue, and explanation-first search prioritizes nodes with higher epistemic depth. This means that all of a node's branches will be searched before the trunk, so before a node is visited, if any of its branches are not explained, it is because the search failed to find an explanation for the character of that branch and thus the action can never be explained.- Overrides:
prunein classProgressionSearch- Type Parameters:
N- the type of object used to represent a node inthe search space- Parameters:
node- the search node that is about to be visited if it is not pruned- Returns:
- true if the search node should be pruned (that is, not visited), or false if the node should be visited
-
visit
protected <N> boolean visit(edu.uky.cs.nil.sabre.prog.SearchNode<N> node) Description copied from class:ProgressionSearchPerforms one iteration of the search on the givensearch node. One iteration usually means removing one node from thequeue,visitingthat node, and possiblyadding more nodes to the queue. If this method returns true,the number of visited nodeswill be incremented by one, otherwise it will not be incremented.By default, this method simply calls
ProgressionSearch.expand(SearchNode)with the same node and returns true.- Overrides:
visitin classProgressionSearch- Type Parameters:
N- the type of object used to represent a node inthe search space- Parameters:
node- the search node to be visited- Returns:
- true if the number of visited nodes should be incremented, false otherwise
-
compare
protected <N> double compare(edu.uky.cs.nil.sabre.prog.SearchNode<N> node1, edu.uky.cs.nil.sabre.prog.SearchNode<N> node2) Defines the priority in whichsearch nodesshould be visited. This method follows the contract ofComparator.compare(Object, Object), except that it returns adoubleinstead of anint. In other words, this method should return a negative number if the first node should be visited before the second node, a positive number if the second node should be visited before the first, or 0 if the order does not matter.By default, this method prioritizes nodes in this order:
- The node with the lowest
costplusheuristicvalue is first. - In case of a tie, the node with the lowest heuristic value is first.
- In case of a further tie, the node with the lowest
temporal depthis first. - In case of a further tie, the node with the lowest
epistemic depthis first. - In case of a further tie, the
root for both nodesare compared. - In case of a further tie, the
node objects of both nodesare compared.
During explanation-first search, nodes with higher epistemic depth are visited first to ensure a node's branches are always searched before the node (the trunk) is searched.
- Overrides:
comparein classProgressionSearch- Type Parameters:
N- the type of object used to represent a node inthe search space- Parameters:
node1- the first node to be comparednode2- the second node to be compared- Returns:
- a negative double, zero, or a positive double as the first node is higher priority, the same priority, or lower priority than the second node
- The node with the lowest
-