Due Tuesday, April 29 at 11:59 PM via Blackboard. PDF format required. Late assignments penalized 10% per day.

Assignment 2

Write a constraint satisfaction problem solver to solve sudoku puzzles of varying size (see the link for the rules if you're unfamiliar with sudoku puzzles). 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 (for this assignment, this is equal to the number of variable assignments your code makes).

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:

C++ Starter Code

The C++ starter code includes the following key functions:

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
 34 
4   

When testing your code, it will help to try some easy test boards, which you can find here. You want more boards? For further testing you may use these boards. Note that for the larger problems, without powerful heuristics your program will not terminate in a reasonable amount of time -- you should choose an upper bound to the number of consistency checks you make so that the program terminates in, say, 10 minutes.

What to Turn In

Note: This assignment can be done in groups. Each student must turn in their own, individual homework write-up along with the code.

Turn in the following:
  1. Code
    1. (3 points) Your code
    2. (1 point) Describe who within your team performed which piece of the design/programming effort.
  2. Write-up
    1. (1 point) Briefly explain your code's representation of each of the following, in 1-2 sentences each: the board, variables, constraints, and the states.
    2. (1 point) How do you implement forward checking?
    3. (1 point) Make a table comparing the performance of the heuristics (in terms of number of consistency checks, i.e. variable assignments) for these test problems: 4x4 9x9 16x16 25x25
    4. The table should have the following format (numbers are random)
      ProblemBacktrackingForward CheckingMRV+MCVMRV+MCV+LCV
      4x41234567......
      9x9234567890......
      16x16789K12K......
      25x25(> 1M)234K......
    5. (2 points) Comment on your results in about 100 words: what trends do you see, in terms of scalability across the various heuristics? Are these as expected?
    6. (1/2 point each) Implement the following heuristics. For each one, describe how you implemented it and evaluate it within the table in problem 3 above.
      • MRV + most constraining variable.
      • MRV + most constraining variable + least constraining value.
If your program does not work, you may still discuss your methodology and what went wrong, and any possible ways to fix this. Considerable credit can still be earned even if the program doesn't work, provided the writeup is of sufficient quality.