Modeling Sudoku as a CNF Formula

Slides:



Advertisements
Similar presentations
Resolution Proof System for First Order Logic
Advertisements

SAT Encoding For Sudoku Puzzles
UIUC CS 497: Section EA Lecture #2 Reasoning in Artificial Intelligence Professor: Eyal Amir Spring Semester 2004.
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
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View SAT.
Review: Constraint Satisfaction Problems How is a CSP defined? How do we solve CSPs?
Number puzzles in the paper Did you know there’s a whole range of number puzzles you can try in most newspapers? Click on the puzzles below to complete.
Formal Logic Proof Methods Direct Proof / Natural Deduction Conditional Proof (Implication Introduction) Reductio ad Absurdum Resolution Refutation.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
SAT Algorithms in EDA Applications Mukul R. Prasad Dept. of Electrical Engineering & Computer Sciences University of California-Berkeley EE219B Seminar.
A game of logic where the player must assign the numbers 1..9 to cells on a 9x9 grid. The placement of the numbers must be such that every number must.
SAT Solving Presented by Avi Yadgar. The SAT Problem Given a Boolean formula, look for assignment A for such that.  A is a solution for. A partial assignment.
SAT Solver Math Foundations of Computer Science. 2 Boolean Expressions  A Boolean expression is a Boolean function  Any Boolean function can be written.
SOLVING SUDOKU WITH MATLAB VERIFICATION FUNCTION correctness verification of the puzzle: checks if the current element appears twice in the same line,
Boolean Satisfiability and SAT Solvers
Quantified Formulas - Decision Procedure Daniel Kroening, Ofer Strichman Presented by Changki Hong 07 NOV 08.
CHAPTERS 7, 8 Oliver Schulte Logical Inference: Through Proof to Truth.
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)
Sudoku Solver Comparison A comparative analysis of algorithms for solving Sudoku.
HW #1. Due Mar 22 Midnight Verify the following program using SAT solver 1. Translate the program into a SSA form 2. Create a Boolean formula from.
Propositional Satisfiability A compound proposition is satisfiable if there is an assignment of truth values to its variables that make it true. When no.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
Explorations in Artificial Intelligence Prof. Carla P. Gomes Module Logic Representations.
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):
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.
Planning as Satisfiability (SAT-Plan). SAT-Plan Translate the planning problem into a satisfiability problem for length n of Plan garb 0 (proposition)present.
Monster (“Mega”) Sudoku
Custom Computing Machines for the Set Covering Problem Paper Written By: Christian Plessl and Marco Platzner Swiss Federal Institute of Technology, 2002.
CompSci Problem Solving: Sudoku  Rules of the Game Sudoku is played with a 9 by 9 "board" consisting of nine 3 by 3 sub-boards. The symbols 1 -
SAT Encodings for Sudoku Bug Catching in 2006 Fall Sep. 26, 2006 Gi-Hwon Kwon.
Knowledge Repn. & Reasoning Lecture #9: Propositional Logic UIUC CS 498: Section EA Professor: Eyal Amir Fall Semester 2005.
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.
Monster (“Mega”) Sudoku
Inference and search for the propositional satisfiability problem
Introduction to MiniSAT
More NP-complete Problems
A CIS 5603 Course Project By: Qizhong Mao, Baiyi Tao, Arif Aziz
The Propositional Calculus
Constraint Satisfaction Problems (CSPs)
More NP-complete Problems
Recovering and Exploiting Structural Knowledge from CNF Formulas
(xy)(yz)(xz)(zy)
Clause Learning and Intelligent Backtracking in MiniSAT
Watched Literals and Restarts in MiniSAT
Example Fill in the grid so that every row, column and box contains each of the numbers 1 to 9:
Where Can We Draw The Line?
More NP-complete Problems
Modeling Sudoku as a CNF Formula
Logic Use mathematical deduction to derive new knowledge.
Introduction to the Boolean Satisfiability Problem
Propositional Equivalences
Unit Propagation and Variable Ordering in MiniSAT
Decision Procedures An Algorithmic Point of View
Clause Learning and Intelligent Backtracking in MiniSAT
Unit Propagation and Variable Ordering in MiniSAT
Introduction to the Boolean Satisfiability Problem
Introduction to MiniSAT
Constraint satisfaction problems
HW #2. Due Apr 25 23:59 Do NOT forget to submit both a hardcopy solution to the HW box and a softcopy solution to TA.
Clause Learning and Intelligent Backtracking in MiniSAT
Sudoku.
Watched Literals and Restarts in MiniSAT
Modeling Sudoku as a CNF Formula
Instructor: Aaron Roth
Constraint satisfaction problems
Constraint Satisfaction Problems (CSP)
Presentation transcript:

Modeling Sudoku as a CNF Formula Spring 2018 CSCE 235H Introduction to Discrete Structures URL: cse.unl.edu/~cse235h All questions: Piazza

Sudoku Rules Each cell filled with a number 1…9 All nine numbers appear in each row, column, and 3x3 block (i.e., no duplicates)

Sudoku Rules Each cell filled with a number 1…9 All nine numbers appear in each row, column, and 3x3 block (i.e., no duplicates)

Defining the Variables asserts that the cell in row column is assigned value

Rules of the Game as Clauses Putting numbers in cells Put a number in a given cell / Put a number in every cell A given cell cannot take two numbers / No cell can take two numbers Constraining rows Every number must appear in every row Constraining columns Every number must appear in every column Constraining 3x3 blocks Every number must appear in every 3x3 block

Putting Numbers in Cells (1) 2 3 4 5 6 7 8 9 Put at least one number in [1,9] in cell

Putting Numbers in Cells (2) Put a number in cell Put a number in every cell

Putting Numbers in Cells (3) & Cell cannot take two numbers \neg{(p(i,j,1)\wedge(p,i,j,2))} \wedge \neg{(p(i,j,1)\wedge(p,i,j,3))} \wedge \ldots \wedge \neg{(p(i,j,1)\wedge(p,i,j,9))} \wedge \neg{(p(i,j,2)\wedge(p,i,j,3))} \wedge \neg{(p(i,j,2)\wedge(p,i,j,4))} \wedge \ldots \wedge \neg{(p(i,j,2)\wedge(p,i,j,9))} \wedge \neg{(p(i,j,3)\wedge(p,i,j,4))} \wedge \neg{(p(i,j,3)\wedge(p,i,j,5))} \wedge \ldots \wedge \neg{(p(i,j,3)\wedge(p,i,j,9))} \wedge \neg{(p(i,j,3)\wedge(p,i,j,4))} \wedge \neg{(p(i,j,3)\wedge(p,i,j,5))} \wedge \ldots \wedge \neg{(p(i,j,3)\wedge(p,i,j,9))} \wedge \ldots

Putting Numbers in Cells (4) Order of the literals does not matter so becomes

Putting Numbers in cells (5) Every cell takes at most one number

Constraining Rows (1) For every Row Number Select some column 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9

Constraining Rows (2) Every number must appear in every row

Constraining Columns (1) For every Column Number Select some row 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9

Constraining Columns (2) Every number must appear in every column

Constraining 3x3 Blocks (1) For every Block Number Select some cell in block 1 2 1 2 3 1 1 2 3 2

Constraining 3x3 Blocks (2) Every number must appear in every 3x3 block

Sudoku CNF Formula 729 variables 324 clauses with 9 literals 3240 total clauses (+ clauses for initial setup)

Redundant Clauses We can model a Sudoku as a SAT sentence in many ways Some models may have redundant clauses Removing redundant clauses does not change the problem and yields an equivalent formula Example: we can generate redundant clauses by applying inference rules on some clauses in the model Redundant clauses Do not change the model May speed the solving process.. Useful!

Declaring the Hints/Clues We add propositions as unary clauses corresponding to hints/clues (filled cells)

Solving Sudoku Total number of possible assignments Testing one billion assignments a second SAT solvers solve a Sudoku in milliseconds by aggressively pruning the search tree