Upload
dinhkhanh
View
237
Download
1
Embed Size (px)
Citation preview
15
Chapter 2
Existing Literature on Sudoku Puzzle: A Review
Overview
In this chapter, we are going to study about the different existing Sudoku solving techniques.
This chapter is organized into four sections. In the first section, we have briefly discussed about
the nature of the puzzle problem. In Section 2.2, we have considered and illustrated different
Sudoku solving algorithms. In Section 2.3, we have talked about the total number of different
Sudoku instances. A brief summary of the chapter is presented in Section 2.4.
2.1 Nature of the Puzzle Problem
Yato and Seta proved that a Sudoku instance is a type of Latin square [10]. Colbourn proved the
NP-completeness of partial Latin square completion by showing a reduction from 1-in-4 SAT to
this problem [26]. Therefore, we can conclude that solving an instance of Sudoku problem is also
NP-complete [10].
The NP (Non-deterministic Polynomial time computable) class of problems is those problems
whose solution for some instance of such a problem is to be guessed but verification of the
solution as correct or not could be performed in polynomial time. For example, for the Travelling
Salesman Problem (TSP), once we are given a tour (means somehow a tour is obtained /
guessed), it is easy to verify (or compute) the tour cost (or length) in polynomial time. However,
even if the TSP (and all the problems in NP) can have a (guessed) solution that can be verified in
polynomial time, nobody knows an algorithm that can solve the problem in polynomial time. If
we are able to show that P = NP (i.e., all NP problems can be solved in polynomial time or
belonging to the class P of problems), then we know that we can solve a wide range of difficult
problems in polynomial time. NP problems are known as non-deterministic polynomial (time
computable), because if we have a non-deterministic machine, which is able to guess correctly at
each decision point, then it is able to solve the problem in polynomial time, which is the same as
verifying the solution.
16
Showing that P = NP (or the reverse) is one of the most important open questions in theoretical
computer science and, in fact, is one of the seven most important problems across all of
mathematics according to Devlin [27]. However, it is widely believed that P NP.
NP-complete problems are considered to be the hardest problems in NP. The definition of an NP-
complete problem is that it is in NP and every other problem in NP is reducible to it. By
reducible we mean that there is a polynomial time algorithm that can transform an instance of
one problem to a corresponding instance of another problem. These properties mean that if we
ever find an efficient (polynomial time) algorithm for any NP-complete problem, then we have
an efficient algorithm for solving all NP-complete problems, as we have a way of transforming
one problem instance to another, in polynomial time. To show that a problem is NP-complete, it
is sufficient to show that it is in NP and can be transformed from another NP-complete problem
by a polynomial bounded algorithm.
At present, all known algorithms for NP-complete problems require time that is super
polynomial in the input size, and it is unknown whether there are any faster algorithms.
The following techniques can be applied to solve computational problems in general, and they
often give rise to substantially faster algorithms:
Approximation: Instead of searching for an optimal solution (that requires exponential time
and/or space), search for an “almost” optimal (or close to optimal) one (in polynomial time).
Randomization: Use randomness to get a faster average running time, and allow the
algorithm to fail with some small probability. Note that the Monte Carlo method is not an
example of an efficient algorithm, although evolutionary approaches like Genetic evolution
or Genetic algorithm may be considered as an efficient wayout.
Restriction: By restricting the structure of the input (e.g., planar graphs in place of general
graphs), faster algorithms are usually achievable.
Parameterization: Often there are fast algorithms if certain parameters of the input are
fixed.
Heuristics: The objective of a heuristic is to produce a solution in a reasonable time frame
that is good enough for solving the problem at hand. This solution may not be the best of all
the actual solutions to this problem, or it may simply approximate the exact solution. But it
17
is still valuable because finding it does not require a prohibitively long time. Heuristics and
meta-heuristics are only viable option for solving an NP-complete problem.
Metaheuristics: Metaheuristics are general algorithmic methods which search for a solution
of a specific problem. They are normally used when no deterministic algorithms for a
problem exist or the calculation of a satisfying solution would take too long. As they are
very general, they can be used on a wide range of problems and even without specific
knowledge about the problem or the solution to it. The drawback is that they are not as
efficient as a specific algorithm for the problem and the less knowledge about a problem is
available the less efficient is the search process. In the extreme case, without problem
knowledge, the search process would be similar to random search. These conflicts with the
generality of the approach as to design an effective heuristic, it needs to become more
problem-specific. By doing so, the algorithm is only efficiently applicable to a specific
problem and not anymore to others. One can also only be certain to find an optimal solution
and near optimal solutions with a certain probability. Therefore, they are mostly used in
optimization tasks where sub-optimal solutions are sufficient.
What most of them have in common, regarding their functionality, are the following points:
• Random initialization or selection of a starting point.
• Execution of one or more, random, moves in the neighbourhood of the starting point.
• Evaluation of the quality of new position(s).
Different termination conditions could be a high enough quality of the solution, a user defined
time budget for the algorithm or no gain in quality for a certain amount of time.
Each of the mentioned steps is very dependent on the specific metaheuristic.
2.2 A Study on Different Existing Sudoku Solving Techniques
In this section, we have made an exhaustive study on different Sudoku solving techniques. This
work is published in [28, 29, 30, 31]. There are quite a few logic based techniques that
researchers use to solve this problem. Some are basic simple logic, some are more advanced.
Depending on the difficulty of the puzzle, a blend of techniques may be needed in order to solve
18
a puzzle. We have briefly classified the different methodologies for solving Sudoku puzzle into
three groups.
1) Backtracking based Methodologies: These methods use the backtracking technique for
solving the Sudoku puzzles. These also include the improved methods of backtracking, such as
(a) Forward Checking,
(b) Constraint Propagation,
(c) Minimum Remaining Values, and
(d) Hill Climbing.
2) Elimination based Strategy: Here a list of probable candidates is created for each cell of the
puzzle in the beginning. Then candidates are eliminated based on certain rules such as:
(a) Unique Missing Candidate,
(b) Naked Single,
(c) Hidden Single,
(d) Lone Ranger,
(e) Locked Candidate,
(f) Twin,
(g) Triplet,
(h) Quad,
(i) X-Wing,
(j) XY-Wing,
(k) XYZ-Wing,
(l) Swordfish,
(m) Colouring,
(n) Forcing Chains, and
(o) Tuleja’s Theorem.
19
3) Soft Computing based Optimization Technique: Different optimization techniques are used
to select the best candidate for a particular Sudoku cell. It includes the following methodologies:
(a) Cultural Genetic Algorithm (CGA),
(b) Repulsive Particle Swarm Optimization (RPSO),
(c) Quantum Simulated Annealing (QSA),
(d) Hybrid Genetic Algorithm and Simulated Annealing (HGASA),
(e) Bee Colony Optimization (BCO), and
(f) Artificial Immune System (AIS) based Optimization.
A 9×9 Sudoku puzzle can be divided into nine 3×3 minigrids. We have labelled each minigrid
from 1 to 9, with minigrid 1 at the top-left corner and minigrid 9 at the bottom-right corner;
minigrid numbers are shown in faded larger font size in Figure 2.1. Also we refer to each cell in
the grid by its row number followed by its column number, as shown in the same figure.
Figure 2.1: The structure of a 99 Sudoku puzzle (problem) with its nine minigrids of size 33
each as numbered (in grey outsized font) 1 through 9. Representation of each cell of a Sudoku
puzzle and some example givens (or clues coloured by red) in the remaining cells. So, the cells
are [1,1] through [9,9], and the distinct cells may have some clues as well. Minigrid numbered 1
consists of the cell locations [1,1], [1,2], [1,3], [2,1], [2,2], [2,3], [3,1], [3,2], and [3,3], minigrid
numbered 2 consists of the cell locations [1,4], [1,5], [1,6], [2,4], [2,5], [2,6], [3,4], [3,5], and
[3,6], and so on.
8 9
6 5
7
4
3 2 1 [1,2]
[1,3]
[1,4]
[1,5]
[1,6]
[1,7]
[1,8]
[1,9]
[2,1] [2,2]
[2,3]
[2,4]
[2,5]
[2,6]
[2,7]
[2,8]
[2,9]
[3,1]
[3,3]
[3,2]
[3,4]
[3,5]
[3,6]
[3,7]
[3,8]
[3,9]
[4,1]
[4,2]
[4,3]
[4,4]
[4,5]
[4,6]
[4,7]
[4,8]
[4,9]
[9,1]
[9,3]
[9,2]
[9,4]
[9,5]
[9,6]
[9,7]
[9,8]
[9,9]
[6,1]
[6,3]
[6,2]
[6,4]
[6,5]
[6,6]
[6,7]
[6,8]
[6,9]
[1,1]
6 1
9
7
8
5 6
7 6 5
9
7
20
Now we discuss on backtracking based methodology for solving Sudoku puzzle.
2.2.1 Backtracking based Methodology
The most common technique for solving Sudoku puzzle is backtracking [15]. The basic
backtracking algorithm works as follows. The program places number 1 in the first empty cell. If
the choice is compatible with the existing clues, it continues to the second empty cell, where it
places a 1 (in some other row, column, and minigrid). When it encounters a conflict (which can
happen very quickly), it erases the 1 just placed and inserts 2 or, if that is invalid, 3 or the next
legal number. After placing the first legal number possible, it moves to the next cell and starts
again with a 1 (or a minimum possible acceptable value). If the number that has to be altered is a
9, which cannot be raised by one in a standard 99 Sudoku grid, the process backtracks and
increases the number in the previous cell (or the next to the last number placed) by one. Then it
moves forward until it hits a new conflict. In this way, the program may sometimes backtrack
several times before advancing. It is guaranteed to find a solution if there is one, simply because
it eventually tries every possible number in every possible location. This algorithm is very
effective for a size of two puzzles. Unfortunately, for a size of three puzzles, there are nine
possibilities for each square. This means that there are roughly 981−n
possible states that might
need to be searched, where n is the number of given values. Obviously this version of
backtracking search does not work for a size of three puzzles. Fortunately, there are several
means by which this algorithm can be improved: Constraint Propagation [32], Forward
Checking [32], and Choosing Most Constrained Value First [32] are some of them. The allied
algorithm is as follows where we may view the algorithm at a glance.
Step 1: There are 81 cells c[i] in a 99 Sudoku puzzle, where i = 1, 2, …, 81.
Step 2: Consider the sequence {k1, …, kn}, where n is the number of empty cells and each ki is
the index of such a cell.
Step 3: Set i = 1.
Step 4: Set ti = 1.
Step 5: Set c[ki] = ti.
Step 6: Check the grid for validity then:
• If valid, set i = i+1.
21
– If i = n+1, we stop with success.
– If i = 0, we stop with failure.
– Otherwise, go to Step 4.
• If invalid and ti < 9, then set ti = ti+1 and go to Step 5.
• If invalid and ti = 9 then:
– Unset c[ki].
– Set ti−1 = ti−1+1.
– Set i = i−1.
– Go to Step 5.
2.2.1.1 Forward Checking
The first improvement on backtracking search is forward checking. Notice that the old version of
backtracking search had to place a value and then check for conflicts. Instead, it is easier to
maintain a list of which possible values each square can possibly have given the other numbers
that have been assigned. Then while the values are being assigned to that square, only consider
the ones that do not directly conflict with the other already placed numbers. For a size three
puzzle forward checks can be stored in a nine by nine Boolean array. Basically each square has
its own array of nine Boolean values corresponding to each of the numbers that could possibly
go in that square. If the third value in the array is set to false, then that square cannot contain a
three. Maintaining these lists is simple. Whenever a new value x is assigned, go to every other
square in the same row, column, and box, and mark false in its array for value x. Storing this
information can be used in two ways. First, it can be used to verify that no value is ever assigned
that directly conflicts with another assigned value. Second, if the array for any square contains
all false values, then there is no possible value for that square and the most recently assigned
value is wrong. Using forward checking the backtracking search can now solve size three
puzzles.
2.2.1.2 Constraint Propagation
Forward checking can only catch conflicts right before they cause a certain branch to fail. It is
possible to detect errors even earlier and prune off entire branches.
22
Consider the following size two puzzles, as shown in Figure 2.2.
Figure 2.2: A size two (2× 2) Sudoku puzzle for executing constraint propagation.
It may seem like a good idea to place a 4 in the shaded cell. It does not immediately conflict with
any other locations and after placing it, all of the cells still have possible values. Next look at the
cell right below the shaded one, it must be a 2. Filling in a 2 there, however, leaves the lower left
cell with no possible value. This may not seem like a big deal, it only takes an extra two
assignments to realize that the 4 was wrong, but what if the 2 is not the next assignment. If the
search is moving from left to right across the rows, it will assign the three empty cells to the right
of the shaded one first. Depending on the possible values that these cells have, there may be up
to three layers of branching before reaching the conflict. Each branch must now fail separately
before the search realizes that the 4 was a bad choice. The result is an exponential increase in the
time needed for the search to realize that the 4 was a bad choice. The solution is to assign values
that only have one possible choice immediately. This is known as constraint propagation [32].
After each value is assigned by the search algorithm, constraint propagation iterates through the
squares assigning values to cells with only one possible value. If a cell has no possible values,
the algorithm fails and returns to the search which reselects the last value. If multiple values are
assigned by constraint propagation, then they are all repealed at once upon a fail. In the example
above after the 4 is assigned, constraint propagation realizes that the space below the 4 must be a
2. It then notices that the lower left corner has no possible value and fails, returning to the search,
which chooses another value for the shaded cell.
2.2.1.3 Minimum Remaining Values
Another method for improving the backtracking search is the minimum remaining values
heuristic [32]. The minimum remaining values heuristic is used to alter the order in which cells
are guessed in order to reduce the number of branches at each level. In essence, instead of
choosing the first empty cell, the cell with the least number of possible values is chosen. For
1
3
4
4
2
3
23
example, in the puzzle given in Figure 2.3, one of the three shaded cells would be chosen next.
This is because the two shaded cells have two possible values and the other cells have three
possible values.
Figure 2.3: A size two (2×2) Sudoku puzzle with minimum remaining values.
By choosing the square with only two possible values instead of three, the search tree only
branches in two directions instead of three. Essentially, the search tree is reduced in size by a
factor of two-thirds.
2.2.1.4 Hill Climbing
Given the size of the state space, it is logical to use a search method with a heuristic function to
avoid searching less promising sections of the state space. One type algorithm that meets this
criterion is hill climbing. Hill climbing algorithms work by generating a list of successors of the
current state, then choosing the one with the lowest heuristic value. In order to apply hill
climbing to Sudoku, three things must be defined: the start state, the successor function, and the
heuristic function. One way to go about this is to fill in each box so that it contains the numbers 1
to n2 and allows successors to be generated by switching values within the same box [13].
Instead of filling in the boxes with the numbers 1 to n2 the rows will be filled, but the idea is the
same. Let the start state be defined as the initial puzzle with all of the empty spaces filled in such
a way that each row contains the numbers 1 to n2. Using this as a start state, the successor
function can be defined as swapping any two non-fixed values in the same row. The heuristic can
simply be the sum of the number of conflicts that appear within each column and each box. Since
each row has exactly the numbers 1 to n2 there are no conflicts within the rows. Hill climbing
can successfully solve size two puzzles intermittently.
2.2.2 Elimination based Strategies
In this approach, based on the given clues a list of possible values for every blank cell is first
obtained. Then using the following different methods such as Unique Missing Candidate, Naked
single, Hidden single, Lone ranger, Locked candidate, Twin, Triplet, Quad, X-Wing, XY-Wing,
1 3
9 1 3 2
4 5 7
1 3
6 1 3 3 6
24
XYZ-Wing, Swordfish, Colouring, Tuleja’s Theorem, and so on we eliminate the multiple
possibilities of each and every blank cell, satisfying the constraints that each row, column, and
minigrid should have the numbers 1 through 9 exactly once. Strategies in this section are
mathematically obvious, although searching for them in a puzzle may sometimes be difficult,
simply because there are a lot of things to look for. Most puzzles ranked as “easy” and even
some ranked “medium” can be completely solved using only techniques discussed in this section.
The methods are presented roughly in order of increasing difficulty for a human. An instance of
a Sudoku puzzle and its possible values for each blank cell are shown in Figures 2.4(a) and
2.4(b), respectively.
After maintaining the list of possible values (candidates), the different elimination based
methods are applied to it based on certain rules. In the next subsections we are going to discuss
different elimination based strategies.
2.2.2.1 Unique Missing Candidate
If eight of the nine elements in any row, column or minigrid are already determined, the final
element has to be the one that is missing. When most of the cells are already filled in, this
technique is heavily used. Similarly, if eight of the nine values are impossible for a given cell,
that cell’s value must be the ninth. This technique is published in [27].
(a)
2
4 5 7
6 8
2
5
3
7
5 4
6 1
9
7
8
5 6
7 6 5
9
5 1
8 2
7
6
1 3 4
5 7 9
1 3
9
1 3
2
4 5 7
1 3
6
8 9
1 3
8
3 6
8 9
6 8 1 3 4
7 9
1 9
1 9
2
2 3
4 9
1 4
5 1 4
9 1 7
8
1 6
8 9 1 2
4 6
7
7
7
2 3
8
5 3 4
2 3
8 9
6 1
9 3
7
8
5 6
7 6 5
9
5 1
8
9 2
3 4 7
6
2 3
4
5 9
1 3 4
7 9
1 3 4
5 7 9
2 4 7
8 9
1 4 6
8 9
3 8
9
2 3
4 9
3 4
8 9 1 3
7 9
1 3
7 9 3 4
5
8 9
2 3
4 9
4 9
1 2
3
8 9
1 2
3
4 8
1 2
3
4 7 9
1 3
4
7 9
3 5
6 8
1 2
3 4
1 3
4 8
1 2 3
4 7 9
2 4
8 1 2
3
1 3
4 2 4
8
3 8
1 2
3 8
1 2
3 4
1 2
3 4 1 3
4 8
3 6
(b)
25
Figure 2.4: (a) An instance of a Sudoku puzzle. (b) Potential values in each blank cell are
inserted based on the given clues of the Sudoku instance in Figure 2.4(a); here green digits are
naked singles. (c) The concept of naked singles is preferably used to reduce the domain of
probable candidate values in each blank cell, and the process is successive in nature to find out
consequent naked singles, as much as possible. As for example, the naked single for cell [9,8] is
2, as 4 and 8 have already been recognized as naked singles along row 9 and column 8; then 8 is
a naked single for cell [7,8], as 2 and 4 are already identified naked singles along column 8, and
so on.
Figure 2.5: A Sudoku puzzle with unique missing candidate in cell [5,3].
6
8
2
9 1
3 8
4
7
7 1
2
7 8 9
1
1 8
3 2
9
4
1
6
5
6
1
3
5
8 3
4 5
2 6
(c)
1
2
4
5
7
6
8
2
5
8
7
5 3 4
6 1
9 3
7 8
8
5 6
7 6 5
9
5
1
8 9 2
4 7
6
1 3 4
5 7 9
1 3
9
1 3
6
8 9
1 8 6 8
9
1 3 4
7 9
1 9
1 9
2 3
4 9
1 4
1 4
9
3
5
1 7
1 6
8 9 1 2
4 6
2 8
2 8
9 3 4
2 3
4
5 9
6
8 9
1 3 4
7 9
1 3 4
5 7 9
2 4
7 8
1 4 6
8 9
8 9
2 3
4 9
3 4
8 9
3 6
1 7 1 7
3 4
5
8 9
2 3
4 9
1 2
8 9
1 2
4 8
1 2
3
4 7 9
1 3
4
7 9
5 6
8
1 2
3 4
1 3
4 8
1 2 3
4 7 9
2 4
8 1 2 1 4
2 4
8
1 2
8
1 2
3 4
1 2
4 1 3
4 8
26
For example, consider the puzzle shown in Figure 2.5. In this figure we can find a unique
missing candidate is present in cell [5,3]. Because in the third column of the puzzle all other cells
are already been filled up and only the cell [5,3] remains, where 2 is the only possible option.
This strategy is also known as obvious strategy.
2.2.2.2 Naked single
For any given Sudoku cell, imagine listing of all the candidates from 1 to 9 in each unfilled cell.
Then, for every cell, whose value v is determined, cross off every instance of v as a possible
candidate in the row, column, and minigrid to which that cell belongs to. The remaining values
in each cell represent possible values that could possibly be inserted there. If, after such an
elimination of the impossible candidates, only a single possible value remains, that situation is
referred to as a naked single [14] and that one remaining value can be assigned to the square.
Figure 2.6: An instance of Sudoku puzzle, where hidden singles can be found in cell [7,2] and
[4,9].
After assigning the probable values for each blank cell, as shown in Figure 2.4(b), we obtain the
naked singles 3, 9, and 3 at locations [5,2], [5,8], and [8,3], respectively. So, we can directly
assign these values to these cells. Then we eliminate these digits (or naked singles) from each of
the corresponding row, column, and minigrid. Hence, after elimination of these numbers, as
stated above, we obtain a modified (reduced) status of each blank cell as shown in Figure 2.4(c),
wherein several other naked singles could be found (and this process is recursive until no naked
singles are found).
1
2
4
5
7
6
8
2
5
8
7
5 3 4
6 1
9 3
7 8
8
5 6
7 6 5
9
5
1
8 9 2
4 7
6
1 3 4
5 7 9
1 3
9
1 3
6
8 9
1 8 6 8
9
1 3 4
7 9
1 9
1 9
2 3
4 9
1 4
1 4
9
3
5
1 7
1 6
8 9 1 2
4 6
2 8
2 8
9
3 4
2 3
4
5 9
6
8 9
1 3 4
7 9
1 3 4
5 7 9
2 4
7 8
1 4 6
8 9
8 9
2 3
4 9
3 4
8 9
3 6
1 7 1 7
3 4
5
8 9
2 3
4 9
1 2
8 9
1 2
4 8
1 2
3
4 7 9
1 3
4
7 9
5 6
8
1 2
3 4
1 3
4 8
1 2 3
4 7 9
2 4
8 1 2 1 4
2 4
8
1 2
8
1 2
3 4
1 2
4 1 3
4 8
27
2.2.2.3 Hidden single
Sometimes there are blank cells that do, in fact, have only one possible value based on the
situation, but a simple elimination of candidate in that cell’s row, column, and minigrid does not
make it obvious. This kind of possible value is known as a hidden single [33]. Suppose, if we re-
examine the possible values in each cell of Figure 2.6, hidden single can easily be found in cell
[7,2] whose value must be 4 (marked with green colour) as in the seventh minigrid, 4 is not there
as plausible value in other cells. Similarly, for cell [4,9], the hidden single is 6 (as in other cells
of the same minigrid, 6 is not present as probable values). Most of the puzzles ranked as easy,
extremely easy, and medium can simply be solved using these two techniques of singles.
Figure 2.7: An example row of a Sudoku puzzle with a lone ranger 3 in the second cell.
Figure 2.8: A Sudoku puzzle with probable locked candidates in the last row of minigrid 6 (and
here the locked candidates are 3 and 5 in cells [6,7] and [6,8]), in the first column of minigrid 8
(and here the locked candidates are 9 and 3 in cells [8,4] and [9,4]), and so on.
2.2.2.4 Lone ranger
Lone ranger is a term that is used to refer to a number that is one of multiple possible values for
a blank cell that appears only once in a row, or column, or minigrid [15]. To see what this means
5 1 9 8 6 7 6 7 2 3 6
7 4
7 9 3
8 2 5
1 4 6
4 5 1 6
7 4 9 3
8 5 9 2
2 4 5 8
4 6
9
4 6
9 1
3 5
9 5 3 9
3 4
5 3 6 9
4 5 1 8
2 3 6 7
1 4
5 6 4 5
6
7
4 5 3 2
1 4 5
6 9 8
4 6
9
2 8 1 4
9 6 7
3 4
5 3 4
5
1 4
3 4 7 9
1 3 4 8
6 2 5
6 8 1
3 9 5 2
7 4
3 4 2 5
7 4 6
9
3 4
6 9
8 1 3 9 3 9
28
in practice, consider a row of a Sudoku puzzle with all its possibilities for each of the cells as
shown in Figure 2.7 (red digits are either givens or already achieved). In this row, six cells (with
red digits) have already been filled in, leaving three unsolved cells (second, eighth, and ninth)
with their probable values written in them.
Notice that the second cell (in Figure 2.7) is the only cell that contains the possible value 3. Since
none of the remaining cells in this row can possibly contains 3, this cell can now be confirmed
with the number 3. In this case, this 3 is known as a lone ranger.
2.2.2.5 Locked candidate
Sometimes it can be observed that a minigrid where the only possible position for a number is in
one row (or column) within that block, although the position is not fixed for the number. That
number is known as a locked candidate [14]. Since the minigrid must contain the number in a
row (or column) we can eliminate that number not as a probable candidate along the same row
(or column) in other minigrids. Consider the Sudoku puzzle along with its probable assignments
for each blank cell, as shown in Figure 2.8. It can readily be found that the sixth minigrid should
have 3 in the last row. So we can simply eliminate number 3 from cell [6,5] of the fifth minigrid.
Similarly, the eighth minigrid should have 3 in its first column. So, 3 can be eliminated as a
possible candidate from cell [4,4].
Figure 2.9: (a) A partial Sudoku instance with presence of twin 2 and 3 in cells [2,5] and [2,6].
(b) Elimination of probable values (that are 2 and 3) based on the twin from the second row (2 is
deleted from cells [2,1] and [2,3]) and from the same minigrid (2 and 3 are deleted from cells
[1,4] and [1,5]).
(b)
4 7
8
8
4
2 3
8 9
7 2 3 2 3
6 5
1 6 9
2 8 7
2 4
5
2 4
5
9 3 1
5 2 3 7 1 2 4 7 8 9 2 3
4
2 3
8 9 1 3 4
5
3 4
5
3 4
5 5 6
(a)
2 3
8 9
7 2 3 2 3
6 4 5
6 9
2 8 7
2 4
5
2 4
5
9 3 1
5 2 3 7 1 2 4 7 8 9 2 3
4
2 3
8 9 1 3 4
5
3 4
5
3 4
5 5 4 7
8 6
8 1
29
2.2.2.6 Twin
If two same possible values are present for two blank cells in a row (or column) of a Sudoku
puzzle, they are referred to as twin [15]. Consider the partially solved Sudoku puzzle as shown in
Figure 2.9(a). Observe the two cells [2,5] and [2,6]. They both contain the values 2 and 3 (means
either 2 or 3). So, if cell [2,5] takes value 2, then cell [2,6] must contain 3, or the reverse. This
type of situation is an example of twin.
Once a twin is identified, these values can be eliminated by striking through from the same row,
column, and minigrid as shown in Figure 2.9(b), as the values cannot be probable candidates in
other blank cells along the same row (or column) and in the same minigrid.
Figure 2.10: Example rows of Sudoku puzzles with different varieties of triplet. (a) A triplet of
Variety# 1 with same three possible values present in three cells. (b) A triplet of Variety# 2 with
same three possible values present in two cells and the other cell containing any two of them. (c)
A triplet of Variety# 3 with three possible values present in one cell and the two other cells
containing two different subsets of two possible values of the earlier three values.
2.2.2.7 Triplet
If three cells in a row (or column) are marked with a set of same three possible values, they are
referred to as triplet [15]. Like twins, triplets are also useful for eliminating some other possible
values for other blank cells. Triplet has several variations like the following.
Variety# 1: Three cells with same three possible values, as shown in Figure 2.10(a).
(a)
(b)
(c)
8
2
3
4 6 4 5
6 7
4 5 9
1
8
2
3
4 5
6 4 5 7
4 5
6 9
1
8 2 3 4 5
6 4 5
6 7
4 5
6 9 1
30
Variety# 2: Two cells with same three possible values and the other cell containing any two of
the possible values, as shown in Figure 2.10(b).
Variety# 3: One cell with three possible values and the two other cells containing two different
subsets of two possible values of the former three values, as shown in Figure 2.10(c).
Once a triplet is found, we can eliminate all the values of the triplet that are there as possible
candidates in other blank cells along the same row (or column) and in the same minigrid.
2.2.2.8 Quad
Analogous to triplet, a quad consists of a set of four possible values and these values are present
in some form in four blank cells in a row (or column) of the Sudoku instance [14]. That is, if the
values only exist in four (blank) cells in a row (or column), while each cell contains at least two
of the four values, then other values (or numbers except the specified four values) can be
eliminated from each of the assumed cells (forming the quad). Figure 2.11 shows a row of a
Sudoku puzzle where the quad comprising the digits 1, 2, 4, 7 formed by the cells in column
four, six, seven, and eight. So other possible values can straightway be eliminated from these
cells, as shown by striking through the inapplicable digits in the figure.
Figure 2.11: An example row of a Sudoku puzzle with quad comprising digits 1, 2, 4, and 7
present in columns four, six, seven, and eight. To support the digits present in the quad in the
stated cells, other probable values (like 8 and 9 in columns six, seven, and eight) are eliminated
from these cells of the quad, as these values (that are 8 and 9) cannot be probable digits for the
specified cells.
2.2.2.9 X-Wing
The X-wing [33] method can be applied when there are two rows and columns for which a given
value is possible to assign only to two blank (diagonal) cells. If these four cells are only at the
intersections of two orthogonal rows and columns, then all other cells along these rows and
columns must not get assigned to this value. Figure 2.12 shows a Sudoku puzzle where 2 are
present as probable value for cells [3,2], [3,8], [7,2], and [7,8]. It forms an X-wing. So, 2 can be
1 2
4 7 1 2
4 8 1 4
7 8
1 2
7 8
9 6 3 5 8 9 1 8
31
eliminated as probable candidate value for other cells in the same row and column. In this
example, we can eliminate 2 as probable candidate for cells [3,1], [3,3], [3,9], [7,1], [7,3], and
[7,9].
Figure 2.12: A Sudoku puzzle with X-wing comprising digit 2 present at the crossings of rows
three and seven, and columns two and eight.
2.2.2.10 XY-Wing
If a Sudoku puzzle has three cells containing the list of probable candidate values in the
following patterns: (1) all cells have exactly two candidates, (2) they share the same three
candidates in the form of xy, yz, and xz, and (3) one cell (the ‘stem’ of Y with candidates xy)
shares a group with the other two cells (the ‘branches’ of Y with candidates xz and yz). Then we
can say that they form an XY-wing [14]. At that moment any other cell that shares a group with
both ‘branch’ cells can have excluded the ‘z’ candidate that is common to the ‘branch’ cells.
Consider the Sudoku puzzle shown in Figure 2.13, as pointed out, the cells [1,2], [1,7], and [6,7]
contain the list of probable candidate values as {1,8}, {1,5}, and {5,8}, respectively. So the
values of x can be assumed as 5, y as 1, and z as 8. Now, irrespective to cell [1,7] that contains
either the value 1 or 5, the cell either [1,2] or [6,7] will have 8. Therefore, the intersection of
these two cells, i.e., [6,2] cannot have 8, i.e., z as a probable candidate. We can simply eliminate
z from the intersection of the cells containing xz and yz.
5 9
3 5
9
5 6 4
7 2
9
6
8
4 6 8 5
7 1
3 8
4 2
2
6 7
4 7 6
3
6 1
2 3 9
4
7
1 3 4
5 6 8
3 8
1 2
3
7 8
1 2 2 3
7
3 4
5 8
1 3
1 3
3 5
8 9
5 8
3 5
1 7
1 2
3 7 1 5
7 9
2 9
2 3
9
5 8 3 5
6
8 9
1 3 4
5 8
1 3 4
5 6 8
2 4
5 9
1 2
3
5 7
2 3
3 5
8 9
2 3
5 8
7 8
1 4 1 4
2 3
5
6 8
3 5
8 9 1 2
3 9
1 2
5 9
1 3
4
5 8 9
1 3
4
5 8
2 6
7
1 5
8 9
1 2
5 8
1 3 4
5 8 9
2 5
9 1 9 1 5
2 5
9
1 2
9
1 5
8 9
1 5
9 1 2
5 8
4
32
In the case above, the cells xz and yz share a common row or a common column with the cell xy.
It may also be a case that it shares a minigrid as well. Consider the partial Sudoku puzzle
structure shown in Figure 2.14.
Figure 2.13: A Sudoku puzzle with XY-wing, where x = 5, y = 1, and z = 8.
Figure 2.14: A Sudoku puzzle structure with XY-wing, sharing minigrid.
Here the cell containing xz shares a minigrid with cell containing xy, and the cell containing yz
shares a common row with the cell having xy. In this case, all the cells marked yellow colour
cannot contain z as a probable candidate. Because if x is assigned in cell [2,2], then z must be
assigned to cell [3,1], then cells [3,4], [3,5], [3,6], [2,1], and [2,3] cannot have z. Similarly, if y is
assigned to cell [2,2], then also z cannot be assigned to all these cells.
2.2.2.11 XYZ-Wing
An XYZ-wing [14] is similar to XY-wing. In this case, there is a group of three cells, one sharing
a candidate with the other two. However, the first cell in an XYZ-wing has three candidates while
the other two, called the wings, have two. Each of the wings must share one candidate with the
first cell, (that is part of sharing a unit) but of different values. If the second candidates in the
1 8
9
5 6 4
7 2
9
6
8
6
3 8
5
7 1
8
7 2
2
6 2
4 7 6
4 8
9
3
6 1
2 3 9
5 4
7
1 3 4
5 6 8
1 3
8
1 2 2 3
7
1 3 4
5 8
1 3
1 3
3 5
8 9
1 5
1 3
5 1 7
1 2
3 7 1 5
7 9
2 9
5 8 3 5
6
8 9
1 3 4
5 8
1 3 4
5 6 8
2 4
5 9
1 2 3
5 7
2 3
3 5
8 9
3 5
8
8
7 8
1 8 1 8
3 5
6 8
3 5
8 9 1 2
3 9
1 2
5 9
1 3
4
5 8 9
1 3
4
5 8
2 6
7
1 5
8 9
1 2
5 8
1 3 4
5 8 9
2 5
9 1 9 1 5
5 9 1 9 1 5
8 9
1 5
9 1 5
8
1 2
3 8
4
3 9
2 8
9
xy
yz
xz
33
wings are both the same, and are also the same as the extra candidate in the first cell, then if any
fourth cell shares that candidate and a unit with all three, that candidate can be eliminated. Figure
2.15 shows an example of the said technique.
Figure 2.15: A Sudoku puzzle with XYZ-wing occured at fifth and seventh column.
In Figure 2.15, the cell [2,8] with the candidates 1, 3, and 7 formed an XYZ-wing with other two
cells [1,8] and [2,4]. One wing shares 1 with the first cell and the other cell shares 3. Every wing
is having 7 in common. If this type of situation arises, then we can eliminate 7 from all other
cells in common. As shown in the figure, 7 can easily be eliminated from cell [2,7] highlighted
with green colour.
Figure 2.16: A Sudoku puzzle with swordfish occurred at the first, fifth, and seventh column.
7 8
3
4
6 1
5 9
2
9 8
6
3 8
5
7 1
8
7 2
2
6 2
4 7 6
4 8
9
3
6 1
2 3 9
5 4
7
1 3
3 7 2 3
7
3 7
6 8
3 5
8 9
6 8
5
2 5
7
7 9
2 9
3 5
6
8 9
2 3
7
2 3
3 5
8 9
3 5
8 1 8 1 8
3 5
6 8
3 5
8 9 1 2
3 9
1 2
5 9
1 3
4
5 8 9
1 3
4
5 8
2 6
7
1 5
8 9
1 2
5 8
1 3 4
5 8 9
2 5
9 1 9 1 5
5 9 1 9 1 5
8 9
1 5
9 1 5
8
1 3
3 8
4
3 9
2 8
9
2 4 8
4 6
8
5 8 9
1 7
5 1 7
9
8 9
1 5
7 9
3 5
7 8
1 3
7
8 9
3 5
6 8
4
6
1
8 4 3
2 4 5
1 6
4 7
1
3 7 5
8
8
7 5
2
3 8
7 8 5
4 8
9
6
3 5
8 1
9
3
7
1 5
4 5
7
8
2 5
9
7 9
7 9
1 9
2 4
9
2 6
9
2 6
9
5 2 7 4 6
8
9
3
4 6
1
4 8 6 2
3 6
9 4 2 6
7
2 6
2 6 9
3 7 5 1 4 6
9
4 6
9
4 6 5 1 6 4 9
3 7
3 4
6
1 3
9
2 6
9
4 6
9
1 4 2 4
9
2 9
4 9
1
34
2.2.2.12 Swordfish
Swordfish [14] is a generalization of X-wing. If a digit is a candidate for at most three cells in
each of three different columns and the positions of the cells fall into the same three rows, then
this digit cannot be a candidate for any other columns in the three matching rows.
In Figure 2.15, in the first, fifth and seventh column the element 4 appears in the list of probable
candidate values in the same three rows (that are the first, seventh, and eighth row) and 4 is not a
member of any other rows of the columns. So, this is a swordfish pattern. Now the digit, i.e., 4,
can safely be eliminated from other cells in the same rows. In the above figure, 4 can be removed
not as a probable candidate from cell [1,8], and [8,4] as highlighted with green colour.
2.2.2.13 Colouring
If a digit is a candidate for exactly two cells in a row, in a column, or in a minigrid, then the
technique of colouring [33] may be very much dominant to make decisions to eliminate a
probable candidate from a cell or to confirm a digit for a cell. There are several alternatives to
colour a cell starting from single colouring to multi-colouring. Let us state a simple multi-
colouring technique. Consider the Sudoku puzzle as shown in Figure 2.17.
Figure 2.17: A Sudoku puzzle with multi-colouring for cells [2,4], [2,6], [3,2], [3,4], and [5,6].
Let us consider the second minigrid of the puzzle shown in Figure 2.17, digits 4 and 6 are
candidates for exactly two cells [2,4] and [3,4]. Let us allocate yellow colour for these cells.
Then we can also find that in the third row, 4 and 6 also appear two times in cells [3,2] and [3,4],
7
8
3
8
7
6
3 2
3 9
5 4
5 6 8 2
9
5 6
7
1 6 9 2
3 4
6
1
3 4
6
5 4 6
1 5
9
2 9 3
4 9
4
4
2 5
3 4
6 9
1 6
7
1 6 5
3
1 6
7 9
9
8 4
1 9 2 7
3
1
5
2 3
1 8
9 5 6
8 5 9
3 9 6 4
1 7
6 1
7
1 3
4 6
8 2
3 9
8 9 6 8
1 4
6
1 6
8
4 6
2 7
2 7 4 5 1 7 2 4
8 1 8
35
and let us again mark these cells with yellow colour. Again we can find that 1 and 6 appear
exactly two times in the sixth column. Let us assign a separate colour, say green, for these cells.
Now let us follow the path as shown by arrow marks and we can visibly find the intersection
between these yellow and green coloured cells, and it is marked as blue. We can easily conclude
from all these that 6 cannot be present in the blue coloured cell and we can simply eliminate 6 as
a probable candidate from the blue coloured cell. The example shows an elimination technique
using multi-colouring method. It can also be used to confirm the value for a cell as well.
2.2.2.14 Forcing Chains
This method is almost like guessing, but it is a form of guessing that is not too hard for a human
to do. There are various types of forcing chains [33], but the easiest to understand works only
with cells that contain two-candidates.
The idea is this: For each of the two-candidate cells, tentatively set the value of that cell to the
first value and see if that forces any other two-candidate cells to take on a value. If so, find
additional two-candidate cells whose values are forced and so on until there are no more forcing
moves. Then repeat the same operation assuming that the original cell had the other value. If,
after making all possible forced moves with one assumption and with the other, there exists a cell
that is forced to the same value, no matter what, then that must be the value for that cell.
Figure 2.18: A Sudoku puzzle where we can apply the forcing chain method for confirming the
value of cell [8,4].
4
8
5
7
3 6
3
3 5
2
1
6 3
8 7
2 8 7
4 8
9
6
6 7
8 3
8
1 2
3 5
1 2
3 4
9
1 3
4
3 4
9
5
9
7 2 9
4
1
5
2 3
8
5 2 1 9
3 9
5 4
2 3
9
4
2 9
6 7 8
6
2 3
2 3
9
1 9
4 1 2
6 1 5
9
2 3
9
3 4
5 1 3
1 9
1 2
6 9 3 6
1 2
3 5
2 3
1 6
9 1 3
2 7
8 4
7 6 1
9
8 7 5
4
1 2
5 9
36
As an example, consider the Sudoku instance shown in Figure 2.18, and let us begin with cell
[2,3] which can contain either 1 or 3. If cell [2,3] contains 1, then cell [9,3] contains 3, so cell
[8,2] contains 9 and cell [8,4] contains 1. On the other hand, if cell [2,3] contains 3, then cell
[9,3] contains 1, so cell [9,4] contains 9 and cell [8,4] contains 1. In other words, it does not
matter which value we assume that cell [2,3] takes; either assumption leads to the conclusion that
cell [8,4] contains 1, so we can go ahead and assign 1 to cell [8,4].
Figure 2.19: An example of solved Sudoku puzzle used for Tuleja’s theorem.
2.2.2.15 Tuleja’s (or Mr. T’s) Theorem
This theorem is invented by Greg Tuleja (Popularly known as Mr. T.) in the year of 2008 [33].
Although it might not single-handedly tell us where to put the numbers, Tuleja’s Theorem is used
to eliminate the candidates in a particular square. When coupled with other strategies, it could
help one to figure out what number goes in a particular position.
Consider the completed Sudoku puzzle illustrated in Figure 2.19. We can observe the rows of
minigrids 1, 2, and 3. In this case, the numbers 1, 2, and 3 appear in row 1 of the first minigrid,
row 3 of the second, and row 2 of the third. If this situation occurs where the same three numbers
appear in different rows of all three minigrids, then all the other sets of three numbers in rows
will also repeat. So in this case, we have got 645, 456, and 546 as rows in those, and also 987,
798, and 789. The order of the numbers within the minigrids is arbitrary. If we reflect this puzzle
across the main diagonal, it is obvious that the same thing can occur in columns. If a set of three
numbers is repeated in rows of any two minigrids, it is clear that the same set must occur in the
1 2 3
6 4 5
9 8 7
4 5 6
7 9 8
3 1 2
7 8 9
3 2 1
5 4 6
1 7 3
2 9 8
6 5 4
8 5 9
4 1 6
7 3 2
6 7 3
2 8 5
9 4 1
4 1 2
9 3 7
8 6 5
5 6 4
3 7 1
2 9 8
8 2 9
5 6 4
1 3 7
37
third minigrid in the other row. Then however an additional row is filled in, it forces those same
numbers to appear as sets of three in rows in the other minigrids.
Let us discuss with another case studies, where there is not a set of triples in a row of minigrids.
Consider minigrids 4, 5, and 6. In the middle row of minigrids, we can see that the pairs 85, 41,
and 73, are repeating in all three minigrids. A pair of numbers is defined as two numbers that
exist in the same row of the same minigrid, but they do not necessarily have to be adjacent.
When a pair is present, the third number with that pair is a floater, meaning that it is not part of
any pair or triple. The floaters in row number 4, 5, and 6 are 9, 6, and 2, respectively. If we can
show that a certain digit is a floater, we might be able to use that information to figure out which
numbers are pairs in an unsolved puzzle.
Tuleja figured out that there is only one other possible scenario if triples do not appear. There
will be three sets of pairs that will be repeated throughout the three rows of a series of minigrids.
Given any three numbers in one row of minigrid 1, then minigrids 2 and 3 must contain these
same three numbers in a row, or as a pair in one row and as a single in another. Those numbers
can never appear as singles simultaneously in the same minigrid. If one assumes that the set of
three numbers from minigrid 1 is not a triple, there must be pairs somewhere in minigrids 2 and
3 using those numbers. Although this rule has been explained in terms of pairs and triples in a
row, Tuleja’s theorem also applies to columns of numbers.
Figure 2.20: Assignment of numbers in cells in rows belonging to other minigrids of a Sudoku
puzzle following Tuleja’s theorem.
Suppose that the numbers in cells [a,1], [a,2], and [a,3] are filled with 1, 2, and 3, respectively,
and this 1, 2, and 3 altogether is not forming a triple. Assume that 1 and 2 are the pair in the
other two rows in other minigrids; so we can place them in [b,4] and [b,5], and [c,7] and [c,8],
respectively. As 1, 2, and 3 altogether is not forming a triple, 3 cannot be placed in [b,6] or [b,9],
38
and the two numbers that are placed there must be different. For example, if [b,6] and [c,9] both
had the number 4, then 4 would have to go in one of the cells [a,1], [a,2], and [a,3] in row a,
which are already occupied by 1, 2, and 3. Since the numbers in [b,6] and [c,9] are arbitrary, we
can place 4 in [b,6] and 5 in [c,9]. Then we know that the numbers 4 and 5 must also go in the
other two rows that they do not cover yet. Now, it is apparent that whatever numbers are placed
in [b,2] and [b,3] must also go in [a,8] and [a,9], which force the same numbers to be available in
[c,5] and [c,6]. The last pair of numbers will be placed in the remaining empty cells, thus
concluding the proof for Tuleja’s theorem showing that there will be exactly three pairs of
numbers given in any three consecutive blocks in a row or in a column that do not contain
triples. All these have been explained in Figure 2.20 where numbers are assigned to cells in rows
in different minigrids following the Tuleja’s theorem for a given Sudoku instance.
(a) (b)
Figure 2.21: (a) A Sudoku puzzle instance with pair. (b) A Sudoku puzzle instance without pair,
used to illustrate Tuleja’s theorem.
A. Applications of Tuleja’s Theorem
In the examples that follow, in most cases, at least, other standard techniques can be used to fill
in numbers or eliminate candidates. The examples basically illustrate how Tuleja’s theorem
might be used. Generally, it is most useful when a fair number of cells have been filled since
39
some data is required to figure out which numbers form the pairs and which numbers are the
floaters.
We now begin with an example Sudoku puzzle, as illustrated in Figure 2.21(a).
For the puzzle in Figure 2.21(a), we only need minigrids 7, 8, and 9 while using Tuleja’s
theorem. From cells [i,4], [i,5], and [i,6] and cells [g,7], [g,8], and [g,9], we can promptly
observe that 2 and 6 is forming a pair that making 3 and 7 floaters. Now as 7 is a floater, 1 must
form a pair with the number available in [i,1]. Looking at [b,7], we see that there are two choices
for [i,1]; either 8 or 5. However, we may observe that there is already an 8 in row i, so the
number that goes to [i,1] is 5. In this context, for the puzzle in Figure 2.21(b), first look at the
fifth minigrid. The two missing numbers there are 4 and 2, so we can deduce that 4 and 2 is not a
pair even though they appear to be in one row in the sixth minigrid. In cells [e,4], [e,5], and [e,6],
there must be a pair using cell [e,5] because 5 and 7 cannot form a pair (as they are in different
rows in [b,4]). The four possible pairs are 5 and 2, 5 and 4, 7 and 2, and 7 and 4. Pairs 5 and 2,
and 5 and 4 can immediately be eliminated because they are not a pair in [b,6]. This means that
either 2 or 4 could be assigned to cell [d,2]. However, [c,2] shows that [d,2] must contain a 4,
and not a 2.
2.2.3 Soft Computing based Techniques
There are also several soft computing based techniques available to solve the interesting puzzle
like Sudoku. One of the most popular practices is known as the stochastic optimization
technique.
2.2.3.1 Stochastic Optimization Technique
Some work has been done on solving Sudoku using stochastic optimization techniques [13, 16,
34]. The primary motivation behind using these techniques is that difficult puzzles can be solved
as efficiently as simple puzzles. This is due to the fact that the solution space is searched
stochastically until a suitable solution is found [13]. Hence, the puzzle does not have to be
logically solvable or easy for a solution to be reached efficiently.
Furthermore, stochastic optimization techniques are used to find the global optimum of a
problem which contains many local optima [34]. Due to the constrained nature of Sudoku, it is
very likely to find a solution that satisfies some of the constraints but, in general, not all of them;
40
hence, often it finds a local optimum solution. But due to the stochastic nature of these
techniques, the solution space is still searched for finding a global optimum, if one exists, even
though a local optimum has been detected.
Figure 2.22: An instance of a Sudoku Puzzle having 47 solution spaces (or empty cells).
This section of the thesis explores the achievement of four different stochastic optimization
techniques as applied to the Sudoku problem; Cultural Genetic Algorithm, Repulsive Particle
Swarm Optimization, Quantum Simulated Annealing, and Hybrid Genetic Algorithm and
Simulated Annealing.
All four techniques share some common features. Each technique requires an initialization
process, where the solution space is defined, as well as a fitness function, which ensures that the
objectives and the constraints are being adhered to. Let us discuss about the solution space
requirements and about fitness functions in the subsequent sections.
A. Solution Space Representation
The technique is explored with the help of the Sudoku puzzle shown in Figure 2.22. This puzzle
contains 47 empty cells that signify the size of the solution space to be filled in. There are three
ways the solution space can be represented. The first way is to treat each of the 47 cells as a
separate variable, individual or particle, with each individual / particle requiring its own
population. Therefore, the solution space consists of 47 separate population groups. The problem
with this approach is that each individual / particle can only be operated upon separately. This
prevents the possibility of interaction between individuals / particles and also is more
computationally demanding.
1
8
7
9
5 3
2
3 7
8
9
8
1
8
6
9 7
7 3
4 2
8 5
5 4
7
1
1
3 4
8
8 7
6
41
The second approach is to treat a combination of 47 integers ranging between 1 and 9
(corresponding to the empty cells in Figure 2.22) as one individual / particle. Therefore, the
solution space consists of one population with each individual / particle having 47 dimensions or
genes. This approach allows for greater interaction amongst individuals / particles since
algorithmic operations are carried out among possible solutions only. This approach is also
computationally less demanding since there is only one population group.
The third approach is to represent an individual as a puzzle with all its cells filled while ensuring
that one of the constraints mentioned above is always met. Thus, when a population or state is
initialized, it is ensured that each 33 grid in each puzzle contains the numbers 1 through 9
exactly once [13]. Furthermore, any operation carried out on an individual must ensure that this
constraint is not violated. This approach is also computationally less demanding (when compared
to the first approach) since an individual is still represented as a complete puzzle (as opposed to
one cell).
Therefore, only the second and third approaches are considered here; the Cultural Genetic
Algorithm is realized using both of these two approaches, the Repulsive Particle Swarm
Optimization uses only the second approach, the Quantum Simulated Annealing uses the third
approach, and the Hybrid Genetic Algorithm and Simulated Annealing also uses the third
approach.
B. Fitness Function
A number of possibilities exist with regards to implementing a suitable fitness function. From an
arithmetic perspective, the sum of each column, row, and minigrid must equal to 45 and the
product must equal to 362880. One possible fitness function executes these arithmetic operations
to ensure that the constraints are satisfied.
The problem with using arithmetic operation to uphold constraints is that the non-repetition of an
integer in the same column, row, or minigrid is not guaranteed; rather, a row containing nine
entries of 5 still adds up to 45. This could cause the algorithm to converge to a local minimum
and not meet all the constraints. Therefore, a different approach is taken care of.
The fitness function employed here involves determining whether an integer is repeated or is not
present in a particular row, column, or minigrid. A fitness value is assigned to a possible solution
42
based on the number of repeated or non-present integers. The more repeated or non-present
integers there are in a solution’s rows and columns, the higher the fitness value assigned to that
solution.
If the third approach to solution space representation mentioned in A under Section 2.2.3.1 is
used, then only repetitions in rows and columns are considered. If merely the second approach is
used in isolation, then repetition in the minigrids also contributes to the fitness value.
2.2.3.2 Cultural Genetic Algorithm
Cultural Genetic Algorithm (CGA) is an evolutionary optimization technique where individuals
are influenced both genetically as well as culturally [35]. Next a background to both the regular
Genetic Algorithm (GA) as well as CGA has been presented. Then the application of CGA to the
Sudoku problem is discussed and two alternative approaches are considered.
A. Genetic Algorithm (GA) Background
GA optimization is a population based optimization technique inspired by biological genetics
and the Darwinian Theory of Evolution (survival of the fittest and natural selection). A good
introduction to GA is given in [36]. A population (set of numerical data) is chosen for natural
selection. The population comprises a number of potential solutions to a specific problem. Each
possible solution is referred to as an individual. An individual consists of a combination of
genes. The optimal combination of genes could lie dormant amongst the population and could
come from a combination of individuals. An individual with a genetic combination close to the
optimal is described as being fit. A new generation of individuals is created by mating two
individuals from the current population. The fitness function is used to determine how close an
individual is to the optimal solution. The selection function ensures that genetic information from
the fittest individuals is passed down to the next generation, generating a fitter population.
Eventually the population will converge on the optimal solution or get as close to it as possible.
Implementation of a GA is carried out in four steps: Initialization, Selection, Reproduction, and
Termination.
i) Initialization entails encoding the chromosomes into a format suitable for natural selection.
There are several types of encoding modalities, each with their advantages and disadvantages.
Each individual of a population can be represented as a binary number. Since a binary number
43
consists of ones and zeros (base 2), more digits are required to define an individual than if a
decimal number is used (base 10). This lends itself to greater diversity in chromosome
representation and hence greater variance in subsequent generations [36]. The problem with
binary encoding is that most populations are not naturally represented in binary form due to the
length of binary numbers; they are computationally expensive.
Another form of encoding is floating point encoding. Each individual is represented as a floating
point number or a combination of floating point numbers. Floating point encoding is far more
efficient than binary encoding [36]. Value encoding is similar but allows for characters and
commands to represent an individual.
ii) Selection of individuals for mating involves using a fitness function. A fitness function is used
to determine how close an individual is to the optimal solution. The fitness function is the only
part of GA which has the knowledge of the problem [13]. The fitness function for the Sudoku
problem is discussed in B under Section 2.2.3.1.
After defining the fitness of each individual, it is necessary to select individuals for mating.
There are various methods used. Two methods are discussed here. The Roulette technique
involves first summing the fitnesses of all the individuals of a population and then selecting a
random number between zero and the summed result. The fitnesses are then summed again until
the random number is reached or just exceeded. The last individual to be summed is selected.
Another selection technique is the tournament method. The tournament method involves
selecting a random number of individuals from the population and the fittest individual is
selected. The larger the number of individuals selected, the better the chance of selecting the
fittest individual.
Selection ensures that the fittest individuals are more likely to be chosen for mating but at times
also allows for less fit individuals to be chosen. A selection function which only mates the fittest
individuals is termed elitist and may result in the algorithm converging to a local minimum.
iii) Reproduction comprises two different genetic operations: crossover and mutation.
Crossover is the process by which two individuals share their genes, giving rise to a new
individual. Crossover ensures that genes of fit individuals are mixed in an attempt to create a
44
fitter new generation. There are various types of crossover depending on the encoding type, two
of which are mentioned here: simple and arithmetic crossover.
Simple crossover is carried out on a binary encoded population. This involves choosing a
particular point and all genes up until that point will come from the one parent while the rest
comes from the other. For example, one parent has the following binary configuration:
11010100. The other has the following: 00101111. If the fifth point is chosen then the resultant
child will have the following configuration: 11010111. It is also possible to choose multiple
points, which signify where crossover occurs.
In arithmetic crossover, a new generation is created from adding a percentage of one individual
to another. For example an individual has the value 9.3 and another 10.7. If we select 30% from
the one and 70% from the other, then the child will have the value 10.28.
Over the course of reproduction, a child’s chromosome will go through mutation. Mutation is
when the gene sequence of a chromosome is altered slightly, either by changing a gene or by
changing the sequence. This is done to ensure that the populations converge to a global minimum
as opposed to a local minimum.
iv) Termination determines the criteria for the algorithm to stop. This can be once the optimal
solution is reached but could be computationally expensive. Otherwise, the GA can terminate
once a certain number of generations have been reached, if the optimal solution has not been
reached or once no better solution can be achieved.
B. Cultural Genetic Algorithm (CGA) Background
Cultural Genetic Algorithm (CGA) is a variant of GA that includes a belief space [17]. There are
various categories of belief space [35]:
Normative belief, where there is a particular range of values to which an individual is
bound.
Domain specific belief, where the information about the domain of the problem is
available.
Temporal belief, where information about important events in search space is available,
and
Spatial belief, where the topographical information of the search space is available.
45
In addition to the belief space, an influence function is also required in order to implement a
CGA [35]. An influence function forms the interface between the population and the belief
space. It alters individuals in the population to conform to the belief space.
CGA is a suitable candidate for solving Sudoku since it prevents the algorithm from producing
an individual which violates the belief space. This reduces the number of possible individuals the
GA needs to generate until the optimum is found. Two different approaches are considered,
depending on the way the solution space is represented.
C. CGA Applied to the Sudoku Problem: First Approach
This approach uses the second solution space representation scheme mentioned in A of Section
2.2.3.1, where each individual consists of 47 genes, with each gene corresponding to a non-fixed
cell in the puzzle. A population of 50 individuals is randomly initialized, ensuring that each
individual contains genes which conform to the belief space. The belief space consists of three
main categories:
Normative belief, where each individual can only contain genes ranging between 1 and
9.
Domain specific belief, where each individual can only contain genes which are integers,
and
Spatial belief, where each individual can only contain genes that do not result in the
repetition of a fixed cell values within the same row, column, or minigrid, as defined in
Figure 2.22.
The third belief criterion contains knowledge of the topography of the search space; in other
words, the fixed cell values.
An influence function is used to ensure that the belief space is adhered to. The influence function
ensures that only random numbers between 1 and 9 are used to initialize the puzzle. It also
implements a rounding function to ensure that the values are all integers. In addition, it performs
a check to make sure that the random numbers generated are not repetitions of one of the fixed
numbers in the same column, row, and minigrid.
Once the problem is initialized, the fitness of each individual in the population is determined
using the fitness function described in B of Section 2.2.3.1. A sub-population of 25 individuals is
46
selected for reproduction. A tournament selection is carried on the individuals of the sub-
population to determine which individuals mate. Tournament selection is carried out since it is
efficient to code, works on parallel architectures, and allows the selection pressure to be easily
adjusted [36].
During reproduction both crossover as well as mutation is carried out. Single point, simple
crossover is implemented; a number between 1 and 47 is randomly generated from a Gaussian
distribution [36]. This number corresponds to the point of crossover. All genes before this point
come from the one parent while the other parent contributes the rest. A new individual, whose
genetic composition (or structure) is a combination of both parents’, is thus reproduced.
The new individual also undergoes mutation, and three random genes are selected for mutation.
These genes are allocated new random values, which still conform to the belief space. The new
individuals replace the individuals in the population which have the lowest fitness values. The
CGA is run until an individual with a fitness of zero is found, indicating that the solution to the
puzzle has been reached.
D. CGA Applied to the Sudoku Problem: Second Approach
This approach uses the third solution space representation scheme mentioned in A Section
2.2.3.1. Each individual is represented as a completed puzzle where the third constraint
mentioned in Section 2.2.3.1 is met: Each 33 grid in each puzzle contains the numbers 1 to 9
exactly once. Each 33 grid is thus considered as a gene.
Populations of 100 such individuals are initialized and their finesses are also calculated. The best
individual and fitness in the population, at each generation, are tracked. The fitness function,
described in B of section 2.2.3.1 is used, where only repetitions in the rows and columns
contribute to an increase in the fitness value (by definition, there are no repeats in the minigrids).
The process only implements a mutation. The mutation function is implemented on each
individual separately and works as follows: A 33 grid is randomly selected. Two unfixed cells
in the grid are then randomly selected and switched. During reproduction, the mutation function
is implemented on each individual in the population.
The number of mutations implemented on an individual depends on how far the CGA has
progressed (how fit the fittest individual in the population is). The number of mutations
47
implemented is equal to the fitness of the fittest individual divided by 2, and then rounded up.
Therefore if the fittest individual is 25, then the number of mutations implemented on each
individual in the population during the next generation is 13.
The belief space defined in this approach differs from the previous approach in that it applies to
each 33 minigrid as opposed to each cell. The belief space consists of four categories:
Normative belief, where each 33 minigrid contains entries ranging between 1 and 9.
Domain specific belief, where each 33 minigrid can only contain entries that are
integers.
Spatial belief, where each 33 minigrid must contain the integers 1 to 9 exactly once.
Temporal belief, where when a mutation is applied to a minigrid, it cannot alter the
value of a fixed cell.
During the initialization process it is indemnified that the first three belief criteria are met.
During mutation, it is ensured that the fourth criterion is met. In this approach, there is an
additional form of influence function. As mentioned, the best fitness influences the number of
mutations that at most can take place. Here, knowledge of the solution (how close the puzzle is
from being solved) has a direct impact on how the algorithm is being implemented. This is also a
form of culture [35]. The algorithm terminates when the best individual has a fitness of zero, i.e.,
the solution has been found.
2.2.3.3 Repulsive Particle Swarm Optimization (RPSO)
RPSO is a variant of classical Particle Swarm Optimization (PSO), streamlined for complex
search spaces with many local minima [37]. A background to both classical PSO as well as
RPSO is presented. The application of RPSO to the Sudoku problem is then discussed.
A. Particle Swarm Optimization (PSO) Background
Particle Swarm Optimization is a population based optimization technique, which attempts to
simulate the way birds flock towards food [37]. A group of particles carry out a stochastic
search, iteratively altering each particle’s velocity and position until the optimal position is
reached [37]. The positions of the particles are randomly initialized. A particle’s position is
evaluated based on a fitness function. Like GA, the fitness function is the only part of the
algorithm which has knowledge of the problem.
48
In classical PSO, two values are used in determining a particle’s next velocity and position: The
particle’s personal best position and the best position achieved by any particle in the group over
all iterations. A particle’s velocity and position is altered as follows [37]:
vi+1 = wvi + wc1r1(xbest xi) + wc2r2(gbest xi) … … … … … … … … … … … … … … … ..(1)
xi+1 = xi + vi+1 … … … … … … … … … … … … … … … … … … … … … … … … … ...(2)
where, xi is the current position of the particle, xi+1 is the next position of the particle, vi is the
current velocity of the particle, vi+1 is the next velocity of the particle, w is an inertial constant
(ranging between 0.01 and 0.7), c1 and c2 are constants that indicate to what extent the particle
moves towards the best positions, r1 and r2 are random numbers (ranging between 0 and 1), xbest
is the best position found by the particle, and gbest is the best position found by the group.
Equations (1) and (2) are iteratively applied until the algorithm is terminated. The algorithm is
terminated once the global optimal point has been found or after a certain number of iterations
have passed. For multi-dimensional individuals, the velocity and position of each dimension is
calculated separately. This is analogous to the orthogonality of a particles position and velocity
in three dimensional spaces.
B. Repulsive Particle Swarm Optimization (RPSO) Background
RPSO is a variant of PSO, which is particularly effective in finding the global optimum point in
very complex search spaces [38]. This is done by causing the particles to repel one another,
preventing the particles from gravitating towards local optimum points. Due to its repulsive
nature, RPSO takes longer to find the optimal point in simpler search spaces, when compared to
classical PSO. In RPSO, a particle’s velocity is altered as follows [35]:
vi+1 = wvi + wc1r1(xbest xi) + wc2r2 (xbr xi) + wc3r3z… … … … … … … … … … … … … (3)
where, xi is the current position of the particle, vi is the current velocity of the particle, vi+1 is the
next velocity of the particle, w is an inertial constant (ranging between 0.01and 0.7), c1, c2, and c3
are constants (c2 should be negative and indicates a particle’s repulsion away from another
randomly chosen particle’s best position), r1, r2, and r3 are random numbers (ranging between 0
and 1), xbest is the best position found by the particle, xbr is the best position found by another
randomly chosen particle, and z is the velocity of another randomly chosen particle.
49
Equation (2) is also used to alter the particles position. The algorithm is terminated once the
global optimal point has been found or after a certain number of iterations have passed.
C. RPSO Applied to the Sudoku Problem
RPSO is a suitable candidate for solving Sudoku due to its efficiency in finding the global
optimum. As mentioned above, due to the constraint nature of the Sudoku problem, the
avoidance of local minima is critical. RPSO uses the second solution space representation
scheme mentioned in A of Section 2.2.3.1. Each particle’s position consists of 47 dimensions,
with each dimension corresponding to a non-fixed cell in the puzzle. Hence, as with the first
CGA approach, a population of 50 individuals is chosen. The population is randomly initialized
and the initial velocities are set to zero. It is ensured that all particle positions only contain
integers from 1 to 9.
The personal best positions are initialized to the current values. A random best position from the
population (xbr) (for the same dimension) is selected to be implemented in Equation (3). The
values for c1, c2, and c3 in Equation (3) are 2, 2, and 2, respectively. c2 is made negative in order
to implement the repulsion property between particles. w is set to 0.1.
The first set of velocities is generated using Equation (3), taking vi and z to be zero. The
positions of the particles are then updated, ensuring that the positions remain integers ranging
between 1 and 9. Each particle has 47 dimensions.
Each dimension has a corresponding position value and velocity value. When the velocity and
position of a particle is updated, each dimension’s velocity and position is updated separately.
Consecutive iterations update the particle velocities and positions using Equations (3) and (2),
where z is a different particle’s velocity (for the same dimension), randomly chosen. Even
though the global best position is not used to update the velocity, it is tracked in order to check
when the solution is found.
2.2.3.4 Quantum Simulated Annealing (QSA)
Quantum Simulated Annealing (QSA) is a powerful optimization tool which incorporates
quantum tunneling into classical Simulated Annealing [39]. A background to both classical
Simulated Annealing (SA) as well as QSA is presented. The application of QSA to the Sudoku
problem is then discussed.
50
A. Simulated Annealing (SA) Background
SA is an optimization technique, inspired by the annealing process used to strengthen glass or
crystals through which the materials get their own desired shape [40, 41]. A crystal or glass is
heated until it liquefies in a very high temperature and then it is cooled slowly, allowing for the
molecules to settle into lower possible energy states.
Unlike GA and PSO, SA is not population based but rather alters and tracks the state of an
individual, continuously evaluating its energy by using an energy function [41]. SA finds the
optimal point by running a series of Markov Chains under different thermodynamic conditions
[41]. A neighbouring state is determined by randomly changing the current state of the individual
by implementing a neighbourhood function. If a state with a lower energy is found then the
individual moves to that state. Otherwise, if the neighbouring state has a higher energy then the
individual will move to that state only if an acceptance probability condition is met. If it is not
met, then the individual remains at the current state.
The acceptance probability is a function of the difference in energies between the current and
neighbouring states as well as the temperature [41]. The temperature is initially made high,
making the individual more susceptible to move into the higher energy state. This allows the
individual to explore a greater portion of the search space, preventing it from being trapped in a
local optimum. As the algorithm progresses the temperature is reduced, in accordance with a
cooling schedule, causing the individual to converge towards the state with the lowest energy
and hence the optimal point is reached.
A typical SA algorithm works as follows [41]:
• Initialize an individual’s state and energy.
• Initialize temperature.
• Loop until temperature is at minimum.
Loop until a maximum number of iterations has been reached.
Determine neighbouring state by implementing the neighbourhood function.
Determine the energy of the current and neighbouring state.
If the neighbouring state has a lower energy than the current, then change the
current state to the neighbouring state.
51
Else, if the acceptance probability is fulfilled then move to the neighbouring state.
Else stick to the current state.
Keep track of state with the lowest energy.
End inner-loop.
Alter temperature in accordance with the cooling schedule.
• End outer-loop.
There are various types of cooling schedules [40]. A linear cooling schedule simply subtracts a
constant from the previous temperature. A geometric cooling schedule multiplies the previous
temperature by a fraction.
B. Quantum Simulated Annealing (QSA) Background
QSA is based on quantum tunneling, where an individual can move from one state to another by
tunneling through high energy areas, in search of lower energy areas [40]. This is controlled by
the tunneling field strength (analogous to the temperature in SA). The major difference between
QSA and SA is that in SA the temperature determines the probability of moving from one state
to the next, while the neighbourhood remains constant. In QSA, the tunneling field strength
determines the neighbourhood radius or the distance between the current state and the
neighbouring state [40].
C. QSA Applied to the Sudoku Problem
QSA is used in discrete search spaces which contain many local optima [40], making it ideal for
Sudoku. Since QSA is not a population based algorithm, the third solution space representation
scheme mentioned in A of Section 2.2.3.1 is used. The starting state of the annealing process is
initialized by randomly filling the puzzle, but ensuring that each 33 minigrid contains the
integers 1 through 9 exactly once. The fitness function is described in B of Section 2.2.3.1,
where only repetitions in the rows and columns contribute to an increase in the fitness value (by
definition, there are no repeats in the minigrids as well).
The neighbourhood function is identical to the mutation function described in the second CGA
approach, where a minigrid is randomly selected. Then two unfixed cells in the minigrid are also
selected randomly and switched.
52
The initial tunneling strength should be set high enough to ensure that 80% of states are accepted
during the initial Markov Chain [40]. The tunneling strength is therefore initialized by taking the
standard deviation of 100 randomly initialized states and setting it to that value. 20 iterations of
tunneling strength reduction are implemented (the outer-loop of the algorithm has 20 iterations).
During each iteration, the tunneling strength is reduced by multiplying it with 0.8. This makes
certain that the tunneling strength decreases fast enough to ensure a solution after 20 iterations
but not too fast so as to make the acceptance probability too greedy.
The Markov Chain is set to run for 2209 iterations. This is due to the fact that in general, the size
of the Markov Chain should represent the size of the search space [41], which in this case is the
47 unfilled cells of the puzzle. Therefore, the Markov Chain should be 472
= 2209 iterations. The
probability function is defined as follows [40]:
… … … … … … … … … … … … … … … … … … … … … .. (4)
Where, is the energy of current state, is the energy of neighbouring state, and is the
tunneling strength.
As mentioned above, QSA is different from classical SA in that the tunneling strength also
determines the neighbourhood radius. In this instance, the tunneling strength defines how many
neighbourhood operations are applied to the current state, to derive the neighbouring state.
Initially, when the tunneling strength is high, the current state will undergo many random cell
swaps (within various randomly chosen minigrids). As the tunneling strength decreases, less
random swaps will be undertaken until only one random swap is applied during the final Markov
Chain.
2.2.3.5 Hybrid Genetic Algorithm and Simulated Annealing (HGASA)
A hybrid of Genetic Algorithm and Simulated Annealing (HGASA) [41] combines the parallel
search capability of GA with the flexibility of SA. GA is a population based search, which
allows for the search space to be explored by multiple individuals. SA allows for the possibility
of finding a better optimal point, even though a local minimum has been located. Both of these
aspects are essential in finding the solution for a Sudoku puzzle. A background to HGASA is
presented and its application to the Sudoku problem is then discussed.
53
A. Hybrid Genetic Algorithm and Simulated Annealing Background
At the beginning of a search, it is necessary to explore as much of the search space as possible. A
population based search is ideal for this. Hence, initially a GA is implemented until a low fitness
is achieved. Once the GA cannot find any better individuals after a certain number of
generations, the best individual in the population is chosen to undergo a series of random walks
until the optimal solution is found.
A number of factors need to be defined when implementing an HGASA. It is necessary to
determine how long the GA is required to run (means how many generations). Once the number
of generations is determined, a modified SA algorithm is run on the fittest individual until the
solution is found.
Other aspects to consider are all the same parameters discussed above for the GA and SA. The
GA population representation and size; the reproduction function and the neighbourhood
function (the GA’s reproduction function should be similar to or incorporate the SA’s
neighbourhood function) as well as the fitness function.
Due to the fact that a hybrid model is being used, it might seem fitting for certain aspects of the
GA and SA algorithms, mentioned above, to be omitted. For example, the reproduction function
might only implement a mutation and leave out crossover. If the GA produces an individual with
fitness close to the optimal, then the temperature schedule could be omitted and only a single
Markov Chain is implemented.
B. HGASA Applied to the Sudoku Problem
A population of ten puzzles is initialized. The third solution representation scheme mentioned in
Section 2.2.3.1 is used; each 33 minigrid in the puzzle contains the integers 1 through 9 exactly
once. The reproduction function is the same as mentioned above for the second CGA approach;
only mutation is implemented which randomly selects a minigrid and randomly swaps two
unfixed cells in the minigrid. The number of mutations also corresponds to the best fitness, as per
the CGA discussed in Section 2.2.3.2. The best fitness and individual are tracked until a fitness
of 2 is found (experimentally it was established that the GA found a fitness of 2 very quickly).
Once an individual with a fitness of 2 is found, the individual enters into the SA cycle. Since the
GA managed to find an individual with a low energy, the individual can enter into the SA
54
process fairly late; hence no temperature schedule is implemented. Therefore, instead of
implementing a Markov Chain, a simple moderated Monte Carlo Chain is used. The Monte Carlo
Chain accepts states with energies which are lower or equal to the current state’s energy and runs
until a state with the energy of zero is reached (that means the solution is found).
The SA and GA cycles both share the same fitness function and neighbourhood function used in
the SA is the same as the mutation function used during the GA (with only one mutation applied
per iteration).
2.2.3.6 Bee Colony Optimization (BCO)
BCO is another nature inspired optimization algorithm [42]. It mimics the foraging behaviour of
a bee colony. As there is more than one bee in a colony, it is a swarm intelligence approach
where information among the participating bees is exchanged. Therefore, it is a parallel search
process like Particle Swarm Optimization instead of a single one such as Simulated or Quantum
Simulated Annealing. Each bee represents a potential solution, a minigrid, for the Sudoku
problem.
The natural inspiration comes from a certain class of bees, called honey bees. Colonies of such
bees sent out scout bees to search, e.g., food sources, i.e., fields of flowers. As many bees are
sent out it can be seen as parallel search in a natural search space. After their search, the scout
bees return to the hive. There they communicate their findings among other bees. This is done by
the so-called waggle dance on the ‘dancefloor’. The other bees then know the approximate
direction, distance, and quality of sites that contain nectar and pollen. So other bees get recruited
which leads to a better exploitation of the found sites. Usually, higher quality patches also attract
a higher number of bees. This swarm communication is extremely important as it helps the
colony to survive.
At first, as one can see in Figure 2.23, the population is initialized with randomly filled
minigrids. Then the loop starts. There the fitness of each bee is determined first and therefore it
is checked, if the termination condition is fulfilled. If not, then the bees with the highest fitness
value are identified. By doing so, also the best sites are known as the fitness of a bee is only
dependent on the place it searches for food. For this, patches a certain number of scout bees, a
percentage of the total population, are assigned to. The number depends on the fitness value of
the site and for sites with higher fitness usually more bees are selected. These bees all get the
55
same minigrid which is subsequently slightly mutated. This resembles local search as the
surroundings of the patches are explored. For a number of elite sites, a percentage of the total
number of sites, this procedure is repeated to intensify local search. These are then searched by
an additional number of corresponding elite bees.
The rest of the population, non-elite and non-scout, are selected for random search to explore
other parts of the search space. At the end of each iteration, the fitness values of the bees are
calculated and the best bee from each site is selected for the next generation. The rest of the
population is filled with randomly generated bees. This procedure combines local search with
random exploring of the whole search space.
Figure 2.23: Flowchart of an algorithm based on Bee colony.
Initialise population
with random solutions
Evaluate fitness of the
population
Termination condition
fulfilled?
Select sites for
neighbourhood search
Recruit bees for selected sites
and evaluate their fitness
Select best bee from
each patch
Assign remaining bees
for random search
No
Yes Terminate
56
2.2.3.7 Artificial Immune System
Artificial Immune System (AIS) is unlike all other algorithm implemented not just a single
algorithm, but as the name implies, a whole system [39]. As the immune system comprises many
cells, the approach is in the realm of swarm intelligence. It is not only useful for optimization,
but also for applications such as clustering, data visualization, and control. Therefore, a right set
of procedures has to be selected.
Figure 2.24: Flowchart of an algorithm based on Artificial Immune System (AIS).
An algorithm which is often used for optimization is the Clonal Selection Algorithm. It is
inspired by the response of the immune system to antigens and the clonal selection theory. When
an antigen enters the body the immune system reacts and tries to eliminate the intruder.
Therefore, lymphocytes, the killer cells, bind themselves to the antigen. If the lymphocytes are
useful against the intruder, they get cloned, which increases the effect of the immune reaction.
This ensures that only useful killer cells are produced in large numbers and therefore, the
Initialize population
with random solutions
Evaluate fitness of the
population
Termination
condition fulfilled?
No
Do cloning and mutate
clones
Update lifetime
Build new generation
Terminate Yes
57
lymphocytes affinity to the antigen increases more and more. High affinity corresponds to a high
fitness of the killer cell and the global optimum is a fully developed lymphocyte, which is able to
destroy the intruder. A maximum lifetime is used to eliminate solutions that have no increase in
fitness for a certain number of generations.
In algorithmic form, see Figure 2.24, this means that at first a population with a certain minimum
size is randomly initialized. Then, by calculation of the fitness values, the best ‘cells’ are
identified. Those are then cloned. The number of clones can be calculated in various ways. The
simple formula used here takes the ratio of the maximum fitness value achievable, 216, and the
fitness value of the cell multiplied by a certain number of allowed clones. The more clones are
allowed the more the search is concentrated on minigrids with the highest fitness. This is due to
the fact, under the assumption that cloning proceeds from the best to the worst individual, that
not all cells will have the possibility to clone themselves as the maximum population size will be
reached beforehand. Resulting clones are subsequently mutated for local search. New clones start
with full lifetime. In each generation it is checked if the cells have increased their fitness. If not,
the lifetimes are incremented. If the maximum lifetime is reached the cells are deleted as long as
the population size does not fall under the minimum. Those who are selected to be elitists have
their lifetime counter reset. The new population then consists out of the elitists and the surviving
cells.
2.3 Enumerating Sudoku Grids
The number of different 99 Sudoku puzzles that has been calculated by Felgenhauer and Jarvis
is obtained as 6,670,903,752,021,072,936,960 [43]. The key to count the number of possible
puzzles is to first calculate all possible positions for digits in a row of minigrids. Say we are
considering the top row of minigrids (that are minigrids 1, 2, and 3). Starting from the top-left
cell, we can see that there are 9! ways to place the numbers in a row of nine cells. Now let us
assume minigrid 2. Here there are 6C3 (or 20) number of ways to pick three digits for the top row
of minigrid 2. Now, using Tuleja’s theorem [33], we need to split the possibilities for minigrid 2
and minigrid 3 into two cases; the first case that contains only triples as shown in Figure 2.25
and the second case that only has pairs as shown in Figure 2.26.
The first case has two possibilities for triples: 789 and 456 (as 123 have assumed to be there in the
top row of minigrid 1). After the first triple (i.e., 789) is placed in the top row of minigrid 2, the
58
positions for the digits in the other triple are determined. However, the digits in each row of each
minigrid can be permuted in 3! Ways; so the total number of variations for the first case is 2×(3!)6.
Figure 2.25: A partial Sudoku puzzle that consists of triples as a part to study the first case.
Figure 2.26: A partial Sudoku puzzle that contains pairs as a part to study the second case.
There are 18 possibilities for the second case because we subtract the two possibilities in the first
case from the total number of possibilities. First, after placing the digits in the top row of minigrid 2
and then putting certain digits into rows where they are forced to go (but not in order); let a, b, and c
represent the unknown digits that should go in the remaining three cells of minigrid 2 and minigrid 3.
After a value for a is picked (out of three possible values) the values for b and c are arbitrary; so the
total number of variations for the second case is 18×3×(3!)6.
Then adding the number of variations (starting from the first case), we can observe that the total
number of permutations for the first three rows is (2×(3!)6 + 18×3×(3!)
6) × 9! = 2612736 × 9!.
Incidentally, using a computer to compute the number of possible Sudoku puzzles from these
configurations would be impractical. Instead, we need to reduce the number of possibilities with
other methods of reduction.
One of the key ways to minimize the number of cases is to apply lexicographical reduction [43]. This
means that starting from the left column of minigrid 2 and minigrid 3, we have to place the digits in
increasing order. After ordering the digits lexicographically, we can permute the columns in minigrid
2 and minigrid 3, each requires 3! times and we can permute these minigrids 2! times such that the
top-left cell of minigrid 2 contains a digit less than that of the top-left cell of minigrid 3. Using this
reduction method, we can decrease the number of possibilities for the top row of minigrids from
2,612,736 to 2,612,736/72 or 36,288 only. The same method can be applied to minigrid pair 4 and 7.
4 6 8
7 9 a
5 b c
5 7 9
8 b c
4 6 a
1 2 3
4 5 6
7 8 9
3 7 8 5 4 2 1 6 9
3
2
1
7 8 9
1 2 3
4 5 6
4 5 6
7 8 9
1 2 3
1 2 3
4 5 6
7 8 9
3 7 8 5 4 2 1 6 9
c
b
a
59
To further reduce the number 36,288, we should consider the number of permutations of the top three
minigrids (i.e., 3!) and the number of permutations of the columns in each minigrid (i.e., also 3!).
These give (3!)×4 permutations, which reduces the total number of possibilities from 36,288 to 2051
only. The three rows in the top three minigrids can also be permuted six times that even decrease the
possibilities to 416. Now it is quite impressive to test using these 416 possibilities only, considering
that there were initially 2,612,736 possibilities. However, there is still one more method that we can
take advantage of to further decrease the number of cases. Consider the partial Sudoku puzzle shown
in Figure 2.27.
Figure 2.27: (a) A partial Sudoku puzzle consisting of pairs comprising digits 6 and 9. (b) The
same partial Sudoku puzzle after mutual exchange of 6 and 9 in each pair.
In Figure 2.27(a), we observe that there are pairs of 6 and 9 placed in adjacent cells in three
neighbouring minigrids in a row. After swapping the positions of all 6 and 9 in each pair we obtain
the partial Sudoku puzzle as shown in Figure 2.27(b). It may seem that changing the digits in
columns 7 and 8 might alter the rest of the puzzle, but it is important to remember that every single 6
and 9 in the entire puzzle, even the ones that are not shown here, will be changed. Actually, the
puzzle does not change because we are only renaming all of the 6’s and 9’s. By combining all of
these duplications, we finally end up with 44 distinct classes [29].
The total number of cases that eventually is calculated by a computer counts the number of Sudoku
puzzles for each case and then adds them together. Because all the cases are derived such that
minigrid 1 is in the form of case 1 and case 2, as stated above, and that minigrids 2, 3, 4, and 7 in the
same row and same column of minigrid 1 are lexicographically reduced; we must multiply this sum
by 9!×722. The final answer after the computer calculations obtained is very close to 6.671×10
21.
2.4 Summary
In this chapter of the thesis, we have discussed different techniques for solving Sudoku puzzle.
The most fundamental method for solving Sudoku puzzle is backtracking and different
elimination based techniques used for solving a given Sudoku puzzle. The basic backtracking
4 5 8
1 7 6
2 3 9
9 6 7
2 3 8
1 4 5
1 2 3
4 5 9
7 8 6
3 7 8 5 4 2 1 6 9
c
b
a
(a) (b)
4 5 8
1 7 9
2 3 6
6 9 7
2 3 8
1 4 5
1 2 3
4 5 6
7 8 9
3 7 8 5 4 2 1 6 9
c
b
a
60
method first assigns some random variable to a blank cell, and then it goes on checking with other
cells if a value previously assigned to that cell hits a conflict with other cell. If it hits with a
conflict, then it backtracks to the previous cell and assign the next value. In this way, the method
may sometimes backtrack several times before advancing. But, it is guaranteed to find a solution
if there is one, simply because it eventually tries every possible number in every possible location.
This method is very much time consuming.
Instead of assigning a value to a cell based on guess, in the elimination based approach a list of
probable candidate values are maintained for each of the blank cells. Then the different patterns
are searched using the different elimination based techniques such as Naked single, Hidden single,
Locked candidate, Lone ranger, Twin, Triplet, Quad, X-Wing, XY-Wing, Swordfish as described in
this chapter. Some of these techniques are able to directly assign some values to a cell. Some of
them can only eliminate values from other cells present in the same row, column, or minigrid. For
example using Naked single, Hidden single, or Colouring, we can directly assign some value for a
particular cell. Whereas using the other methods, we can only eliminate the candidate values from
other cells, as described earlier.
But these elimination based methods are also very much time consuming as each of them has to
search for a particular pattern and also several backtracking is needed for solving a puzzle. It may
not also be necessary to apply all the methods for solving a Sudoku puzzle. Generally, up to
medium difficulty level, puzzles are solvable using only Naked single, Hidden single, Locked
candidate, Lone ranger, Twin, Triplet, and Quad based techniques. Rests are advanced
techniques, which are essentially used for difficult and evil puzzles.
The other techniques include several optimization techniques. We have found that Particle Swan
Optimization (PSO), Quantum Simulated Annealing (QSA), Cultural Genetic Algorithm (CGA),
Hybrid Genetic Algorithm and Simulated Annealing (HGASA), Bee Colony Optimization
(BCO), Artificial Immune System (AIS) can be used to solve this puzzle game. But each of these
techniques is very much time consuming.
In the last section of this chapter, we have discussed about the total number of different Sudoku
instances possible for puzzles of size 99 each. It has been found that the total number of Sudoku
instances is 6,670,903,752,021,072,936,960 6.671×1021
, which is an exceptionally large
number.