Skip to content

Commit

Permalink
BestFirstSearch: cosmetic, extract enqueue method
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Mar 24, 2022
1 parent 0d28522 commit aed3800
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ private class BestFirstSearch private (
}
Q += start

def enqueue(state: State) = {
Q.enqueue(state)
}

// TODO(olafur) this while loop is waaaaaaaaaaaaay tooo big.
while (true) {
val curr = Q.dequeue()
Expand Down Expand Up @@ -161,8 +165,7 @@ private class BestFirstSearch private (
else shouldRecurseOnBlock(splitToken, stop)
if (blockClose.nonEmpty)
blockClose.foreach { end =>
shortestPathMemo(curr, end, depth + 1, maxCost)
.foreach(Q.enqueue(_))
shortestPathMemo(curr, end, depth + 1, maxCost).foreach(enqueue)
}
else if (
escapeInPathologicalCases &&
Expand Down Expand Up @@ -202,24 +205,24 @@ private class BestFirstSearch private (
val overflow =
furtherState.appliedPenalty > nextNextState.appliedPenalty
if (overflow)
Q.enqueue(nextNextState)
enqueue(nextNextState)
else {
optimalNotFound = false
Q.enqueue(furtherState)
enqueue(furtherState)
}
} else if (
!killOnFail &&
nextState.cost - curr.cost <= maxCost
) {
// TODO(olafur) DRY. This solution can still be optimal.
Q.enqueue(nextState)
enqueue(nextState)
} else { // else kill branch
if (updateBest) best.remove(curr.depth)
}
case _
if optimalNotFound &&
nextState.cost - curr.cost <= maxCost =>
Q.enqueue(nextState)
enqueue(nextState)
case _ => // Kill branch.
if (updateBest) best.remove(curr.depth)
}
Expand Down

0 comments on commit aed3800

Please sign in to comment.