Docsity

Solving Sudoku with WalkSAT: A Probabilistic Approach to SAT Problems, Study Guides, Projects, Research of Stochastic Processes

Toggle sidebar
bg1
1-Introduction:
Sudoku is a widely popular logic-based number puzzle that consists of a 9×9 grid, subdivided
into 3×3 subgrids. The objective is to fill the grid so that each row, column, and subgrid contains
the numbers 1 to 9 exactly once. Due to its structured constraints, Sudoku can be transformed
into a Boolean Satisfiability (SAT) problem, where each cell's value is represented as
a Boolean variable in a logical formula to find a truth assignment that satisfies all logical
constraints—ensuring that each row, column, and subgrid obeys Sudoku rules. This allows
Sudoku to be tackled using SAT solvers.
While deterministic SAT-solving techniques could be applied in this problem, they can be
inefficient for large-scale instances. As an alternative approach, probabilistic algorithms such
as WalkSAT utilizes randomized local search and iteratively flips variable assignments to satisfy
more clauses while incorporating random moves to escape local optima to achieve more practical
results.
By modeling WalkSAT’s execution as a Markov Chain, the analyze of its behavior
using Random Walk theory is applied, where each state represents a potential Sudoku
assignment and each transition corresponds to a probabilistic modification of the solution.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Solving Sudoku with WalkSAT: A Probabilistic Approach to SAT Problems and more Study Guides, Projects, Research Stochastic Processes in PDF only on Docsity!

1 - Introduction: Sudoku is a widely popular logic-based number puzzle that consists of a 9×9 grid, subdivided into 3×3 subgrids. The objective is to fill the grid so that each row, column, and subgrid contains the numbers 1 to 9 exactly once. Due to its structured constraints, Sudoku can be transformed into a Boolean Satisfiability (SAT) problem , where each cell's value is represented as a Boolean variable in a logical formula to find a truth assignment that satisfies all logical constraints—ensuring that each row, column, and subgrid obeys Sudoku rules. This allows Sudoku to be tackled using SAT solvers. While deterministic SAT-solving techniques could be applied in this problem, they can be inefficient for large-scale instances. As an alternative approach, probabilistic algorithms such as WalkSAT utilizes randomized local search and iteratively flips variable assignments to satisfy more clauses while incorporating random moves to escape local optima to achieve more practical results. By modeling WalkSAT’s execution as a Markov Chain , the analyze of its behavior using Random Walk theory is applied, where each state represents a potential Sudoku assignment and each transition corresponds to a probabilistic modification of the solution.

2 - Problem Statement Rule 1: A Sudoku puzzle is represented by a 9×9 grid, which comprises nine 3×3 sub-grids (also called boxes). Some of the entries in the grid are filled with numbers from 1 to 9, whereas other entries are left blank. Rule 2: A Sudoku puzzle is solved by assigning numbers from 1 to 9 to the blank entries such that every row, every column, and every 3×3 sub-grid contains each of the nine possible numbers. In this problem, we will consider Sudoku puzzles with these properties: Property 1 Sudoku puzzles that have only one solution. Property 2 Sudoku puzzles that can be solved with only reasoning, i.e., with no search. To illustrate how to solve a Sudoku puzzle, let us consider entry (a) in the left-hand grid of Figure 2.

b-Sudoku Constraints as CNF Clauses: The constraints to be added to our SAT encoding refer to each entry, each row, each column and each 3x3 sub-grid, as illustrated in Figure 3. We may either use the minimal or the extended encoding, but given the context of our use case— which involves modeling WalkSAT's execution as a Markov Chain and analyzing its behavior using Random Walk theory, we tend to adopt the extended encoding to ensure a well-defined constraint structure. The extended encoding consists of the following logical constraints: 1.Each cell contains exactly one number:

  • There is at least one number in each entry:
  • There is at most one number in each entry:

2.Each number appears exactly once per row:

  • Each number appears at most once in each row:
  • Each number appears at least once in each row: 3. Each number appears exactly once per column
  • Each number must appear in a column at most once : - Each number appears at least once in each column: 4. Each number appears exactly once per 3×3 sub-grid Each number must appear in every 3×3 sub-grid at most once : Each number must appear at least once in each 3×3 sub-grid: In the extended encoding, the resulting CNF formula consists of 11,988 clauses , excluding the unit clauses corresponding to pre-assigned Sudoku entries. These clauses can be categorized as follows: - Nine-ary clauses (324 in total): These clauses ensure that each number appears at least once in every row, column, 3×3 sub-grid, and cell. Since there are 4 sets of at-least-one constraints , each applied to a 9×9 grid, the total number of nine-ary clauses is:

In the context of our use case, WalkSAT treats the Sudoku puzzle as a SAT instance, where each variable represents a cell's assignment and each clause enforces a Sudoku constraint (row, column, and subgrid rules). The algorithm randomly explores possible assignments, continuously flipping variables until a valid Sudoku solution is found or a stopping condition is met. WalkSAT algorithm for Sudoku is considered random walk on a Markov chain where each state represents a Sudoku grid with a certain number of unsatisfied constraints with:

- States: Each state represents a partially completed Sudoku grid, which includes the current assignments for all cells in the grid, and contains number of constraint violations ( valid Sudoku solution would have 0 constraint violations , with:  S 0 is the initial state with a random Sudoku grid.  Sn is the final solution state, where all constraints are satisfied (no violations). - Actions (Transitions): At each state, the WalkSAT algorithm picks an unsatisfied clause (a constraint violation) and flips the value of a variable by changing the number in one of the grid cells), considered transition from one state to another.

  • The transition probability depends on the heuristic used: Random flip : A variable is flipped randomly within an unsatisfied clause with probability p by moving from Si (with i violations) to Si+1 (state with more violations). Greedy flip : A variable is flipped to minimize the number of violations, possibly choosing the variable that maximizes the satisfaction of unsatisfied clauses with probability 1−p, by moving from state Si(with i violations) to Si+1 (state with fewer violations). With an assumption of p>1/2, to allow the algorithm to make a greedy move (improve the solution) than a random move (regress), with a higher chance of making progress toward the solution with each step. Expected Steps from State Si to Sn:

Let E[Ni] represent the expected number of steps from state Si to the solution state Sn.

The recurrence relation for E[Ni] is: where:

pE[Ni+ 1 ] represents the expected steps if a greedy move is taken.  qE[Ni− 1 ] represents the expected steps if a random move is taken. Where: α=p/q Time Complexity Analysis: The complexity of WalkSAT depends on the value of p:

  • When p=1/2: The expected time grows quadratically with the problem size n, giving us:

- When p>1/2: The expected time grows linearly with the problem size n, giving us:

- When p<1/2: The expected time grows exponentially with the problem size n, giving us: 4 - Implementation:

6 - Results: