This is iterative deepening search and I want to keep track of the nodes generated before the goal state. I am using RUNNING_TIME as a counter and then assign it to each node in the tree. The thing is, because o recursion RUNNING_TIME is incremented more than once and the value is not valid anymore. Hence, I get a RUNNING_TIME for BFS which is better than this one which theoretically doesn't make sense (only worst case scenario). Do you have any idea how I should increment this value in my methods? I sincerely have no idea, thanks.
public void IDS() {
Grid startNode = new Grid(initState, A, B, C, agent);
for(int depth = 0; depth < Integer.MAX_VALUE; depth ++) {
Grid found = DLS(startNode, depth);
if(found != null) {
retracePath(found);
return;
}
}
}
public Grid DLS(Grid current, int depth) {
RUNNING_TIME ++;
current.nodesGeneratedBefore = RUNNING_TIME;
if(depth == 0 && current.checkGoalState()) {
return current;
}
if(depth > 0) {
for(Grid neighbor : current.getNeighbors(current)) {
Grid found = DLS(neighbor, depth - 1);
if(found != null) {
return found;
}
}
}
return null;
}
EDIT: Also I forgot to mention that I get the correct path to the destination, but only the "RUNNING_TIME" variable is wrongly incremented.
0 0 0 0
0 0 0 0
0 0 0 -1
1 2 3 0
Number of nodes generated by now 4680622
0 0 0 0
0 0 0 0
0 0 -1 0
1 2 3 0
Number of nodes generated by now 6297726
0 0 0 0
0 0 0 0
0 -1 0 0
1 2 3 0
Number of nodes generated by now 7106272
0 0 0 0
0 0 0 0
0 2 0 0
1 -1 3 0
Number of nodes generated by now 7760396
0 0 0 0
0 0 0 0
0 2 0 0
-1 1 3 0
Number of nodes generated by now 7837602
0 0 0 0
0 0 0 0
-1 2 0 0
0 1 3 0
Number of nodes generated by now 7837603
0 0 0 0
0 0 0 0
2 -1 0 0
0 1 3 0
Number of nodes generated by now 7842162
0 0 0 0
0 0 0 0
2 1 0 0
0 -1 3 0
Number of nodes generated by now 7848122
0 0 0 0
0 0 0 0
2 1 0 0
0 3 -1 0
Number of nodes generated by now 7849095
0 0 0 0
0 0 0 0
2 1 -1 0
0 3 0 0
Number of nodes generated by now 7849096
0 0 0 0
0 0 -1 0
2 1 0 0
0 3 0 0
Number of nodes generated by now 7849097
0 0 0 0
0 -1 0 0
2 1 0 0
0 3 0 0
Number of nodes generated by now 7849111
0 0 0 0
0 1 0 0
2 -1 0 0
0 3 0 0
Number of nodes generated by now 7849125
0 0 0 0
0 1 0 0
-1 2 0 0
0 3 0 0
Number of nodes generated by now 7849127