Skip to content

This is a simple exercise to use MiniSAT to solve any Sudoku Puzzle

Notifications You must be signed in to change notification settings

vivekkvvermaindia/Sudoku-Solver-using-MiniSAT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Sudoku-Solver-using-MiniSAT

Description:

SAT solver for Sudoku puzzles.

This program is a sudoku solver that will transform a sudoku puzzle (9x9) into an instance of the NP-complete SAT problem. It will read a sudoku puzzle table and convert it to a set of boolean formulae (used by SAT solvers) to solve the puzzle.

Instructions:

Run the following command (assuming minisat is installed on the machine, put all files in the core folder of minisat):

"python main.py input.txt"

Contents:

main.py

The main.py program will read in the input file and encode it into a string. This main file also includes code to generate the minimal number of clauses by writing it to a tempOutput.txt file after running each of the functions included in the second file (constraint.py).

constraint.py

The constraint.py includes the following functions:

Row: generate row constraints

Column: generate column constraints

smallbox: generate the 3x3 CNF grid

value: generate the prefilled CNF values from user input

individual: generate the individual CNF cells

utils.py

The utils.py contains a utility function convertBase9 which is used to generate a number by combining row number, column number and a value(1-9).

input.txt

Contains unsolved Sudoku Puzzle (follow the same input format)

Files generated by the program:

tempOutput.txt: Contains all generated constraints

SATOutput.txt: MiniSAT generated output

SolvedPuzzle.txt: Contains solved Sudoku Puzzle

Methodology:

The program begins by reading in the input file which is an unsolved 9x9 sudoku puzzle and it is minimally encoded and then pushed into miniSAT. MiniSAT will output if the problem is SATISFIABLE or UNSATISFIABLE. In the case of the sudoku problem, it is indeed SATISFIABLE. The SAT output gets outputted to the text file "SATOutput.txt". The program will then attempt to decode the puzzle encoding and then finally produce the solution to the problem, by outputting to the "SolvedPuzzle.txt" file.

About

This is a simple exercise to use MiniSAT to solve any Sudoku Puzzle

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages