def a_star_analysis(self): count = 0 analysis_as = { "h1": { "as_total_cost": 0, "as_solutions_found": 0, "as_total_execution_time": 0, "as_total_solution_path_length": 0, "as_total_search_path": 0 }, "h2": { "as_total_cost": 0, "as_solutions_found": 0, "as_total_execution_time": 0, "as_total_solution_path_length": 0, "as_total_search_path": 0 } } for puzzle in self.puzzles: count += 1 print("Puzzle", count) algo = AStar(puzzle, 2, 4) stats = algo.run_algo() print("") for h, stat in stats.items(): if stat['total cost'] is not None: analysis_as[h]["as_total_cost"] += stat['total cost'] analysis_as[h]["as_solutions_found"] += 1 analysis_as[h]["as_total_execution_time"] += stat[ 'execution_time'] analysis_as[h]["as_total_solution_path_length"] += stat[ 'solution_path_length'] analysis_as[h]["as_total_search_path"] += stat[ 'search_path_length'] with open("analysis_output_file.txt", "a") as analysis_output: analysis_output.write("#### A* ####") for h, analysis in analysis_as.items(): print(h + " " + 'as_total_cost: ' + str(analysis["as_total_cost"]) + " AVG: " + str(analysis["as_total_cost"] / analysis["as_solutions_found"])) print(h + " " + ' as_solutions_found: ' + str(analysis["as_solutions_found"])) print(h + " " + 'as_total_execution_time: ' + str(analysis["as_total_execution_time"]) + " AVG: " + str(analysis["as_total_execution_time"] / analysis["as_solutions_found"])) print(h + " " + 'as_total_solution_path_length: ' + str(analysis["as_total_solution_path_length"]) + " AVG: " + str(analysis["as_total_solution_path_length"] / analysis["as_solutions_found"])) print(h + " " + 'as_total_search_path: ' + str(analysis["as_total_search_path"]) + " AVG: " + str(analysis["as_total_search_path"] / analysis["as_solutions_found"])) with open("analysis_output_file.txt", "a") as analysis_output: analysis_output.write(h + " " + 'as_total_cost: ' + str(analysis["as_total_cost"]) + " AVG: " + str(analysis["as_total_cost"] / analysis["as_solutions_found"]) + "\n") analysis_output.write(h + " " + ' as_solutions_found: ' + str(analysis["as_solutions_found"]) + "\n") analysis_output.write( h + " " + 'as_total_execution_time: ' + str(analysis["as_total_execution_time"]) + " AVG: " + str(analysis["as_total_execution_time"] / analysis["as_solutions_found"]) + "\n") analysis_output.write( h + " " + 'as_total_solution_path_length: ' + str(analysis["as_total_solution_path_length"]) + " AVG: " + str(analysis["as_total_solution_path_length"] / analysis["as_solutions_found"]) + "\n") analysis_output.write(h + " " + 'as_total_search_path: ' + str(analysis["as_total_search_path"]) + " AVG: " + str(analysis["as_total_search_path"] / analysis["as_solutions_found"]) + "\n")