@@ -44,7 +44,7 @@ public class BidirectionalSearch<S, A> extends QueueSearch<S, A> {
4444 private boolean isReverseActionTestEnabled = true ;
4545
4646 // index 0: original problem, index 1: reverse problem
47- private List <Map <S , ExtendedNode <S , A >>> explored ;
47+ private final List <Map <S , ExtendedNode <S , A >>> explored ;
4848 private ExtendedNode <S , A > goalStateNode ;
4949
5050 public BidirectionalSearch () {
@@ -78,7 +78,6 @@ public BidirectionalSearch(NodeFactory<S, A> nodeFactory) {
7878 * containing a single NoOp Action if already at the goal, or an
7979 * empty list if the goal could not be found.
8080 */
81- @ SuppressWarnings ("unchecked" )
8281 public Optional <Node <S , A >> findNode (Problem <S , A > problem , Queue <Node <S , A >> frontier ) {
8382 assert (problem instanceof BidirectionalProblem );
8483
@@ -103,7 +102,7 @@ public Optional<Node<S, A>> findNode(Problem<S, A> problem, Queue<Node<S, A>> fr
103102
104103 while (!isFrontierEmpty () && !Tasks .currIsCancelled ()) {
105104 // choose a leaf node and remove it from the frontier
106- ExtendedNode <S , A > node = (ExtendedNode ) removeFromFrontier ();
105+ ExtendedNode <S , A > node = (ExtendedNode < S , A > ) removeFromFrontier ();
107106 ExtendedNode <S , A > nodeFromOtherProblem ;
108107
109108 // if the node contains a goal state then return the corresponding solution
@@ -156,8 +155,7 @@ protected void addToFrontier(Node<S, A> node) {
156155 * @return A node of a not yet explored state.
157156 */
158157 protected Node <S , A > removeFromFrontier () {
159- cleanUpFrontier (); // not really necessary because isFrontierEmpty
160- // should be called before...
158+ cleanUpFrontier (); // not really necessary because isFrontierEmpty should be called before...
161159 Node <S , A > result = frontier .remove ();
162160 updateMetrics (frontier .size ());
163161 // add the node to the explored set of the corresponding problem
@@ -180,7 +178,7 @@ protected boolean isFrontierEmpty() {
180178 * head of the frontier.
181179 */
182180 private void cleanUpFrontier () {
183- while (!frontier .isEmpty () && isExplored (frontier .element ()))
181+ while (!frontier .isEmpty () && isExplored (frontier .peek ()))
184182 frontier .remove ();
185183 }
186184
@@ -215,8 +213,7 @@ private Optional<Node<S, A>> getSolution(Problem<S, A> orgP, ExtendedNode<S, A>
215213
216214 /**
217215 * Returns the action which leads from the state of <code>node</code> to the
218- * state of the node's parent, if such an action exists in problem
219- * <code>orgP</code>.
216+ * state of the node's parent, if such an action exists in problem <code>orgP</code>.
220217 */
221218 private A getReverseAction (Problem <S , A > orgP , Node <S , A > node ) {
222219 S currState = node .getState ();
@@ -230,15 +227,13 @@ private A getReverseAction(Problem<S, A> orgP, Node<S, A> node) {
230227 return null ;
231228 }
232229
233- @ SuppressWarnings ("unchecked" )
234230 private boolean isExplored (Node <S , A > node ) {
235- ExtendedNode <S , A > eNode = (ExtendedNode ) node ;
231+ ExtendedNode <S , A > eNode = (ExtendedNode < S , A > ) node ;
236232 return explored .get (eNode .getProblemIndex ()).containsKey (eNode .getState ());
237233 }
238234
239- @ SuppressWarnings ("unchecked" )
240235 private void setExplored (Node <S , A > node ) {
241- ExtendedNode <S , A > eNode = (ExtendedNode ) node ;
236+ ExtendedNode <S , A > eNode = (ExtendedNode < S , A > ) node ;
242237 explored .get (eNode .getProblemIndex ()).put (eNode .getState (), eNode );
243238 }
244239
0 commit comments