![]() It first examines if the puzzle already been solved. Our first trial for solving the puzzle is by a naive backtracking algorithm. Backtracking is a classical depth-first search. Data structure and some important methods of the Sudoku class The following Java code includes some important methods of the Sudoku class. The full Java code of the SudokuSolver is publicly available on. ![]() finally, we also holds a list of non-assigned cells in the puzzle. In addition we keep for each row/column/block (a unit for short) a BitSet that maintains all values that have already been set in this unit. Any constraint entry (i,j) represents all candidates that can be legally assigned to cell (i,j). ![]() BitSet is a Java class that can be used to efficiently maintain a set of values, including adding, removing, and querying the containment of a specific value. In addition, we manage an auxiliary NxN matrix of BitSet objects. At the beginning, only clue cells are set with their values, while all other cells are set to zero. We represent a Sudoku puzzle by an NxN matrix holding all values that have already been set on the grid. I’ll also report the results of some experiments I conducted on a popular benchmark of 95 9×9 puzzles which had already been used in Norvig study. I’ll begin with the search algorithm, and then describe the heuristics. In the following I will describe the HS-solver that is based on backtracking search, integrated with the human strategies. This is especially useful for (the few) tasks for which humans are still superior to machines. Realizing the difficulty in searching over huge spaces, it is inspired from the ways humans tend to solve the problem and whether human strategies can be applied to improve our solver performance. ![]() Heuristic search is one of my favorite AI techniques. In this study I follow Norvig by integrating common Sudoku strategies, popular among Sudoku fans, into the search process. Peter Norvig, the famous AI pioneer, provided a Python code for a Sudoku solver based on integrating CSP with search. Genetic algorithms, and modeling Sudoku as an exact cover problem while using the dancing links techniques. There are many approaches for solving Sudoku puzzles, including CSP-based solutions , Unfortunately, Sudoku is an NP-complete problem, when generalized to N × N grids, in the sense that all known solvable algorithms do so inefficiently in spite of the fact that if a candidate solution is given, it takes only polynomial time to check its correctness. Therefore, a naive search approach is unlikely to be efficient so we need some domain knowledge (called heuristics in AI terminology ) to direct our problem solver. Right: its solutionĪs a lazy scientist who hates hard work but also can’t stand unsolved puzzles, I decided to write a Sudoku solver program based on searching over all legal assignments for a given puzzle. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |