/** * 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(); } }
/** * 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(); } }
/** {@inheritDoc} */ public ResolutionState search() throws SearchNotExhaustiveException { SearchNode<ResolutionState, ResolutionState> path = findGoalPath(); if (path != null) { return path.getState(); } else { return null; } }
/** * Constructor that takes an initial search node, a goal node, a forward and a reverse search queue implementation. * Different kinds of searches can be instantiated by passing different queue and search nodeimplementations to this * constructor. * * @param startNode The search start point as a search node. * @param goalNode The search end point as a search node. * @param forwardQueue The queue implementation for the forward search. * @param reverseQueue The queue implmenetation for the reverse search. */ public BaseBiDirectionalQueueSearch(SearchNode<O, T> startNode, SearchNode<O, T> goalNode, Queue<SearchNode<O, T>> forwardQueue, Queue<SearchNode<O, T>> reverseQueue) { this.forwardQueue = forwardQueue; this.reverseQueue = reverseQueue; this.startNode = startNode; this.goalNode = goalNode; // Clear both fringe sets forwardFringe = new HashMap<T, SearchNode<O, T>>(); reverseFringe = new HashMap<T, SearchNode<O, T>>(); // Add just the start node to the forward queue and fringe set to begin with forwardQueue.add(startNode); forwardFringe.put(startNode.getState(), startNode); // Add just the goal node to the reverse queue and fringe set to begin with reverseQueue.add(goalNode); reverseFringe.put(goalNode.getState(), goalNode); }
/** * Constructor that takes an initial search node, a goal node, a forward and a reverse search queue implementation. * Different kinds of searches can be instantiated by passing different queue and search nodeimplementations to this * constructor. * * @param startNode The search start point as a search node. * @param goalNode The search end point as a search node. * @param forwardQueue The queue implementation for the forward search. * @param reverseQueue The queue implmenetation for the reverse search. */ public BaseBiDirectionalQueueSearch(SearchNode<O, T> startNode, SearchNode<O, T> goalNode, Queue<SearchNode<O, T>> forwardQueue, Queue<SearchNode<O, T>> reverseQueue) { this.forwardQueue = forwardQueue; this.reverseQueue = reverseQueue; this.startNode = startNode; this.goalNode = goalNode; // Clear both fringe sets forwardFringe = new HashMap<T, SearchNode<O, T>>(); reverseFringe = new HashMap<T, SearchNode<O, T>>(); // Add just the start node to the forward queue and fringe set to begin with forwardQueue.add(startNode); forwardFringe.put(startNode.getState(), startNode); // Add just the goal node to the reverse queue and fringe set to begin with reverseQueue.add(goalNode); reverseFringe.put(goalNode.getState(), goalNode); }
/** * Perform the search. This can be called multiple times to get successive results where more than one goal can be * found, if the algorithm supports this. In this case it should return null once no more goals can be found. * * @return The first state corresponding to a goal state that is found or null if none can be found after exhaustive * searching. A return value of null should really mean that exhaustive searching has been completed rather * than some premature termination condition being reached. See the comment below about the * SearchNotExhaustiveException. * * @throws SearchNotExhaustiveException If the search stops before finding a solution or exhausting the search * space. Different search algorithms may fail for different reasons but in * particular it it is worth noting that if the maximum number of steps is * reached without exhausting the search space this will cause an exception to * be thrown rather than for this method to return null. */ public T search() throws SearchNotExhaustiveException { SearchNode<O, T> path = findGoalPath(); if (path != null) { return path.getState(); } else { return null; } }
/** * Perform the search. This can be called multiple times to get successive results where more than one goal can be * found, if the algorithm supports this. In this case it should return null once no more goals can be found. * * @return The first state corresponding to a goal state that is found or null if none can be found after exhaustive * searching. A return value of null should really mean that exhaustive searching has been completed rather * than some premature termination condition being reached. See the comment below about the * SearchNotExhaustiveException. * * @throws SearchNotExhaustiveException If the search stops before finding a solution or exhausting the search * space. Different search algorithms may fail for different reasons but in * particular it it is worth noting that if the maximum number of steps is * reached without exhausting the search space this will cause an exception to * be thrown rather than for this method to return null. */ public T search() throws SearchNotExhaustiveException { SearchNode<O, T> path = findGoalPath(); if (path != null) { return path.getState(); } else { return null; } }
/** * Perform the search. This can be called multiple times to get successive results where more than one goal can be * found, if the algorithm supports this. In this case it should return null once no more goals can be found. * * @return The first state corresponding to a goal state that is found or null if none can be found after exhaustive * searching. A return value of null should really mean that exhaustive searching has been completed rather * than some premature termination condition being reached. See the comment below about the * SearchNotExhaustiveException. * * @throws SearchNotExhaustiveException If the search stops before finding a solution or exhausting the search * space. Different search algorithms may fail for different reasons but in * particular it it is worth noting that if the maximum number of steps is * reached without exhausting the search space this will cause an exception to * be thrown rather than for this method to return null. */ public T search() throws SearchNotExhaustiveException { SearchNode<O, T> path = findGoalPath(); if (path != null) { return path.getState(); } else { return null; } }
/** * Perform the search. This can be called multiple times to get successive results where more than one goal can be * found, if the algorithm supports this. In this case it should return null once no more goals can be found. * * @return The first state corresponding to a goal state that is found or null if none can be found after exhaustive * searching. A return value of null should really mean that exhaustive searching has been completed rather * than some premature termination condition being reached. See the comment below about the * SearchNotExhaustiveException. * * @throws SearchNotExhaustiveException If the search stops before finding a solution or exhausting the search * space. Different search algorithms may fail for different reasons but in * particular it it is worth noting that if the maximum number of steps is * reached without exhausting the search space this will cause an exception to * be thrown rather than for this method to return null. */ public T search() throws SearchNotExhaustiveException { SearchNode<O, T> path = findGoalPath(); if (path != null) { return path.getState(); } else { return null; } }
forwardFringe.remove(currentForwardNode.getState()); if (reverseFringe.containsKey(currentForwardNode.getState())) return joinBothPaths(currentForwardNode, reverseFringe.get(currentForwardNode.getState())); forwardFringe.put(nextSearchNode.getState(), nextSearchNode); reverseFringe.remove(currentReverseNode.getState()); if (forwardFringe.containsKey(currentReverseNode.getState())) return joinBothPaths(forwardFringe.get(currentReverseNode.getState()), currentReverseNode); reverseFringe.put(nextSearchNode.getState(), nextSearchNode);
/** * 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(); } } }
/** * 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(); } } }
for (Iterator<Successor<O>> successors = getState().successors(reverse); successors.hasNext();)
for (Iterator<Successor<O>> successors = getState().successors(reverse); successors.hasNext();)
HierarchyLabelState goalLabel = goal.getState(); List<String> goalPath = goalLabel.getPath();
TreeSearchState<CategoryNode> goalState = (TreeSearchState<CategoryNode>) goal.getState();
TreeSearchState<CategoryNode> goalState = (TreeSearchState<CategoryNode>) goal.getState();