#implementation of function “Iterative_deepening_DFS”def Iterative_deepening_DFS(self,goalState): queueNodesPopped =0 queueMaxLen = 1 for depthLimitIn in range(40): queue = self depthOfQueue = 0 pathCostQueue = 0 alreadyVisitedNodes = set() while queue: if len(queue) > queueMaxLen : queueMaxLen = len(queue) currentNodeOfQueue = queue.pop(0) queueNodesPopped += 1 currentDepthQueue = depthOfQueue.pop(0) currentPathCostOfQueue = pathCostQueue.pop(0) alreadyVisitedNodes.add(tuple(currentNodeOfQueue.state.reshape(1,9)0)) if np.array_equal(currentNodeOfQueue.state,goalState): currentNodeOfQueue.printPathToGoal() print (‘Time performance to get to the goal’, str(queueNodesPopped), ‘are the nodes pooped off the queue.’) print (‘Time spent to get to the goal:% 0.2fs’ %(time.time()-start)) else: if currentNodeOfQueue < depthLimitIn: if currentNodeOfQueue.isMovingDownValid() : destinationState,upValuePosition = currentNodeOfQueue.isMovingDownValid() if tuple(destinationState.reshape(1,9)0) not in alreadyVisitedNodes: currentNodeOfQueue.moveDownDirection = Node(state=destinationState,parent=currentNodeOfQueue,actionResulted='down',depthValue=currentDepthQueue+1,stepCost=upValuePosition,pathCost=currentPathCostOfQueue+upValuePosition,heuristicCost=0) queue.insert(0,currentNodeOfQueue.moveDownDirection) depthOfQueue.insert(0,currentDepthQueue+1) pathCostQueue.insert(0,currentPathCostOfQueue+upValuePosition) if currentNodeOfQueue.isMovingRightValid() : destinationState,leftValuePosition = currentNodeOfQueue.isMovingRightValid() if tuple(destinationState.reshape(1,9)0) not in alreadyVisitedNodes: currentNodeOfQueue.moveRightDirection = Node(state=destinationState,parent=currentNodeOfQueue,actionResulted='Right',depthValue=currentDepthQueue+1,stepCost=leftValuePosition,pathCost=currentPathCostOfQueue+leftValuePosition,heuristicCost=0) queue.insert(0,currentNodeOfQueue.moveRightDirection) depthOfQueue.insert(0,currentDepthQueue+1) pathCostQueue.insert(0,currentPathCostOfQueue+leftValuePosition) if currentNodeOfQueue.isMovingUpValid() : destinationState,lowerValuePosition = currentNodeOfQueue.isMovingUpValid() if tuple(destinationState.reshape(1,9)0) not in alreadyVisitedNodes: currentNodeOfQueue.moveUpDirection = Node(state=destinationState,parent=currentNodeOfQueue,actionResulted='up',depthValue=currentDepthQueue+1,stepCost=lowerValuePosition,pathCost=currentPathCostOfQueue+lowerValuePosition,heuristicCost=0) queue.insert(0,currentNodeOfQueue.moveUpDirection) depthOfQueue.insert(0,currentDepthQueue+1) pathCostQueue.insert(0,currentPathCostOfQueue+lowerValuePosition) if currentNodeOfQueue.isMovingLeftValid() : destinationState,rightValuePosition = currentNodeOfQueue.isMovingLeftValid() if tuple(destinationState.reshape(1,9)0) not in alreadyVisitedNodes: currentNodeOfQueue.moveLeftDirection = Node(state=destinationState,parent=currentNodeOfQueue,actionResulted='Left',depthValue=currentDepthQueue+1,stepCost=rightValuePosition,pathCost=currentPathCostOfQueue+rightValuePosition,heuristicCost=0) queue.insert(0,currentNodeOfQueue.moveLeftDirection) depthOfQueue.insert(0,currentDepthQueue+1) pathCostQueue.insert(0,currentPathCostOfQueue+rightValuePosition)