SAT Encoding For Sudoku Puzzles

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Using Matrices in Real Life
Bellwork If you roll a die, what is the probability that you roll a 2 or an odd number? P(2 or odd) 2. Is this an example of mutually exclusive, overlapping,
Analysis of Algorithms
Combining Like Terms. Only combine terms that are exactly the same!! Whats the same mean? –If numbers have a variable, then you can combine only ones.
February 21, 2002 Simplex Method Continued
February 7, 2002 A brief review of Linear Algebra Linear Programming Models Handouts: Lecture Notes.
February 14, 2002 Putting Linear Programs into standard form
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
0 - 0.
ALGEBRAIC EXPRESSIONS
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULTIPLICATION EQUATIONS 1. SOLVE FOR X 3. WHAT EVER YOU DO TO ONE SIDE YOU HAVE TO DO TO THE OTHER 2. DIVIDE BY THE NUMBER IN FRONT OF THE VARIABLE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Maximal Independent Subsets of Linear Spaces. Whats a linear space? Given a set of points V a set of lines where a line is a k-set of points each pair.
Sep 16, 2013 Lirong Xia Computational social choice The easy-to-compute axiom.
Discrete Math Recurrence Relations 1.
PROLOG MORE PROBLEMS.
DIVISIBILITY, FACTORS & MULTIPLES
Ch 3 Sec 3: Slide #1 Columbus State Community College Chapter 3 Section 3 Solving Application Problems with One Unknown Quantity.
Patterns to help you learn your times tables!
3 Logic The Study of What’s True or False or Somewhere in Between.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Artificial Variables, 2-Phase and Big M Methods
Simultaneous Equations 6-Apr-17
Rahnuma Islam Nishat Debajyoti Mondal Md. Saidur Rahman Graph Drawing and Information Visualization Laboratory Department of Computer Science and Engineering.
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
More Two-Step Equations
Addition 1’s to 20.
25 seconds left…...
Test B, 100 Subtraction Facts
Complexity ©D.Moshkovits 1 Where Can We Draw The Line? On the Hardness of Satisfiability Problems.
11 = This is the fact family. You say: 8+3=11 and 3+8=11
Sep 15, 2014 Lirong Xia Computational social choice The easy-to-compute axiom.
Week 1.
2 x0 0 12/13/2014 Know Your Facts!. 2 x1 2 12/13/2014 Know Your Facts!
2 x /18/2014 Know Your Facts!. 11 x /18/2014 Know Your Facts!
2 x /10/2015 Know Your Facts!. 8 x /10/2015 Know Your Facts!
Solution of a 20-Variable 3-SAT Problem on a DNA Computer R. S. Briach, N. Chelyapov, C. Johnson, P. W. K. Rothemund, L. Adleman 발표자 : 문승현.
Distributed Constraint Satisfaction Problems M OHSEN A FSHARCHI.
Complexity ©D.Moshkovitz 1 NPC More NP-Complete Problems.
5 x4. 10 x2 9 x3 10 x9 10 x4 10 x8 9 x2 9 x4.
Parallel algorithms for expression evaluation Part1. Simultaneous substitution method (SimSub) Part2. A parallel pebble game.
EMIS 8374 LP Review: The Ratio Test. 1 Main Steps of the Simplex Method 1.Put the problem in row-0 form. 2.Construct the simplex tableau. 3.Obtain an.
Linear Programming – Simplex Method: Computational Problems Breaking Ties in Selection of Non-Basic Variable – if tie for non-basic variable with largest.
The Problem of K Maximum Sums and its VLSI Implementation Sung Eun Bae, Tadao Takaoka University of Canterbury Christchurch New Zealand.
Multiplication Facts Practice
A Case Study  Some Advice on How to Go about Solving Problems in Prolog  A Program to Play Connect-4 Game.
Variational Inference Amr Ahmed Nov. 6 th Outline Approximate Inference Variational inference formulation – Mean Field Examples – Structured VI.
Probabilistic sequence modeling II: Markov chains Haixu Tang School of Informatics.
Graeme Henchel Multiples Graeme Henchel
The Project Problem formulation (one page) Literature review –“Related work" section of final paper, –Go to writing center, –Present paper(s) to class.
0 x x2 0 0 x1 0 0 x3 0 1 x7 7 2 x0 0 9 x0 0.
Adding & Subtracting Mixed Numbers. Objective: To develop fluency in +, –, x, and ÷ of non-negative rational numbers. Essential Question: How.
SAT Solver CS 680 Formal Methods Jeremy Johnson. 2 Disjunctive Normal Form  A Boolean expression is a Boolean function  Any Boolean function can be.
Constraint Networks (cont.) Emma Rollón Postdoctoral researcher at UCI April 1st, 2009.
7x7=.
CS162 Week 2 Kyle Dewey. Overview Continuation of Scala Assignment 1 wrap-up Assignment 2a.
Propositional Satisfiability A compound proposition is satisfiable if there is an assignment of truth values to its variables that make it true. When no.
HW #2. Due Mar 27 23:59 Do NOT forget to submit both a hardcopy solution to the HW box and a softcopy solution to TA (Youngjoo Kim):
Planning as Satisfiability (SAT-Plan). SAT-Plan Translate the planning problem into a satisfiability problem for length n of Plan garb 0 (proposition)present.
SAT Encodings for Sudoku Bug Catching in 2006 Fall Sep. 26, 2006 Gi-Hwon Kwon.
Optimized SAT Encoding For Sudoku Puzzles Will Klieber and Gi-Hwon Kwon Sept 27, 2007 rev. 2 Changes from v1: Added a new slide after “A Better Encoding.
Modeling Sudoku as a CNF Formula
Propositional Equivalences
Modeling Sudoku as a CNF Formula
Modeling Sudoku as a CNF Formula
Presentation transcript:

