Presentation is loading. Please wait.

Presentation is loading. Please wait.

SAT Encodings for Sudoku Bug Catching in 2006 Fall Sep. 26, 2006 Gi-Hwon Kwon.

Similar presentations


Presentation on theme: "SAT Encodings for Sudoku Bug Catching in 2006 Fall Sep. 26, 2006 Gi-Hwon Kwon."— Presentation transcript:

1 SAT Encodings for Sudoku Bug Catching in 2006 Fall Sep. 26, 2006 Gi-Hwon Kwon

2 2 2 Agenda Introduction Background and Previous Encodings Optimized Encoding Experimental Results Conclusions

3 3 3 What is Sudoku ? 846172593 739658142 521349768 962837451 485921376 173465829 298714635 354286917 617593284 6125 3914 4 92341 87 13689 1 5491 7532 Given a problem, the objectvie is to find a satisfying assignment w.r.t. Sudoku rules. Problem Solution There is a number in each cell. A number appears once in each row. A number appears once in each column. A number appears once in each block. Sodoku rules

4 4 4 Sudoku as SAT Problem Encoder SAT Solver Decoder CNF SAT? yes no Sudoku symbol table model  No solution found Solution found

5 5 5 Previous Encodings Encoder SAT Solver Decoder CNF SAT? yes Sudoku symbol table model Minimal encoding [Lynce & Ouaknine, 2006] Extended encoding [Lynce & Ouaknine, 2006] Efficient encoding [Weber, 2005]

6 6 6 Analysis of Previous Encodings Encoding Number of Variables Number of Clauses Minimal Efficient Extended

7 7 7 Exponential Growth in Clauses sizeminimalefficientextended 9x988291174511988 16x1692416123136123904 25x25563125750625752500 36x36245073632672163271104 49x4984731291129670511303908 64x64247767043303424033046528 81x81637794818503712185056804

8 8 8 Experimental Results minimal encodingefficient encodingextended encoding sizelevelvarsclausestimevarsclausestimevarsclausestime 9x9easy72988540.00729117700.00729120130.00 9x9hard72988590.00729117750.00729120180.00 16x16easy4096925200.1040961232400.0940961240080.01 16x16hard4096925140.4640961232340.2140961240020.01 25x25easy156255634179.071562575091717.48156257527920.07 25x25hard15625563403time15625750903time156257527780.21 36x36easy466562451380time466563267860time4665632717480.50 36x36hard466562451400time466563267880time4665632717680.67 49x49easy1176498474410time11764911297986time117649113051891.47 64x64easy26214424779088stack26214433036624stack26214433048912stack 81x81easy53144163783464stack53144185041104stack53144185060787stack

9 9 9 Experimental Results minimal encodingefficient encodingextended encoding sizelevelvarsclausestimevarsclausestimevarsclausestime 9x9easy72988540.00729117700.00729120130.00 9x9hard72988590.00729117750.00729120180.00 16x16easy4096925200.1040961232400.0940961240080.01 16x16hard4096925140.4640961232340.2140961240020.01 25x25easy156255634179.071562575091717.48156257527920.07 25x25hard15625563403time15625750903time156257527780.21 36x36easy466562451380time466563267860time4665632717480.50 36x36hard466562451400time466563267880time4665632717680.67 49x49easy1176498474410time11764911297986time117649113051891.47 64x64easy26214424779088stack26214433036624stack26214433048912stack 81x81easy53144163783464stack53144185041104stack53144185060787stack  No solution found Solution found

10 10 Motivations Sudoku was regarded as SAT problem  W Weber, A SAT-based Sudoku Solver, Nov. 2005.  Lynce & Ouaknine, Sudoku as a SAT Problem, Jan. 2006.  Extended encoding shows the best performance in our experiments Problems in previous works  Too many clauses are generated (e.g. 85,056,804 clauses)  Thus, large size puzzles are not solved  The extended encoding must be optimized for large size puzzles Our objectives  To propose an optimization for the extended encoding

11 11 Agenda Introduction Background and Previous Encodings Optimized Encoding Experimental Results Conclusions

12 12 Encoding Kowledge compilation into a target language Knowlede about Sudoku A number appears once in each cell A number appears once in each row A number appears once in each col A number appears once in each block A pre-assigned number rules facts CNF problem knowlege 9

13 13 Glance at CNF CNF represented by boolean variables Literal is a variable or its negation Clause is a disjunction of literals CNF is a conjunction of clauses

14 14 Variables Each cell has one number from 1..N  [1,1]=1 or [1,1]=2 or …… or [1,1]=N  Each cell needs N boolean variables to consider all cases Total number of variables  N 3 Boolean variable name as a triple  (r,c,v)iff [r,c]  v   (r,c,v) iff [r,c]  v N

