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

Slides:



Advertisements
Similar presentations
Hybrid BDD and All-SAT Method for Model Checking Orna Grumberg Joint work with Assaf Schuster and Avi Yadgar Technion – Israel Institute of Technology.
Advertisements

SAT Encoding For Sudoku Puzzles
Order encoding x i ↔ (X ≥ i)(X = 3) = [1,1,1,0,0] Problem (hard) Problem (hard) Solution CNF Encoding Finite Domain Problem Solving Model Constraint Model.
Satisfiability Modulo Theories (An introduction)
Propositional and First Order Reasoning. Terminology Propositional variable: boolean variable (p) Literal: propositional variable or its negation p 
CPSC 422, Lecture 21Slide 1 Intelligent Systems (AI-2) Computer Science cpsc422, Lecture 21 Mar, 4, 2015 Slide credit: some slides adapted from Stuart.
Lecture 23. Subset Sum is NPC
Properties of SLUR Formulae Ondřej Čepek, Petr Kučera, Václav Vlček Charles University in Prague SOFSEM 2012 January 23, 2012.
© 2011 Carnegie Mellon University Binary Decision Diagrams Part Bug Catching: Automated Program Verification and Testing Sagar Chaki September.
1 Boolean Satisfiability in Electronic Design Automation (EDA ) By Kunal P. Ganeshpure.
Formal Verification Group © Copyright IBM Corporation 2008 IBM Haifa Labs SAT-based unbounded model checking using interpolation Based on a paper “Interpolation.
Integer Programming Difference from linear programming –Variables x i must take on integral values, not real values Lots of interesting problems can be.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture NP-Completeness Jan Maluszynski, IDA, 2007
Shatter: Efficient Symmetry- Breaking for Boolean Satisfiability Fadi A. Aloul Igor L. Markov, Karem A. Sakallah The University of Michigan.
1 CS 4700: Foundations of Artificial Intelligence Carla P. Gomes Module: Satisfiability (Reading R&N: Chapter 7)
SAT Solver Math Foundations of Computer Science. 2 Boolean Expressions  A Boolean expression is a Boolean function  Any Boolean function can be written.
1 L is in NP means: There is a language L’ in P and a polynomial p so that L 1 ≤ L 2 means: For some polynomial time computable map r : x: x L 1 iff r(x)
Complexity Classes Kang Yu 1. NP NP : nondeterministic polynomial time NP-complete : 1.In NP (can be verified in polynomial time) 2.Every problem in NP.
The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial.
Boolean Satisfiability and SAT Solvers
Quantified Formulas - Decision Procedure Daniel Kroening, Ofer Strichman Presented by Changki Hong 07 NOV 08.
SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014.
Problem (hard) Solution CNF Satisfied assignment Encoding FINITE DOMAIN PROBLEM SOLVING Model Constraint Model Direct Constraint / Bits relation lost.
February 18, 2015CS21 Lecture 181 CS21 Decidability and Tractability Lecture 18 February 18, 2015.
Lecture 22 More NPC problems
Propositional Equivalences
INTRODUCTION TO ARTIFICIAL INTELLIGENCE COS302 MICHAEL L. LITTMAN FALL 2001 Satisfiability.
Explorations in Artificial Intelligence Prof. Carla P. Gomes Module 3 Logic Representations (Part 2)
1 The LPSAT Engine and its Application to Metric Planning Steve Wolfman University of Washington CS&E Advisor: Dan Weld.
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
Lacey Johnson Summer 2013 Student Research Project – James Madison University Sudoku can be described as a system of polynomials which can then be solved.
Propositional Satisfiability A compound proposition is satisfiable if there is an assignment of truth values to its variables that make it true. When no.
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View BDDs.
Explorations in Artificial Intelligence Prof. Carla P. Gomes Module Logic Representations.
1 P P := the class of decision problems (languages) decided by a Turing machine so that for some polynomial p and all x, the machine terminates after at.
Fitting a Function to the Difficulty of Boolean Formulas Greg Dennis NMM Final Project.
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View BDDs.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
SAT 2009 Ashish Sabharwal Backdoors in the Context of Learning (short paper) Bistra Dilkina, Carla P. Gomes, Ashish Sabharwal Cornell University SAT-09.
CPSC 422, Lecture 21Slide 1 Intelligent Systems (AI-2) Computer Science cpsc422, Lecture 21 Oct, 30, 2015 Slide credit: some slides adapted from Stuart.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong The Cook-Levin.
Tommy Messelis * Stefaan Haspeslagh Patrick De Causmaecker *
Planning as Satisfiability (SAT-Plan). SAT-Plan Translate the planning problem into a satisfiability problem for length n of Plan garb 0 (proposition)present.
Generating High-Quality Tests for Boolean Circuits by Treating Tests as Proof Encoding Eugene Goldberg, Pete Manolios Northeastern University, USA TAP-2010,
Monster (“Mega”) Sudoku
28.
NPC.
CSC 413/513: Intro to Algorithms
Custom Computing Machines for the Set Covering Problem Paper Written By: Christian Plessl and Marco Platzner Swiss Federal Institute of Technology, 2002.
NP-complete Languages
CSCI 2670 Introduction to Theory of Computing December 2, 2004.
CSCI 2670 Introduction to Theory of Computing December 7, 2005.
Dana Nau: Lecture slides for Automated Planning Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License:
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.
Sudoku Solutions Using Logic Equations Christian Posthoff The University of The West Indies, Trinidad & Tobago Bernd Steinbach Freiberg University of Mining.
NP-Completeness (2) NP-Completeness Graphs 4/13/2018 5:22 AM x x x x x
Hybrid BDD and All-SAT Method for Model Checking
NP-Completeness (2) NP-Completeness Graphs 7/23/ :02 PM x x x x
NP-Completeness (2) NP-Completeness Graphs 7/23/ :02 PM x x x x
NP-Completeness Proofs
Richard Anderson Lecture 26 NP-Completeness
Lecture 24 NP-Complete Problems
NP-Completeness (2) NP-Completeness Graphs 11/23/2018 2:12 PM x x x x
NP-Completeness Proofs
Modeling Sudoku as a CNF Formula
Propositional Equivalences
Modeling Sudoku as a CNF Formula
Modeling Sudoku as a CNF Formula
Instructor: Aaron Roth
NP-Completeness (2) NP-Completeness Graphs 7/9/2019 6:12 AM x x x x x
Presentation transcript:

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

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

3 3 What is Sudoku ? 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 Sudoku as SAT Problem Encoder SAT Solver Decoder CNF SAT? yes no Sudoku symbol table model  No solution found Solution found

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 Analysis of Previous Encodings Encoding Number of Variables Number of Clauses Minimal Efficient Extended

7 7 Exponential Growth in Clauses sizeminimalefficientextended 9x x x x x x x

8 8 Experimental Results minimal encodingefficient encodingextended encoding sizelevelvarsclausestimevarsclausestimevarsclausestime 9x9easy x9hard x16easy x16hard x25easy x25hard time time x36easy time time x36hard time time x49easy time time x64easy stack stack stack 81x81easy stack stack stack

9 9 Experimental Results minimal encodingefficient encodingextended encoding sizelevelvarsclausestimevarsclausestimevarsclausestime 9x9easy x9hard x16easy x16hard x25easy x25hard time time x36easy time time x36hard time time x49easy time time x64easy stack stack stack 81x81easy stack stack stack  No solution found Solution found

10 Motivations Sudoku was regarded as SAT problem  W Weber, A SAT-based Sudoku Solver, Nov  Lynce & Ouaknine, Sudoku as a SAT Problem, Jan  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 Agenda Introduction Background and Previous Encodings Optimized Encoding Experimental Results Conclusions

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 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 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 Set Notation Indexed generalized disjunction and union operators Re-definitions of clause and CNF using the operators

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 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 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 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 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 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 Analysis (Recap) Encoding Number of Variables Number of Clauses Minimal Efficient Extended

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

24 Example 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 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]= (1,1,2)

26 Variables Let V be a set of variables

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 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 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 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 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 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 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 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 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 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 Agenda Introduction Background and Previous Encodings Optimized Encoding Experimental Results Conclusions

38 Experimental Results extended encodingproposed encodinganalysis of pre-assigned cells sizelevelvarsclausestimevarsclausestimekratio vars  claus  9x9easy x9hard x16easy x16hard x25easy x25hard x36easy x36hard x49easy x64easy stack x81easy stack

39 81x81 Puzzle 81x stack Variables are reduced 30 times Clauses are reduced 320 times

40 Variable Reduction

41 Clause Reduction

42 Time Reduction

43 Variable Reduction Ratio

44 Clause Reduction Ratio

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

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 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!!