def build_multipuzzle_solver(image_filenames, puzzle_type, piece_width): """ Build the multipuzzle solver object. Args: image_filenames (List[str]): List of puzzle file paths. puzzle_type (PuzzleType): Type of the puzzle to solve. piece_width (int): Puzzle piece width in number of pixels Returns (MultiPuzzleSolver): The multipuzzle solver object built from the input image files. """ pieces, puzzles = Puzzle.get_combined_pieces_multiple_images(image_filenames, piece_width) pickle_filename = PickleHelper.build_filename("multipuzzle_distances", image_filenames, puzzle_type) # Initialize the distance information if _FORCE_RECALCULATE_DISTANCES or not os.path.exists(pickle_filename): multipuzzle_solver = MultiPuzzleSolver(image_filenames, pieces, top_level_calculate_asymmetric_distance, puzzle_type) if _POST_INITIAL_CONSTRUCTION_PICKLE_EXPORT: PickleHelper.exporter(multipuzzle_solver, pickle_filename) return multipuzzle_solver # Read the pickle information from the else: multipuzzle_solver = PickleHelper.importer(pickle_filename) multipuzzle_solver.reset_timestamp() return multipuzzle_solver
def run_paikin_tal_solver(image_filenames, puzzle_type, piece_width): """ Paikin & Tal Solver This function takes a set of inputs and runs the Paikin and Tal solver. It can be sped-up by importing the calculations of distances from existing Pickle files. Args: image_filenames (List[String]): Path to the image files used to create the puzzles puzzle_type (PuzzleType): Type of the puzzle to be solved piece_width (int): Width/length of all puzzle pieces Returns (PaikinTalSolver): Solved Paikin & Tal result. """ pickle_filename = PickleHelper.build_filename( PaikinTalSolver.POST_INITIAL_CONSTRUCTOR_PICKLE_FILE_DESCRIPTOR, image_filenames, puzzle_type ) # Optionally import the images from disk if FORCE_RECALCULATE_DISTANCES or not os.path.exists(pickle_filename): combined_pieces, puzzles = Puzzle.get_combined_pieces_multiple_images(image_filenames, piece_width) # Select whether or not to use fixed puzzle dimensions puzzle_dimensions = puzzles[0].grid_size if USE_KNOWN_PUZZLE_DIMENSIONS and len(images) == 1 else None # Create the Paikin Tal Solver logging.info("Beginning calculating of Paikin & Tal inter-piece distance information") start_time = time.time() paikin_tal_solver = PaikinTalSolver( combined_pieces, top_level_calculate_asymmetric_distance, len(image_filenames), puzzle_type, fixed_puzzle_dimensions=puzzle_dimensions, image_filenames=image_filenames, ) print_elapsed_time(start_time, "Paikin & Tal inter-piece distance calculations") else: paikin_tal_solver = PaikinTalSolver.pickle_import_after_initial_construction(image_filenames, puzzle_type) if config.IS_SOLVER_COMPARISON_RUNNING: paikin_tal_solver.reset_actual_puzzle_count() # Run the Solver paikin_tal_solver.run_standard() # Export the solved results return paikin_tal_solver