def DFS(StartState): global stepscount, mode, weight # Update hashtable Node.h = {} # tree initialisation current = Node(state=StartState) # queue initialisation queue = Queue() # start of search while True: # show current condition for step mode if mode == 1: print(current.getstate()) input("Press enter to continue...") # step's counting stepscount = stepscount + 1 # the decomposition of the node current.expand() # if a solution is found, output the results if current.goaltest(): weight = sys.getsizeof(Node.h) result = [current] while current.depth != 0: current = current.prev result.append(current) return result # getting child nodes childs = current.getchild() # adding child nodes to queue queue.Queueing_Fn(childs) # getting the next node from the queue if not queue.IsQueusEmpty(): current = queue.RemoveFront() else: return 1
def IDFS(StartState): global stepscount, weight, mode # Update hashtable Node.h = {} # Install current depth depth = 0 # Cycle through depth to the maximum depth while True: Node.h = {} # tree initialisation current = Node(state=StartState) # queue initialisation queue = Queue() flag = True # depth cycle while flag: # show current condition for step mode if mode == 1: print(current.getstate()) input("Press enter to continue...") # step's counting stepscount = stepscount + 1 # the decomposition of the node if current.depth < depth: current.expand() # if a solution is found, output the results if current.goaltest(): weight = sys.getsizeof(Node.h) result = [current] while current.depth != 0: current = current.prev result.append(current) return result # getting child nodes childs = current.getchild() # adding child nodes to queue queue.Queueing_Fn(childs) # getting the next node from the queue if not queue.IsQueusEmpty(): current = queue.RemoveFront() else: flag = False # increasing the depth depth = depth + 1