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.
VARIABLE | STARTING CELL | DOMAIN
================================================
1ACROSS | 1 | {HOSES, LASER, SAILS, SHEET, STEER}
4ACROSS | 4 | {HEEL, HIKE, KEEL, KNOT, LINE}
7ACROSS | 7 | {AFT, ALE, EEL, LEE, TIE}
8ACROSS | 8 | {HOSES, LASER, SAILS, SHEET, STEER}
2DOWN | 2 | {HOSES, LASER, SAILS, SHEET, STEER}
3DOWN | 3 | {HOSES, LASER, SAILS, SHEET, STEER}
5DOWN | 5 | {HEEL, HIKE, KEEL, KNOT, LINE}
6DOWN | 6 | {AFT, ALE, EEL, LEE, TIE}
1ACROSS[3] = 2DOWN[1] i.e. the third letter of 1ACROSS must be equal to the first letter of 2DOWN 1ACROSS[5] = 3DOWN[1] 4ACROSS[2] = 2DOWN[3] 4ACROSS[3] = 5DOWN[1] 4ACROSS[4] = 3DOWN[3] 7ACROSS[1] = 2DOWN[4] 7ACROSS[2] = 5DOWN[2] 7ACROSS[3] = 3DOWN[4] 8ACROSS[1] = 6DOWN[2] 8ACROSS[3] = 2DOWN[5] 8ACROSS[4] = 5DOWN[3] 8ACROSS[5] = 3DOWN[5]
1ACROSS <- HOSES
2DOWN <- HOSES => failure, 1ACROSS[3] not equal to 2DOWN[1]
<- LASER => failure
<- SAILS
3DOWN <- HOSES => failure
<- LASER => failure
<- SAILS
4ACROSS <- HEEL => failure
<- HIKE => failure
<- KEEL => failure
<- KNOT => failure
<- LINE => failure, backtrack
3DOWN <- SHEET
4ACROSS <- HEEL
7ACROSS <- AFT => failure
................................
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;
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.
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) | |
===================================================================
(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) | |
===============================================================
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 | # | +---+---+---+---+---+