I have a problem with my program using BFS search. I am giving this method Node n
and it should give me back true
if it found the way to the target n
using method n.expand
. There are some other classes that implement Node
s and methods for expand
and isTarget
. When it's a short distance, it works, but when it is a longer distance between these nodes, it takes about 15 minutes or more. Can anyone help me with this problem?
public boolean prog(Node n)
{
Queue<Node> FIFO = new LinkedList<Node>();
List<Node> close = new LinkedList<Node>();
FIFO.add(n);
while (true) {
n = FIFO.poll();
if (close.contains(n)) {
} else {
close.add(n);
}
close.add(n);
for (int i = 0; i < n.expand().size(); i++) {
if (!close.contains(n.expand().get(i))) {
FIFO.add(n.expand().get(i));
} else {
}
if (n.expand().get(i).isTarget()) {
return true;
}else{
}
}
}
}