def levelByLevel(self, aFile): ''' Print the nodes of the BTree level-by-level on aFile. ''' aFile.write('A level-by-level listing of the nodes:\n') node_cache = MyQueue() node_cache.enqueue(self.rootNode) while not node_cache.isEmpty(): cur_node = node_cache.dequeue() aFile.write(str(cur_node)) for child_idx in cur_node.child: if child_idx is not None: node_cache.enqueue(self.readFrom(child_idx))
def search(board): start = time() nodes_generated = 0 nodes_repeated = 0 if board.is_win(): end = time() print_results(board, 1, 0, 0, 1, end - start) return board node = deepcopy(board) nodes_generated += 1 frontier = MyQueue() frontier.push(node) explored = set() keepLooking = True while keepLooking: if frontier.isEmpty(): print "Solution not found" return else: currNode = frontier.pop() moves = currNode.moves_available() currNode.fboxes = frozenset(currNode.boxes) explored.add(currNode) for m in moves: child = deepcopy(currNode) nodes_generated += 1 child.move(m) if child not in explored: if child.is_win(): end = time() print_results(child, nodes_generated, nodes_repeated, len(frontier), len(explored), end - start) return child frontier.push(child) else: nodes_repeated += 1
coachSvcStation002.remainingServiceTime = 0 p = coachSvcStation002.servingPassenger busyStation['coach']['002'] += 1 # CO03 if coachSvcStation003.remainingServiceTime > 1: coachSvcStation003.remainingServiceTime -= 1 busyStation['coach']['003'] += 1 elif coachSvcStation003.remainingServiceTime == 1: coachSvcStation003.remainingServiceTime = 0 p = coachSvcStation003.servingPassenger busyStation['coach']['003'] += 1 # Handle IDLE Service Stations # FC01 if firstClassSvcStation001.remainingServiceTime == 0: if not firstClassQueue.isEmpty(): fcp = firstClassQueue.dequeue() firstClassSvcStation001.remainingServiceTime = fcp.service firstClassSvcStation001.servingPassenger = fcp waitTime = duration - fcp.arrival if waitTime > firstQueueSTATS['duration']: firstQueueSTATS['maxWait'] = waitTime firstQueueSTATS['duration'] += waitTime elif not coachQueue.isEmpty(): cp = coachQueue.dequeue() firstClassSvcStation001.remainingServiceTime = cp.service firstClassSvcStation001.servingPassenger = cp waitTime = duration - cp.arrival if waitTime > coachQueueSTATS['maxWait']: