def verbose_info(args, puzzle, solved, size): opts1 = { 'greedy search:': args.g, 'uniform cost search:': args.u, 'visualizer:': args.v, 'solvable:': is_solvable(puzzle, solved, size) } opt_color = 'cyan2' for k, v in opts1.items(): print(color(opt_color, k), color_yes_no(v)) opts2 = { 'heuristic function:': color('green2', args.f), 'puzzle size:': str(size), 'solution type:': color('green2', args.s), 'initial state:': str(puzzle), 'final state:': str(solved) } for k, v in opts2.items(): print(color(opt_color, k), v) print(color('blue2', 'heuristic scores for initial state')) for k, v in heuristics.KV.items(): print(color('blue2', ' - ' + k + '\t:'), v(puzzle, solved, size)) print(color('red2', 'search algorithm:'), 'IDA*' if args.ida else 'A*')
def verbose_info(args, puzzle, solved, size): opts1 = { "greedy search:": args.g, "uniform cost search:": args.u, "visualizer:": args.v, "solvable:": is_solvable(puzzle, solved, size), } opt_color = "cyan2" for k, v in opts1.items(): print(color(opt_color, k), color_yes_no(v)) opts2 = { "heuristic function:": color("green2", args.f), "puzzle size:": str(size), "solution type:": color("green2", args.s), "initial state:": str(puzzle), "final state:": str(solved), } for k, v in opts2.items(): print(color(opt_color, k), v) print(color("blue2", "heuristic scores for initial state")) for k, v in heuristics.KV.items(): print(color("blue2", f" - {k}\t:"), v(puzzle, solved, size)) print(color("red2", "search algorithm:"), "IDA*" if args.ida else "A*")
colors.enabled = True if args.ida: args.g = False TRANSITION_COST = 1 if args.g: TRANSITION_COST = 0 HEURISTIC = heuristics.KV[args.f] if args.u: HEURISTIC = heuristics.uniform_cost solved = solved_states.KV[args.s](size) verbose_info(args, puzzle, solved, size) if not is_solvable(puzzle, solved, size): print(color('red', 'this puzzle is not solvable')) sys.exit(0) maxrss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss print(color('red', 'max rss before search:'), maxrss) t_start = perf_counter() if args.ida: res = ida_star_search(puzzle, solved, size, HEURISTIC, TRANSITION_COST) else: res = a_star_search(puzzle, solved, size, HEURISTIC, TRANSITION_COST) t_delta = perf_counter() - t_start maxrss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss print(color('red', 'max rss after search: '), maxrss)
colors.enabled = True if args.ida: args.g = False TRANSITION_COST = 1 if args.g: TRANSITION_COST = 0 HEURISTIC = heuristics.KV[args.f] if args.u: HEURISTIC = heuristics.uniform_cost solved = solved_states.KV[args.s](size_rows, size_cols) verbose_info(args, puzzle, solved, size_rows, size_cols) if not is_solvable(puzzle, solved, size_rows, size_cols): print(color('red', 'this puzzle is not solvable')) sys.exit(0) maxrss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss print(color('red', 'max rss before search:'), maxrss) t_start = time.time() if args.ida: res = ida_star_search(puzzle, solved, size_rows, size_cols, HEURISTIC, TRANSITION_COST) else: res = a_star_search(puzzle, solved, size_rows, size_cols, HEURISTIC, TRANSITION_COST) t_delta = time.time() - t_start maxrss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss print(color('red', 'max rss after search: '), maxrss)