Due Tuesday, April 23 at 11:59 PM via Blackboard. PDF format required. Late assignments penalized 10% per day.
Write a constraint satisfaction problem solver to solve sudoku puzzles
of varying size (see the link for the rules if you're unfamiliar with the puzzles).
At least backtracking (BT), forward checking (FC), and minimum remaining values (MRV) must
be implemented; other heuristics can be
implemented for extra credit (see note below).
The goal is to obtain a performance comparison of various CSP strategies. The input to the solver is a Sudoku board, and the output should be a complete solution, along with the
number of consistency checks utilized.
Assignment
Starter Code
We've supplied basic starter code for representing a board, and reading the puzzles from the input files
you'll use for the assignment.
Python Starter Code
The python starter code includes the following functions:
sb = init_board("filename.extension")
sb = SudokuBoard(size, board_array)
sbA = sb.set_value(row,col,value)
where #row and col are 0 indexed
C++ Starter Code
The C++ starter code includes the following key functions:
Board * b = new Board(size);
Board * b = Board::fromFile(fileName)
b.set_square_value(row,col,value)
where #row and col are 1 indexed(!).
int sq = b.get_square_value(row,col)
where where #row and col are 1 indexed.
string boardStr = b.toString()
Input Puzzles
We've supplied specific input puzzles you'll use for this assignment (thanks to Stef
Schoenmackers of decide.com for these). Functions for reading the boards from files are included in the
sample code, but for completeness the files have the following format:
<board_size> - (board size will be 4, 9, 16, or 25)
<num_initial_values> - (The number of set cells in the initial state)
<row1> <col1> <value1> - value of the cell at row1, col1
<row2> <col2> <value2> - value of the cell at row2, col2
<row3> <col3> <value3> - value of the cell at row3, col3
... for a total of num_initial_values lines
Each row, col, and value is in the range [1, board_size].
This Example corresponds to the board:
2 2 3 4 4
Note: This assignment can be done in pairs. Each student must turn in their own, individual homework write-up along with the code.
Turn in the following:Problem | Backtracking | Forward Checking | <other methods> |
4x4 | 1234 | 567 | ... |
9x9 | 23456 | 7890 | ... |
16x16 | 789K | 12K | ... |
25x25 | (> 1M) | 234K | ... |