15 15 Set Notation Indexed generalized disjunction and union operators Re-definitions of clause and CNF using the operators

16 16 Cell Rule  CNF A number appears once in each cell There is at least one number in each cell(definedness) There is at most one number in each cell (uniqueness)

17 17 Row Rule  CNF Each number appears at least in each row (definedness) Each number appears at most in each row (uniqueness) A number appears once in each row

18 18 Column Rule  CNF Each number appears at least in each column(definedness) Each number appears at most in each column(uniqueness) A number appears once in each column

19 19 Block Rule  CNF Each number appears at least in each block(definedness) Each number appears at most in each block(uniqueness) A number appears once in each block

20 20 Pre-Assigned Fact  CNF 3 As a constant; the number is never changed It can be represented as a unit clause A pre-assigned number

21 21 Previous Encodings Minimal encoding [Lynce & Ouaknine, 2006] sufficient to characterize the puzzle Extended encoding [Lynce & Ouaknine, 2006] minimal encoding with redundant clauses Efficient encoding [Weber, 2005] between minimal encoding and extended encoding

22 22 Analysis (Recap) Encoding Number of Variables Number of Clauses Minimal Efficient Extended

23 23 Agenda Introduction Background and Previous Encodings Optimized Encoding Experimental Results Conclusions

24 24 Example 43 13 is represented using boolean variables CNF For example, consider the cell [1,1]  Four cases are considered; thus, four variables are needed (1,1,1), (1,1,2), (1,1,3), (1,1,4)

25 25 Variables A pre-assigned cell reduces the cases to be considered  Because the cell has a fixed number  The pre-assigned cell does not need a variable at all  It affects other cells located at the same row, or column, or block. For example, consider the cell [1,1]  The case [1,1]=1 is not allowed since [4,1]=1 are already assigned  The case [1,1]=3 is not allowed since [1,4]=3 are already assigned  The case [1,1]=4 is not allowed since [1,3]=4 are already assigned  Thus, the only case to be cosidered is [1,1]=2 43 13 (1,1,2)

26 26 Variables Let V be a set of variables

27 27 Example (1,1,2) (1,2,1) (1,2,2) 43 (2,1,2) (2,1,3) (2,1,4) (2,2,1) (2,2,2) (2,2,4) (2,3,1) (2,3,2) (2,4,1) (2,4,2) (3,1,2) (3,1,4) (3,2,2) (3,2,4) (3,3,1) (3,3,2) (3,3,3) (3,4,1) (3,4,2) (3,4,4) 13(4,3,2) (4,4,2) (4,4,4) these parts are excluded

28 28 Cell Rule  CNF A number appears once in each cell There is at least one number in each cell(definedness) There is at most one number in each cell (uniqueness)

29 29 Example (1,1,2) (1,2,1) (1,2,2) 43 (2,1,2) (2,1,3) (2,1,4) (2,2,1) (2,2,2) (2,2,4) (2,3,1) (2,3,2) (2,4,1) (2,4,2) (3,1,2) (3,1,4) (3,2,2) (3,2,4) (3,3,1) (3,3,2) (3,3,3) (3,4,1) (3,4,2) (3,4,4) 13(4,3,2) (4,4,2) (4,4,4) {(1,1,2)} {(1,2,1)  (1,2,2)} {(2,1,2)  (2,1,3)  (2,1,4)} {(2,2,1)  (2,2,2)  (2,2,4)} ……… {(4,3,2)} {(4,4,2)  (4,4,4)} {  (1,2,1)  (1,2,2)} {  (2,1,2)  (2,1,3)} {  (2,1,2)  (2,1,4)} {  (2,1,3)  (2,1,4)} ……… {  (4,4,2)  (4,4,4)}

30 30 Row Rule  CNF Each number appears at least in each row (definedness) Each number appears at most in each row (uniqueness) A number appears once in each row

31 31 Example (1,1,2) (1,2,1) (1,2,2) 43 (2,1,2) (2,1,3) (2,1,4) (2,2,1) (2,2,2) (2,2,4) (2,3,1) (2,3,2) (2,4,1) (2,4,2) (3,1,2) (3,1,4) (3,2,2) (3,2,4) (3,3,1) (3,3,2) (3,3,3) (3,4,1) (3,4,2) (3,4,4) 13(4,3,2) (4,4,2) (4,4,4) {(1,2,1)} {(1,1,2)  (1,2,2)} {(2,2,1)  (2,3,1)  (2,4,1)} {(2,1,2)  (2,2,2)  (2,3,2)  (2,4,2)} ……… {(4,3,2)  (4,4,2)} {(4,4,4)} {  (1,1,2)  (1,2,2)} {  (2,2,1)  (2,3,1)} {  (2,2,1)  (2,4,1)} {  (2,3,1)  (2,4,1)} ……… {  (4,3,2)  (4,4,2)}

32 32 Column Rule  CNF Each number appears at least in each column(definedness) Each number appears at most in each column(uniqueness) A number appears once in each column

33 33 Example (1,1,2) (1,2,1) (1,2,2) 43 (2,1,2) (2,1,3) (2,1,4) (2,2,1) (2,2,2) (2,2,4) (2,3,1) (2,3,2) (2,4,1) (2,4,2) (3,1,2) (3,1,4) (3,2,2) (3,2,4) (3,3,1) (3,3,2) (3,3,3) (3,4,1) (3,4,2) (3,4,4) 13(4,3,2) (4,4,2) (4,4,4) {(1,1,2)  (2,1,2)  (3,1,2)} {(2,1,3)} {(2,1,4)  (3,1,4)} ……… {(2,4,2)  (3,4,2)  (4,4,2)} {(3,4,4)  (4,4,4)} {  (1,1,2)  (2,1,2)} {  (1,1,2)  (3,1,2)} {  (2,1,2)  (3,1,2)} {  (2,1,4)  (3,1,4)} ……… {  (3,4,4)  (4,4,4)}

34 34 Block Rule  CNF Each number appears at least in each block(definedness) Each number appears at most in each block(uniqueness) A number appears once in each block

35 35 Example (1,1,2) (1,2,1) (1,2,2) 43 (2,1,2) (2,1,3) (2,1,4) (2,2,1) (2,2,2) (2,2,4) (2,3,1) (2,3,2) (2,4,1) (2,4,2) (3,1,2) (3,1,4) (3,2,2) (3,2,4) (3,3,1) (3,3,2) (3,3,3) (3,4,1) (3,4,2) (3,4,4) 13(4,3,2) (4,4,2) (4,4,4) {(1,2,1)  (2,2,1)} {(1,1,2)  (1,2,2)  (2,1,2)  (2,2,2)} {(2,1,3)} ……… {(3,3,3)} {(3,4,4)  (4,4,4)} {  (1,2,1)  (2,2,1)} {  (1,1,2)  (1,2,2)} {  (1,1,2)  (2,1,2)} {  (1,1,2)  (2,2,2)} ……… {  (3,4,4)  (4,4,4)}

36 36 Optimized Encoding The resulting CNF formula  is satisfiable iff Sudoku has a solution Smaller variables and clauses than previous encodings Number of variables are reduced 12 times on average in our experiments Number of clauses are reduced 79 times on average in our experiments

37 37 Agenda Introduction Background and Previous Encodings Optimized Encoding Experimental Results Conclusions

38 38 Experimental Results extended encodingproposed encodinganalysis of pre-assigned cells sizelevelvarsclausestimevarsclausestimekratio vars  claus  9x9easy729120130.0022017610.00263237 9x9hard729120180.0016410700.003037511 16x16easy40961240080.0164855980.0010441622 16x16hard40961240020.0179785520.009838515 25x25easy156257527920.071762196570.0429247938 25x25hard156257527780.211990241370.0527845831 36x36easy4665632717480.504186575950.06644501157 36x36hard4665632717680.673673453830.08664511372 49x49easy117649113051891.4776421124440.1312825315101 64x64easy26214433048912stack114401697720.0423845823195 81x81easy53144185060787stack177932660250.0639836130320

39 39 81x81 Puzzle 81x8153144185060787stack177932660250.06 Variables are reduced 30 times Clauses are reduced 320 times

40 40 Variable Reduction

41 41 Clause Reduction

42 42 Time Reduction

43 43 Variable Reduction Ratio

44 44 Clause Reduction Ratio

45 45 Agenda Introduction Background and Previous Encodings Optimized Encoding Experimental Results Conclusions

46 46 Conclusions J. Ouaknine, Sudoku as a SAT Problem, 2006 T. Weber, A SAT-based Sudoku Solver, 2005 Previous encodings + Ideal encoding techniques + Well used for small puzzles Props and cons  Too many clauses  Hard to handle large size puzzles such as 81x81

47 47 Conclusions Optimized encoding used to reduce a formula Proposed techniques + All given puzzles are successfully solved + Number of variables is greately reduced Results from 11 different size puzzles + Number of clauses is greately reduced + Execution time is greately reduced + Finally, encoding time is greately reduced Thank You!!


Download ppt "SAT Encodings for Sudoku Bug Catching in 2006 Fall Sep. 26, 2006 Gi-Hwon Kwon."

Similar presentations


Ads by Google