/** * Extracts the state from a search node. * * @param searchNode The search node. * * @return The state of the search node. */ public T apply(SearchNode<O, T> searchNode) { return searchNode.getState(); } }
/** * Creates the correct type of search nodes for this search. This search uses ordinary search nodes. * * @param state The search space state to create a search node for. * * @return The state encapsulated in an ordinary search node. */ public SearchNode<O, T> createSearchNode(T state) { return new SearchNode<O, T>(state); }
/** * Provides a default implementation of the {@link BoundProperty} interface to extract the depth as the bound * property. * * @param searchNode The search node to check the bounded property of. * * @return The search depth of the node. */ public float getBoundProperty(SearchNode searchNode) { return (float) searchNode.getDepth(); }
/** * Back-tracks from the specified node, moving succesively upwards through the chain of parent nodes, until a node * is encountered that has unexamined successors. This method implements the backtracking searches reverse * direction. By checking for the presence of unexamined successors, this method only backtracks where necessary. * * @param checkNode The search node to start back-tracking from. */ protected void backtrack(SearchNode checkNode) { while ((checkNode != null) && (checkNode.unexaminedSuccessorCount == 0)) { Reversable undoState = (ReTraversable) checkNode.getState(); undoState.undoOperator(); checkNode = checkNode.getParent(); } } }
while (!goalPredicate.evaluate(currentReverseNode.getState())) SearchNode<O, T> reverseParentNode = currentReverseNode.getParent(); T state = currentReverseNode.getParent().getState(); Operator<O> operation = currentReverseNode.getAppliedOp(); float cost = currentReverseNode.getPathCost() - reverseParentNode.getPathCost(); currentForwardNode = currentForwardNode.makeNode(new Successor<O>(state, operation, cost));
if (!headNode.isExpanded()) headNode.expandSuccessors(queue, reverseEnqueue); if (currentNode.isExpanded()) if (goalPredicate.evaluate(currentNode.getState()))
Reversable reversableState = (ReTraversable) headNode.getState(); reversableState.applyOperator(); headNode.unexaminedSuccessorCount = headNode.expandSuccessors(queue, reverseEnqueue); if (headNode.getParent() != null) headNode.getParent().unexaminedSuccessorCount--; if (goalPredicate.evaluate(headNode.getState()))
forwardFringe.remove(currentForwardNode.getState()); if (reverseFringe.containsKey(currentForwardNode.getState())) return joinBothPaths(currentForwardNode, reverseFringe.get(currentForwardNode.getState())); currentForwardNode.expandSuccessors(newStates, false); forwardFringe.put(nextSearchNode.getState(), nextSearchNode); reverseFringe.remove(currentReverseNode.getState()); if (forwardFringe.containsKey(currentReverseNode.getState())) return joinBothPaths(forwardFringe.get(currentReverseNode.getState()), currentReverseNode); currentReverseNode.expandSuccessors(newStates, false); reverseFringe.put(nextSearchNode.getState(), nextSearchNode);
/** * Provides an implementation of the {@link BoundProperty} interface to extract the cost as the bound property. * * @param searchNode The search node to extract the bound property for. * * @return The path cost of the supplied search node. The bound property to control the bounded algorithm is the * path cost. */ public float getBoundProperty(SearchNode searchNode) { return searchNode.getPathCost(); } }
newNode.setRepeatedStateFilter(repeatedStateFilter);
/** * Returns a new node based on a successor of this node. This new node will also be a HeuristicSearchNode. * * @param successor The successor state in the search space to create a new node for. * * @return A completely new heuristic search node for the successor state. This node will be of the correct * class, even for classes that sub-class this one. * * @exception SearchNotExhaustiveException If a new node cannot be created. This may happen due to class visibility * or class loading problems. */ public HeuristicSearchNode<O, T> makeNode(Successor successor) throws SearchNotExhaustiveException { HeuristicSearchNode<O, T> node = (HeuristicSearchNode<O, T>) super.makeNode(successor); // Make sure the new node has a reference to the heuristic evaluator node.heuristic = this.heuristic; // Compute h for the new node node.computeH(); return node; }
while (!goalPredicate.evaluate(currentReverseNode.getState())) SearchNode<O, T> reverseParentNode = currentReverseNode.getParent(); T state = currentReverseNode.getParent().getState(); Operator<O> operation = currentReverseNode.getAppliedOp(); float cost = currentReverseNode.getPathCost() - reverseParentNode.getPathCost(); currentForwardNode = currentForwardNode.makeNode(new Successor<O>(state, operation, cost));
if (!headNode.isExpanded()) headNode.expandSuccessors(queue, reverseEnqueue); if (currentNode.isExpanded()) if (goalPredicate.evaluate(currentNode.getState()))
ReTraversable reversableState = (ReTraversable) headNode.getState(); reversableState.applyOperator(); headNode.unexaminedSuccessorCount = headNode.expandSuccessors(queue, reverseEnqueue); if (headNode.getParent() != null) headNode.getParent().unexaminedSuccessorCount--; if (goalPredicate.evaluate(headNode.getState()))
/** * Back-tracks from the specified node, moving succesively upwards through the chain of parent nodes, until a node * is encountered that has unexamined successors. This method implements the backtracking searches reverse * direction. By checking for the presence of unexamined successors, this method only backtracks where necessary. * * @param checkNode The search node to start back-tracking from. */ protected void backtrack(SearchNode checkNode) { while ((checkNode != null) && (checkNode.unexaminedSuccessorCount == 0)) { ReTraversable undoState = (ReTraversable) checkNode.getState(); undoState.undoOperator(); checkNode = checkNode.getParent(); } } }
forwardFringe.remove(currentForwardNode.getState()); if (reverseFringe.containsKey(currentForwardNode.getState())) return joinBothPaths(currentForwardNode, reverseFringe.get(currentForwardNode.getState())); currentForwardNode.expandSuccessors(newStates, false); forwardFringe.put(nextSearchNode.getState(), nextSearchNode); reverseFringe.remove(currentReverseNode.getState()); if (forwardFringe.containsKey(currentReverseNode.getState())) return joinBothPaths(forwardFringe.get(currentReverseNode.getState()), currentReverseNode); currentReverseNode.expandSuccessors(newStates, false); reverseFringe.put(nextSearchNode.getState(), nextSearchNode);
/** * Provides an implementation of the {@link BoundProperty} interface to extract the cost as the bound property. * * @param searchNode The search node to extract the bound property for. * * @return The path cost of the supplied search node. The bound property to control the bounded algorithm is the * path cost. */ public float getBoundProperty(SearchNode searchNode) { return searchNode.getPathCost(); } }
newStartNode.setRepeatedStateFilter(repeatedStateFilter);