SAT Encoding For Sudoku Puzzles Will Klieber and Gi-Hwon Kwon

What is Sudoku? Played on a n×n board. A single number from 1 to n must be put in each cell; some cells are pre-filled. Board is subdivided into n × n blocks. Each number must appear exactly once in each row, column, and block. Designed to have a unique solution. 6 1 2 5 3 9 4 8 7

Puzzle-Solving Process SAT Sol'n Puzzle Sol'n Puzzle CNF Encoder SAT Solver Decoder Mapping of SAT variables to Sudoku cells

Naive Encoding (1a) Use n3 variables, labelled “x0,0,0” to “xn,n,n”. Variable xr,c,d represents whether the number d is in the cell at row r, column c.

Example of Variable Encoding 3 2 1 4 Variable xr,c,d represents whether the digit d is in the cell at row r, column c. digit column row 5

Naive Encoding (1b) Use n3 variables, labelled “x0,0,0” to “xn,n,n”. Variable xr,c,d represents whether the number d is in the cell at row r, column c. “Number d must occur exactly once in column c”  “Exactly one of {x1,c,d, x2,c,d, ..., xn,c,d} is true”. How do we encode the constraint that exactly one variable in a set is true? 6

Naive Encoding (2) How do we encode the constraint that exactly one variable in a set is true? We can encode “exactly one” as the conjunction of “at least one” and “at most one”. Encoding “at least one” is easy: simply take the logical OR of all the propositional variables. Encoding “at most one” is harder in CNF. Standard method: “no two variables are both true”. I.e., enumerate every possible pair of variables and require that one variable in the pair is false. This takes O(n^2) clauses. [ Example on next slide ]

Naive Encoding (3) Example for 3 variables (x1, x2, x3). “At least one is true”: x1 x2  x3. “At most one is true”: (~x1 ~x2) & (~x1 ~x3) & (~x2 ~x3). “Exactly one is true”: (x1 x2 x3) & (~x1 ~x2) & (~x1 ~x3) & (~x2 ~x3).

All of the above constraints are independent of the prefilled cells. Naive Encoding (4) The following constraints are encoded: Exactly one digit appears in each cell. Each digit appears exactly once in each row. Each digit appears exactly once in each column. Each digit appears exactly once in each block. Each application of the above constraints has the form: “exactly one of a set variables is true”. All of the above constraints are independent of the prefilled cells. 9

Problem with Naive Encoding We need n3 total variables. (n rows, n cols, n digits) And O(n4) total clauses. To require that the digit “1” appear exactly once in the first row, we need O(n2) clauses. Repeat for each digit and each row. For your project, the naive encoding is OK. For large n, it is a problem. 10

Better Encoding

A Better Encoding (1a) Simple idea: Don’t emit variables that are made true or false by prefilled cells. Larger grids have larger percentage prefilled. Also, don’t emit clauses that are made true by the prefilled cells. This makes encoding and decoding more complicated. 12

(a  d) & (a  b  c) & (c  ~b  e). A Better Encoding (1b) Example: Consider the CNF formula (a  d) & (a  b  c) & (c  ~b  e). Suppose the variable b is preset to true. Then the clause (a  b  c) is automatically true, so we skip the clause. Also, the literal ~b is false, so we leave it out from the 3rd clause. Final result: (a  d) & (c  e). 13

New Encoding: Implementation Keep a 3D array VarNums[r][c][d]. Map possible variables to an actual variable number if used. Assign 0xFFFFFFF to true variables. Assign -0xFFFFFFF to false variables. Initialize VarNums[r][c][d] to zeros. For each prefilled cell, store the appropriate code (±0xFFFFFF) into the array elems for the cell. For every cell in the same row, column, or block: Assign -0xFFFFFF (preset_false) to the var that would put the same digit in this cell. 14

Room for Another Improvement It still takes O(n2) clauses to encode an “at most one” constraint. When one of these vars becomes true, the SAT solver examines clauses that contain the newly true var. This allows the SAT solver to quickly realize that none of the other vars in the “at most” set can be true. But requires (n)(n-1)/2 clauses. Improvement: Use ‘intermediary’ nodes (next slide). 8 1 7 2 6 3 5 4 15

Intermediary Variables Idea: Divide the n variables into groups containing only a handful of vars. Add an intermediary variable to each group of vars. An intermediary variable is to be true iff one of the (original) vars in its group is true. Add a constraint to ensure that at most one intermediary variable is true. If there are too many intermediary varibles, then they themselves may be grouped, forming a hierarchy. 8 1 7 2 i5-8 i1-4 6 3 5 4 16

Hierarchical Grouping x1 x3 x4 x6 x7 x9 x10 x12 x2 x5 x8 x11 17

Results Number of clauses for an “at most one” clause reduced from O(n2) to O(n log n). But in the larger puzzles, most of the cells are prefilled, so this only offered a 10%-20% performance benefit. 18