Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this document? Why not share!

3,792 views

Published on

A scanning strategy introduces Sudoku and solves the first example. The article presents an estimation of the complexity with stochastic methods. Sudoku-specific advanced strategies refine the scanning technique from the introduction. A software-architecture for efficiently implementing a rule-based solver is integrating the strategies and is using annotations that are updated with notifications. When no rule can be applied, a backtracking search is started. The parametrized solver offers policies for searching. A logging mechanism is presented supporting the search saving memory for the efficient implementation.

The author, Dr. Harald Hiss, has obtained the diploma in software-engineering in 2004 and he has graduated in databases in 2008 at the university of Freiburg supported by the interdisciplinary graduate programme logic and applications. This article is presenting a new Sudoku solver that performs best. The computer scientist is presenting Sudoku-specific strategies and a solver architecture for the fast and simple implementation using the latest technologies.

No Downloads

Total views

3,792

On SlideShare

0

From Embeds

0

Number of Embeds

26

Shares

0

Downloads

91

Comments

0

Likes

1

No embeds

No notes for slide

- 1. Sudoku Solving with Computational Intelligence Dr. Harald Hiss June 30, 2010
- 2. Summary Computers can create convincing results – the cinemas are presenting the latest overwhelming 3D multimedia spectacles. The results and beneﬁts aren’t restricted to the amusement and movies, modern methods for our machines bring further considerable improvements to reality. Programs and algorithms evolve in bioinformatics and public health. Computational intel- ligence can also be utilized in solving brainteasing tasks. This article is presenting a computational intelligence approach for solving Sudoku brain- teasers. A scanning strategy introduces Sudoku and solves the ﬁrst example. The article presents an estimation of the complexity with stochastic methods. Sudoku-speciﬁc advanced strategies reﬁne the scanning technique from the introduction. A software-architecture for efﬁciently implementing a rule- based solver is integrating the strategies and is using annotations that are updated with notiﬁcations. When no rule can be applied, a backtracking search is started. The parametrized solver offers policies for searching. A logging mechanism is presented supporting the search saving memory for the efﬁcient implementation. The author, Dr. Harald Hiss, has obtained the diploma in software-engineering in 2004 and he has graduated in databases in 2008 at the university of Freiburg supported by the interdisciplinary graduate programme logic and applications. This article is presenting a new Sudoku solver that performs best. The computer scientist is presenting Sudoku-speciﬁc strategies and a solver architecture for the fast and simple implementation using the latest technologies.
- 3. Contents 1 Solving Sudoku with Computational Intelligence 1 2 Sudoku and a Scanning Strategy 1 3 Possibilities Estimation 3 4 Sudoku-speciﬁc Strategies and Techniques 4 5 Solver Software-Architecture 6 6 Integrating AI Search Strategies 7
- 4. 2 Sudoku and a Scanning Strategy 1 1 Solving Sudoku with Computational Intelligence Computers can create convincing results – the cinemas are presenting the latest over- whelming 3D multimedia spectacles. The results and beneﬁts aren’t restricted to the amusement and movies, modern methods for our machines bring further consider- able improvements to reality. Programs and algorithms evolve in bioinformatics and public health. Computational intelligence can also be utilized in solving brainteasing tasks. This article is presenting a computational intelligence approach for solving Su- doku brainteasers. The example is illustrating speciﬁc game strategies, estimating the complexity and again proving both power and expressiveness of computational intelli- gence. At the turn of the millenium, the number puzzle became very popular. The enjoyable quest for ﬁlling numbers in ﬁelds comes in some variants and difﬁculty levels. Simple Sudokus can be solved very fast, the next chapter introduces a scanning strategy that is sufﬁcient for automatically solving a ﬁrst example. After the description, an estimation of the complexity is given with stochastic methods showing a huge amount of possibilities that a solver has to face. For the development of an automatic solver, some advanced strategies are presented. The aspects are integrated in a ﬂexible software-architecture that can be easily adapted to Sudoku variants. Finally, the strategies are integrated with the architecture. Computational intelligence extracts information for choosing the appropriate rules to ﬁll the next ﬁeld and for choosing optimal ﬁelds and numbers for backtracking when no rule applies. The article presents an approach in computational intelligence for Sudoku. The con- venient example is illustrating many aspects of computational intelligence. The num- ber quest is formalized, stochastical methods estimate the possibilities, the speciﬁc advanced strategies integrate with the software architecture and a rule-based logical system. Methods from artiﬁcial intelligence and learning optimize the search choosing the right ﬁelds and numbers – a very promising approach for constructing a success- ful Sudoku solver with computational intelligence. The author has acquired very much knowledge in this ﬁeld. The huge power of computational intelligence can impressively be shown with the Sudoku example presented in this article. 2 Sudoku and a Scanning Strategy The challenge of Sudoku is posed in ﬁlling ﬁelds with ﬁtting numbers so that some number constraints are satisﬁed. The ﬁelds are arranged in groups. Within a group, only numbers of a deﬁned domain may be inserted. Numbers may not occur more than once in a group. Solutions have ﬁlled all ﬁelds so that each number occurs exactly 1
- 5. 2 Sudoku and a Scanning Strategy 2 once in each group. The standard Sudoku variant considers a 9 × 9 array of ﬁelds and deﬁnes the domain 1, 2, ..., 9 for the numbers. As groups, the number puzzle considers rows, columns and the 9 blocks formed of the 3 × 3 squares that are tiling the game. The constraints have to be satisﬁed for each group. For instance, a row can contain numbers in 1, 2, ..., 9 and a row of a solution represents a permutation of the domain. The section shows a simple scanning strategy for solving some Sudokus. Figure 1 Figure 1 An easy Sudoku example. 1 2 5 9 4 4 3 6 1 5 5 1 3 1 2 5 7 2 6 9 3 3 4 2 7 1 3 6 7 1 9 7 1 4 2 8 8 5 9 7 presents the example that is illustrating the strategy. For the numbers of the domain, the rows and columns are scanned to ﬁnd the appropriate ﬁeld in a block. The scan starts with 1. The second ﬁeld of the ﬁrst row, abbreviated with S12 , has a 1. In the block below, the ﬁeld S41 stores this number. The ﬁrst two columns may not contain the number anymore, the left bottom block has the 1 in S73 or S93 . Then the scan considers the relevant rows for the bottom block. The seventh row has a 1 in S77 , the 1 can be ﬁlled in S93 . Using scans and ﬁlling obvious ﬁelds the solution in ﬁgure 2 is obtained. The next section estimates the amount of possible games. Then again the article turns to solving strategies and presents some advanced techniques. 2
- 6. 3 Possibilities Estimation 3 Figure 2 The solution for the previous example. 6 1 3 2 7 5 9 8 4 9 2 8 4 3 6 7 1 5 4 7 5 9 1 8 6 3 2 1 3 9 7 8 2 5 4 6 7 4 2 6 5 1 8 9 3 8 5 6 3 4 9 2 7 1 3 6 4 8 2 7 1 5 9 5 9 7 1 6 4 3 2 8 2 8 1 5 9 3 4 6 7 3 Possibilities Estimation A ﬁrst naive estimation of the possibilities for choosing the numbers in the 9 × 9 square considers ﬁlling each ﬁeld with any number. The 981 combinations compute a total of 1.966 · 1077 . The ﬁrst improvement considers the symbols that have been inserted previously in the same row. For nine rows, 9!9 combinations are obtained, a total of 1.091 · 1050 . Taking into account more information considering relevant blocks the num- ber can be improved to 1.528 · 1031 . The huge amount suggests to invest some time in software design considerations and to integrate both efﬁcient game-speciﬁc strate- gies and intelligent computational methods instead of implementing a trial-and-error program. The following sections are going to present an efﬁcient approach for the de- velopment of an automatic solver. The ﬁnal estimation presented in this section is considering sequentially ﬁlling numbers, from the left to the right and from the top to the bottom. The estimation uses the max- imal restriction that is available in the context of the focussed ﬁeld. The maximum of the present numbers in the same row, column or block reduces the possible choice. Figure 3 shows the result. The ﬁeld in line 5, column 4 is regarding the numbers above and to the left. In the same line, three numbers have been inserted. The column has four numbers, and the middle block three. The column offers the maximal restriction of 3
- 7. 4 Sudoku-speciﬁc Strategies and Techniques 4 Figure 3 Possibilities for choosing a number for a ﬁeld starting at the top-left corner continuing from the left to the right and downward. 9 8 7 6 5 4 3 2 1 6 5 4 6 5 4 3 2 1 3 2 1 3 2 1 3 2 1 6 6 6 6 5 4 3 2 1 5 5 4 5 5 4 3 2 1 3 2 1 3 2 1 3 2 1 3 3 3 3 3 3 3 2 1 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 four different numbers. At most ﬁve numbers remain for choosing, the possibilities are inserted in the ﬁeld. With this approach, an estimation of 9! · 6!6 · 3!10 · 5 is obtained. The number of possible valid Sudoku instances can be bound with 1.528 · 1031 . Another aspect of Sudoku brainteasing is presented in ﬁgure 3. The last column and the bottom row have one possibility left for each ﬁeld. Often, many ﬁelds are still empty although the game has been solved. Some clean-up work completes a Sudoku game ﬁlling num- bers in ﬁelds that are restricted already having 8 numbers in the same group. The next section is showing some improvements for the simple scanning solver in- troduced at the beginning and is presenting advanced Sudoku-speciﬁc strategies and techniques. 4 Sudoku-speciﬁc Strategies and Techniques Easy instances can be solved with simple strategies as shown in section 2. For each number, the possible positions within a block have been scanned excluding correspond- ing rows and columns in the blocks of the same column and row. Obvious ﬁelds remain- ing as the single gap in a group can be ﬁlled. For each ﬁeld, the numbers of all groups 4
- 8. 4 Sudoku-speciﬁc Strategies and Techniques 5 it belongs to can be removed from the candidates. Again, if one number is left the gap can be ﬁlled. This section is considering advanced strategies for more complex Sudoku solving. Side-effects of groups can be used for improving the scanning approach presented in Figure 4 First lines of the example for the improvement. 1 1 1 1 1 8 9 2 3 4 section 2. Some group restrictions sufﬁce to determine ﬁelds in depending groups. Fig- ure 4 shows an example, the possible positions for a 1 in the middle block have blue entries. The Information that the middle block has the 1 in the middle row sufﬁces for ﬁlling a 1 in S31 . In this way, the 1 in the ﬁrst block is restricted to the two bottom ﬁelds when the middle and last block share the 1 in the ﬁrst two rows as shown in ﬁgure 5. The section presents a strategy that is not necessarily needed to solve the example of Figure 5 A variant of the improvement. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 2 3 4 5 6 7 the introduction. The last row of the instance shown in ﬁgure 6 contains 9, 6, 7 and 8. Other ﬁelds in this row can be ﬁlled with 1, ..., 5. The bottom middle block contains 4, 2 and is restricting its bottom row to 1, 3, 5. Considering columns is proving S94 , S95 ∈ {1, 5} and S96 ∈ {1, 3}. The constraints for S94 and S95 consume 1 and 5, the three ﬁlls S96 . Constraints consuming numbers can be used sometimes similarly to symbols of ﬁlled ﬁelds. The information just derived together with the 1 in S77 restricts possible positions for ﬁlling a 1 in the bottom left block to S81 and S82 . Furthermore, the remaining ﬁelds of the bottom middle block may only be ﬁlled with 6, ..., 9, possibly resulting in more consequences. 5
- 9. 5 Solver Software-Architecture 6 Figure 6 A number consuming example with S94 and S95 consuming the pair (1, 5). 7 6 1 3 2 8 7 9 3 7 6 5 9 4 6 3 8 2 4 1 5 6 2 9 6 7 8 The strategies introduced here are comfortably integrated in a software-architecture for a Sudoku solver. The ﬂexible approach makes the integration simple and it is open for integrating new strategies. Section 3 has shown the importance with the huge amount of possibilities that make backtracking costly. 5 Solver Software-Architecture The section presents an object-oriented architecture for a Sudoku solver. A class hierarchy is structuring the logical groups of the game, annotations provide a ﬂexible mechanism for rule-based game solving integrating Sudoku-speciﬁc strategies. The solver architecture deﬁnes a hierarchy for groups and offers annotations for the integration of strategies. Fields can be ﬁlled with numbers, groups represent ﬁelds that belong to the same logical unit of the game. In particular, a block represents one of the 3 × 3 squares tiling the game. Rows and columns also represent groups. Each ﬁeld is associated with the groups it belongs to – a block, a row and a column. Vice versa, the groups are associated with their ﬁelds. Furthermore, the groups are associated to the groups they intersect. Empty ﬁelds are annotated with possible numbers. Initially, the annotations get the 6
- 10. 6 Integrating AI Search Strategies 7 numbers that aren’t in the groups of the ﬁeld. Numbers that don’t occur in a group de- ﬁne annotations. The annotated group initially stores the empty ﬁelds. With constraints of these annotations, ﬁelds can be ﬁlled as immediate consequence. In ﬁelds with one possible number, the annotation left can be ﬁlled. When the group annotation for a number leaves one ﬁeld, the number may ﬁll the gap. For ﬁlling ﬁelds, the annotations are updated. Filling a number generates notiﬁcations, the change at a position informs depending ﬁelds and groups. In that block, row and column the number can’t occur again, there are fewer possible numbers. The anno- tations of the ﬁelds in these groups are updated. Depending groups get notiﬁcations. In this way, a generalization of the scanning strategy presented in section 2 is imple- mented. Depending groups are deﬁned having a non-empty intersection with a group of the considered ﬁeld. For example, ﬁlling a 1 in the top left ﬁeld notiﬁes some depending groups. The ﬁrst row intersects the top middle and right block – they can ﬁll the only 1 in the rows two and three. In addition, row one is intersecting the ﬁrst ﬁeld of all columns. The ﬁrst column intersects all rows and restricts the left middle and bottom blocks to the columns two and three. Finally, the top left block removes the ﬁrst three ﬁelds from the group annotations of the ﬁrst three columns and rows. The annotations provide a ﬂexible mechanism for integrating the Sudoku-speciﬁc strate- gies presented in section 4. For instance, when the top left block restricts the 1 to the ﬁrst column, the blocks below are notiﬁed in the same way. Fields consuming con- straints like exclusive pairs can have the same side-effect. Finding these constraints always generates notiﬁcations within the groups the constraint shares. The ﬁeld anno- tations remove the numbers of such a pair, for example. When no rules apply, the solver uses backtracking for searching a solution. The object- oriented architecture and the annotations of this section are integrated in the intelligent search that the next section is presenting. 6 Integrating AI Search Strategies As section 3 has been showing, the huge amount of possibilities can cause consider- able costs and so a simple scanning approach and advanced Sudoku-speciﬁc strate- gies have been introduced in the sections 2 and 4. The previous section has integrated the strategies in a rule-based solver using annotations for ﬁelds and groups. When no rule can be applied, the solver is starting a backtracking search that is presented in this section. The annotations can be used for optimizing the search. The solver stores the progress for a Sudoku instance. A history remembers the ﬁelds that are ﬁlled and the changes that are computed for the annotations. Logging the steps is supporting an optimized backtracking search. When no rule or strategy can be ap- 7
- 11. 6 Integrating AI Search Strategies 8 plied, the solver is introducing a choice-point and is starting a search. Occassionally choosing a ﬁeld and a number can be wrong, a guess can cause a clash. Each time after ﬁlling further ﬁelds, the solver is checking clashes. Empty ﬁelds must have non- empty annotations that suggest possible numbers for ﬁlling. Numbers that don’t occur in a group may not have empty annotations in that particular group. Such numbers are then missing in the group that can’t form a solution anymore. Checking clashes can be limited to changes of annotations. The backtracking is integrating the annotations. The solver makes a guess and then continues with rule-based solving. New choice-points can be introduced and clashes revise a guess. A choice-point is choosing a number for a ﬁeld or the place for a number within a group. The annotations decrease the considered possibilities and can be used to optimize the decisions regarding the basis of a choicepoint. Furthermore, the history is reducing the required resources storing the changes that can simply be undone. A choice-point stores the parent state and the history for reaching a descendant. When breadth-ﬁrst search is desired, the ways to other choice-points can also be logged. The choice-point stores the possible choices within its basis and the choices that can al- ready be disregarded. A ﬁeld is determined, if only one possibility is left. One more clash propagates the change to the parent. The approach offers policies for the parametrized search. The standard depth-ﬁrst search method can be replaced with breadth-ﬁrst search and the approach is open for further strategies. Choosing the basis for a choice-point is using annotations. For exam- ple, a test would like to give high priority to choice-points with group annotations storing two or three ﬁelds for a certain number. Another test might prefer ﬁeld annotations providing few possible numbers for ﬁlling the gap. The solver is open for ﬁne-tuning in accordance with the software-architecture presented in section 5. Finally, the parameter can be optimized with statistical methods. Further methods of artiﬁcial intelligence can be utilized for optimizing the solver. Training with Sudoku instances is very promising for ﬁnding the best basis for the choice-point and for at fastest ﬁnding the solution. 8

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment