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.
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"
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).
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
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).
Contains unsolved Sudoku Puzzle (follow the same input format)
tempOutput.txt: Contains all generated constraints
SATOutput.txt: MiniSAT generated output
SolvedPuzzle.txt: Contains solved Sudoku Puzzle
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.