def run_bfs(p): results = init_results() progress = len(puzzles) * len(orders) i = 0 for puzzle in puzzles: for order in orders: bfs = BFS(search_order=order) dim, lay = load_config(os.path.join("puzzles", puzzle)) bfs.model.load_layout(dim, lay) t = time() path = bfs.run() t = round((time() - t) * 1000, 3) # get the depth from 4x4_depth_00000.txt depth = int(puzzle.split('_')[1]) if path == -1: continue result = { "path_length": len(path), "frontier": len(bfs.frontier) + len(bfs.explored), "explored": len(bfs.explored), "depth": len(path), "time": t } results["BFS"][order][depth].append(result) print("BFS progress: {}%".format(round((i / progress) * 100, 2)), end='\r', flush=True) i += 1 # avg_whole, avg_orders return process_results("BFS", results)
def run(self): if self.algorithm == "DFS": self.solution = DFS.run(self.source, self.destinations) if self.solution is not None: self.end_time = self.start_time + len(self.solution) - 1 self.end_time = self.end_time % 24 elif self.algorithm == "BFS": self.solution = BFS.run(self.source, self.destinations) if self.solution is not None: self.end_time = self.start_time + len(self.solution) - 1 self.end_time = self.end_time % 24 elif self.algorithm == "UCS": self.solution = UCS.run(self.start_time, self.source, self.destinations) if self.solution is not None: self.end_time = self.solution.pop(0) else: raise Exception("Unexpected Algorithm = " + self.algorithm)