Variables:
Use an array to present the grid, assuming it’s A[5][5]
Domain Values:
Each variable can take any of the letters A to Y, but some variables already have assigned values. Here take A[0][4]=’Y’ as an example.
Constraints:
1. Adjacent Letters: If two cells are adjacent (horizontally or vertically), their values must be adjacent in the alphabet.
2. Pre-assigned Values: Some cells already have assigned letters, and these cannot be changed.
3. Unique Letters Constraint: Each letter from A to Y must appear exactly once.
Constraint Propagation:
1. Initialization: Start by reducing the domain of each variable based on the pre-assigned values.
2. Consistency: Ensure that for every pair of adjacent cells, there exists a combination of letters that satisfies the adjacent letters constraint. This might further reduce the domains.
3. Forward: Choosing a random value from the current domain. When a value is assigned to a variable, immediately reduce the domain of all adjacent variables similar to step1 and step2.
4. Back tracing: If no value can be assigned to a variable that satisfies the constraints, backtrack to the previous variable and try a different value.
Solution:
The solution will be a complete assignment of letters to the grid, satisfying all constraints. This can be achieved through a recursive back tracing algorithm, where we choose a variable, assign a value from its domain, propagate constraints, and move to the next variable. If we encounter a dead end, we backtrack and try a different value.