Constraint Satisfaction Revisited

Definitions

Example


      1   2   3   4   5
    +---+---+---+---+---+	Given the list of words:
  1 | 1 |   | 2 |   | 3 |		AFT	LASER
    +---+---+---+---+---+		ALE	LEE
  2 | # | # |   | # |   |		EEL	LINE
    +---+---+---+---+---+		HEEL	SAILS
  3 | # | 4 |   | 5 |   |		HIKE	SHEET
    +---+---+---+---+---+		HOSES	STEER
  4 | 6 | # | 7 |   |   |		KEEL	TIE
    +---+---+---+---+---+		KNOT
  5 | 8 |   |   |   |   |
    +---+---+---+---+---+	
  6 |   | # | # |   | # |       The numbers 1,2,3,4,5,6,7,8 in the crossword
    +---+---+---+---+---+       puzzle correspond to the words 
				that will start at those locations.

Representation

Example revisited:

Binary Constraints

Graphical Representation

Solution Methods

Generate and Test

Backtracking

Example Revisited:

Chronological Backtracking

Constraint Propagation

Constraint Propagation Algorithm

The AC-3 Algorithm

   Function AC-3 (CS-Problem) is
      Let Q be a set initialized to contain all the arcs of CS-Problem;
	NOTE: since the constraint graph is undirected, each of its
	      edges is represented by two directed arcs.
   begin
      Reduce all the domains of CS-Problem so that they satisfy the 
	 unary constraints;
      While Q is not empty
	 Remove an arc (xi xj) from Q;
	 If constraint-propagation(xi, xj) then
	    If the domain of xi is empty 
	        Return with failure;
	    else
	        Add to Q all arcs (xk xi), with k different than 
		    i and j, that are in the CS-Problem;
      Return with success;
   end AC-3;

The Constraint Propagation Check

   Function constraint-propagation (xi, xj: problem variables) is
      Let Change be a boolean variable initialized to false;
   begin
      For each value u in the domain of xi 
	 find a value v in the domain of variable xj such that 
	     u and v satisfy all the binary constraints of the problem. 
	 If there is no such v, 
	    remove u from the domain of xi and set Change to true;
      Return the value of Change;
   end constraint-propagation;

Upon completion of the AC-3 algorithm we usually have to run some form of the backtracking algorithm to find the solutions, if any.

AC-3 Applied to the Crossword Puzzle

We will write thevariable 1ACROSS as just 1A, 2DOWN as 2D, etc.
The AC-3 algorithm proceeds as follows:

	(xi,xj)	| NEW Di, if changed	| ADDED {xk,xi}
	===================================================================
	(1A 1D)	| 			| 
	(1D,1A) | 			| 
	(1A,2D)	|			|
	(2D,1A) |			|
	(1D,3A) |			|
	(3A,1D)	|			|
	(3A,2D)	|			|
	(2D,3A)	|			|
	===================================================================

AC-3 Example Continued

Here are the steps of the AC-3 algorithm in the crossword example.
	(xi,xj)	| NEW Di, if changed	| ADDED {xk,xi}
	===================================================================
	(1A 2D)	| HOSES,LASER		| (3D 1A)
	(3D,1A) | SAILS,SHEET,STEER	| (4A,3D) (7A,3D) (8A,3D)
	(4A,3D) | HEEL,HIKE,KEEL	| (2D,4A) (5D,4A)
	(7A,3D) | ALE,EEL,LEE,TIE	| (2D,7A) (5D,7A)
	(8A,3D)	| 			|
	(2D,4A)	| SAILS,SHEET,STEER	| (1A,2D) (7A,2D) (8A,2D)
	(5D,4A)	| KEEL,KNOT		| (7A,5D) (8A,5D)
	(2D,7A)	|			|
	(5D,7A)	| KEEL			| (4A,5D)
	(1A,2D)	| 			|
	(7A,2D) | EEL,LEE		| (3D,7A) (5D,7A) 
	(8A,2D)	| HOSES,LASER		| (3D,8A) (5D,8A) (6D,8A)
	(7A,5D)	| 			|
	(8A,5D)	|			|
	(4A,5D)	| HIKE			| (2D,4A) (3D,4A) 
	(3D,7A) |			|
	(5D,7A) |			|
	(3D,8A) | SAILS,STEER		| (1A,3D) (4A,3D) (7A,3D)
	(5D,8A) | 			|
	(6D,8A) | ALE			| 
	(2D,4A) | SAILS			| (1A,2D) (7A,2D) (8A,2D)
	(3D,4A) | STEER			| (8A,3D)
	(1A,3D) | HOSES			| (2D,1A) 
	(4A,3D) |			|
	(7A,3D) | LEE			| (2D,7A) (5D,7A)
	(1A,2D) |			|
	(7A,2D) |			|
	(8A,2D) |			|
	(8A,3D) | LASER			| (2D,8A) (5D,8A) (6D,8A) 
	(2D,1A) |			|
	(2D,8A) |			|
	(5D,8A) |			|
	(6D,8A) |			|
	===============================================================

Solution

Thus the solution is:
	      1   2   3   4   5
	    +---+---+---+---+---+	
	  1 | H | O | S | E | S |	
	    +---+---+---+---+---+	
	  2 | # | # | A | # | T |	
	    +---+---+---+---+---+	
	  3 | # | H | I | K | E |	
	    +---+---+---+---+---+	
	  4 | A | # | L | E | E |
	    +---+---+---+---+---+
	  5 | L | A | S | E | R | 
	    +---+---+---+---+---+
	  6 | E | # | # | L | # |
	    +---+---+---+---+---+