CS531 Programming Assignment 3

SuDoKu

Due November 9, 10 AM

In this assignment you will be implementing a solver for SuDoKu. If you have not seen this before, the rules are quite simple. There is a grid of size 9X9 divided into 9 blocks of size 3X3. Some of the grid cells are filled with numbers from 1 to 9. You have to fill in the remaining cells in the grid with numbers from 1 to 9 so that each row, each column, and each 3X3 block, has all different numbers, the so-called all-diff constraint. An example puzzle is here .

The problem is easily seen to be a constraint satisfaction problem, with 3 kinds of constraints (row, column, and block). The variables are cells and the values are numbers 1-9. The algorithm is based on backtracking search plus constraint propagation. It maintains all possible candidate values, i.e., the domain, for each cell after each assignment. We implement a simpler version of constraint propagation, i.e., forward checking, which removes candidate values for a variable when it violate some constraints, given the currently assigned values for other variables.

The search begins by storing all possible values for each of the empty spots. Then it does constraint propagation. When the constraint propagation converges, then:
- if no candidates left for some cell, then backtrack from the current state.
- else pick the most constrained cell, and assign it a consistent value (keep other choices of values as options to backtrack to; there is no need to backtrack over the cell choice since all cells need to be filled).

Here is how our simple version of constraint propagation works:
Repeat each rule until it can no longer be applied. Then move to the next rule. If any rule causeed some values to be removed, go back to the first rule and check it again. Do this until the rules do not cause any change to the domains or assignments.

  1. Assign to any cell a value x if it is the only value left in its domain.
  2. Remove from any cell's domain a value x if it is assigned to some other cell in the same column, row, or block.
  3. Assign to any cell a value x if x is not in the domain of any other cell in that row, column, or block.
For an evaluation of the effectiveness of the heuristics, do the following "control" experiments:
- Instead of picking the most constrained slot, pick a slot randomly.
- In the constraint propagation step, in addition to the above 3 rules, use the following k-cells rule:
If the domains of k cells of a column, row or block are all the same set of k values, then remove those values from the domains of all other cells of that column, row or block. Implement only k=2 or 3. Simple illustration of this rule (thanks to Ronny Bjarnason):
 
    a b c   d e f   g h i
 1  - - - | - - - | - - -
 2  - - - | - - - | - - -
 3  - - - | - - - | - - -
  ------------------------
 4  - - - | 1 3 - | - - -
 5  - - - | 2 4 - | - - -
 6  - - - | 6 5 - | - - -
  ------------------------
 7  - - - | - - - | - - -
 8  - - - | - - - | - - -
 9  - - - | - - - | - - -

Domain(4f)=Domain(5f)=Domain(6f)={7,8,9}. So we can eliminate {7,8,9} from the domains of all other cells of column f.

There is a set of sample problems in my directory. The numbers are written in the file row-wise, with 0 representing empty slots. Each team should try to solve all the problems, starting with the easy ones. Report the number of problems solved and the number of backtrackings with each problem. Experts appear to grade the problems by the number and complexity of rules needed to solve them. Grade each problem, by the set of rules used in solving it. So for example, easy problems may be solved by only using the first and second rules, medium problems may be solved by using the first three rules, and hard and evil problems require the k-cells rule and possibly backtracking. Is this conjecture reasonably correct? Report also the average number of filled-in numbers (in the beginning) for each of these types of problems. Would this accurately reflect the difficulty of the problem?