Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ruediger.lunde@gmail.com committed Apr 17, 2016
1 parent cee1dd3 commit 4fec2e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Expand Up @@ -96,10 +96,10 @@ public List<Action> search(Problem problem, Queue<Node> frontier) {
while (!isFrontierEmpty() && !CancelableThread.currIsCanceled()) {
// choose a leaf node and remove it from the frontier
ExtendedNode nodeToExpand = (ExtendedNode) popNodeFromFrontier();
ExtendedNode nodeFromOtherProblem;

// if the node contains a goal state then return the
// corresponding solution
ExtendedNode nodeFromOtherProblem;

if (!checkGoalBeforeAddingToFrontier
&& (nodeFromOtherProblem = getCorrespondingNodeFromOtherProblem(nodeToExpand)) != null)
return getSolution(orgP, nodeToExpand, nodeFromOtherProblem);
Expand Down Expand Up @@ -172,10 +172,7 @@ protected Node popNodeFromFrontier() {
*/
@Override
protected boolean isFrontierEmpty() {
while (!frontier.isEmpty()) {
Node result = frontier.peek();
if (!isExplored(result))
break;
while (!frontier.isEmpty() && isExplored(frontier.peek())) {
frontier.pop();
updateMetrics(frontier.size());
}
Expand All @@ -198,9 +195,9 @@ private List<Action> getSolution(Problem orgP, ExtendedNode node1, ExtendedNode
while (revNode.getParent() != null) {
Action action = getReverseAction(orgP, revNode);
if (action != null) {
Object stateNext = revNode.getParent().getState();
double stepCosts = orgP.getStepCostFunction().c(revNode.getState(), action, stateNext);
orgNode = new Node(stateNext, orgNode, action, stepCosts);
Object nextState = revNode.getParent().getState();
double stepCosts = orgP.getStepCostFunction().c(revNode.getState(), action, nextState);
orgNode = new Node(nextState, orgNode, action, stepCosts);
revNode = revNode.getParent();
} else { // should never happen...
searchOutcome = SearchOutcome.PATH_FOUND_BUT_NO_REVERSE_ACTIONS;
Expand Down
Expand Up @@ -56,20 +56,20 @@ public List<Action> search(Problem problem, Queue<Node> frontier) {
Node nodeToExpand = popNodeFromFrontier();
// Only need to check the nodeToExpand if have not already
// checked before adding to the frontier
if (!isCheckGoalBeforeAddingToFrontier()) {
if (!checkGoalBeforeAddingToFrontier) {
// if the node contains a goal state then return the
// corresponding solution
if (SearchUtils.isGoalState(problem, nodeToExpand))
return getSolution(nodeToExpand);
}
// expand the chosen node, adding the resulting nodes to the
// frontier
for (Node successor : expandNode(nodeToExpand, problem)) {
if (isCheckGoalBeforeAddingToFrontier()) {
if (SearchUtils.isGoalState(problem, successor))
return getSolution(successor);
for (Node childNode : expandNode(nodeToExpand, problem)) {
if (checkGoalBeforeAddingToFrontier) {
if (SearchUtils.isGoalState(problem, childNode))
return getSolution(childNode);
}
insertIntoFrontier(successor);
insertIntoFrontier(childNode);
}
}
// if the frontier is empty then return failure
Expand Down

0 comments on commit 4fec2e3

Please sign in to comment.