1 Introduction

In the field of Computer Science, under Artificial Intelligence, Evolutionary Computing (EC) is a subfield of Soft Computing. EC has a family of algorithms called Evolutionary Algorithms (EAs) to resolve global optimization problems. Technically, EAs belong to the families of population-based, trial and error metaheuristic problem-solvers involving stochastic computation. EAs use biological evolutions such as reproduction, recombination, mutation, and selection. Natural selection (survival of the fittest) is espoused by individuals that consider fitness score provided by the fitness functions. The best individuals are selected for the iterative evolution process until a final solution is achieved with an appropriate fitness score.

Genetic Algorithm (GA), a component of EA, is used to generate high-quality accurate solutions to optimization and search problems [1, 2]. Parametric values, for the Genetic algorithm, -several initial solutions, initial population, the maximum number of generations, mutation type, and crossover-type - can be initialized or provided by the user. GA encodes a population of solutions, embracing the natural evolution process, to arrive at an optimal solution in the population, with the help of the fitness function. The GA routine is executed until either the appropriate solution is achieved, or limited by the permissible maximum number of generations.

This paper aims at testing the suitability of applying GA to solve an NP-complete problem. The Sudoku problem was selected as a test case to solve Sudoku using GA.

A Sudoku puzzle is defined as a logic-based, number-placement puzzle. It can be of different sizes but the Sudoku used in this paper s 9 × 9 square, in which it has 9 rows, 9 columns, and 9 3 × 3 grids. Initially, some cells of a Sudoku puzzle are provided with numerical digits in the range of 1 to 9. The puzzle is said to be solved, when each of the rows, columns, and grids, contain only single instances of numbers in the range of 1 to 9, such that no digit is repeated within the same row or column or grid. For a traditional Sudoku, the sum of digits in each row, column or grid should be equal to 45.

The remaining part of the paper is organized as follows: Sect. 2 discusses related works, while Sect. 3 presents the design of the experiment. Section 4 reports on the results and the observations, followed by closing remarks in Sect. 5.

2 Related Works

An insight into the assessment of EA in tackling Sudoku was presented in [3], which suggested that random mutation may have a significant impact on the performance of EAs. Coming to grips with Sudoku, using GA, by considering each 3 × 3 grid as a block was reported in [4]. The paper’s authors treated each sub-block as a problem, and applied uniform crossover was to the particular block, in which the crossover positions were limited to the links between sub-blocks. Swap mutation technique was adopted such that it avoids duplication of numerals within a sub-block. This work also did a comparative study of disparity hypothesis and gene duplication using child. It was found The Sudoku was solved with a high degree of accuracy.

Code written in C++, to solve Sudoku, using GA, was explained by Weiss in [5]. He reported that GA’s performance in Sudoku was impaired by slow convergence and inability to escape from local minima. In [6], descriptions on solving Sudoku, using different types of GA were delineated. A novel hybrid genetic algorithm (HGA) was generated, and the workings of HGA, interactive genetic algorithm (IGA), and classical GA were compared. He concluded that HGA gives better results than other GAs. However, the HGA is not that suitable for solving difficult Sudoku puzzles (the puzzles with more unfilled elements).

The authors in [7] described solving Sudoku, using GA mutation and crossover strategies. The Pencil and pen algorithm is one of the frequently proposed methods in the literature, for solutions of the Sudoku puzzle [7]. In GA, used in [7], to solve Sudoku puzzle one crossover type and two mutation types are used. The first mutation operation is applied to a gene (a cell in the matrix) of the chromosome. The second mutation is applied to each of the sub-square rows.

[8] discussed 3 objectives: (1) to check if the GA is efficient in solving the Sudoku problem. (2) Can GA be used to efficiently generate new puzzles for Sudoku? (3) Can GA be used to check the difficulty level of Sudoku problem?

The authors in [9] proposed a modified form of GA, Retrievable Genetic Algorithm (Ret-GA). Ret-GA was applied such that initially it creates a Blueprint Matrix (of the same size as the Sudoku puzzle), wherein ‘1’ is assigned to a particular entry, only if the corresponding entry in the original Sudoku puzzle had an entered value (i.e. non-blank), otherwise that Sudoku location is assigned with value ‘0’. The initial population generated is subjected to Row-wise Uniform Crossover.

[10] described diverse algorithms - Cultural Genetic Algorithm (CGA), Repulsive Particle Swarm Optimization (RPSO), Quantum Simulated Annealing (QSA), and the Hybrid method that combines GA with Simulated Annealing (HGASA), which are used to solve the Sudoku puzzle. This paper concluded that QSA and HGASA are successful in solving the Sudoku puzzle. [11] solved the Sudoku puzzle using a novel multistage genetic algorithm (MGA). To solve a given puzzle, initially, a group table was constructed, with an initial random population. In every cycle, GA worked to find a better solution, and at each iteration, the group table was updated. Swap mutation technique was used, when mutation probability is satisfied.

Dealing with Sudoku through Variable Neighborhood Search (VNS) was shown in [12]. The basic idea is to explore a set of predefined neighborhoods, to provide a better diversification of successful solutions. A particular generation was selected based on the fitness function, invert an exchange strategy was undertaken to obtain the solutions. The performance was compared with Harmony Search, revealed that Harmony search is not as efficient as VNS. Finally, the paper concluded that VNS can produce competitive results at an easy level, and promising results in harder levels.

Authors in [13] introduced a heuristic to grapple with Sudoku, adopting modified crossover and mutation operators of GA. [14]. described a teaching strategy, engaging in-class exercise to introduce GA in Microsoft Excel to solve the Sudoku puzzle A permutation and row-crossover operators were designed for GA to solve Sudoku in [15]; the proposed algorithm was tested on different instances of Sudoku.

On a close review of different versions of GA available in the literature to solve Sudoku problems, the work presented in this paper proposes a study of the effect of using GA for solving Sudoku with combinations of different mutation and crossover operations.

3 Design of Experiments

As noted previously, a Sudoku puzzle is said to be solved, when each of the rows, columns, and grids, contain only single instances of numbers in the range of 1 to 9, such that no digit is repeated within the same row or column or grid. For a traditional Sudoku, the sum of digits in each row, column or grid should be equal to 45. The components of GA are designed as follows.

Population for the GA - The population for the GA to solve is the set of candidates each mean in Sudoku. A two-dimensional array was adopted to represent a Sudoku. Thus, a set of two-dimensional arrays in the population are used in this study.

Fitness of Algorithm - The fitness of each candidate has calculated an algorithm. This algorithm follows the following steps

  1. (1)

    Calculate the number of occurrences of each number row-wise.

  2. (2)

    Calculate the number of occurrences of each number column-wise.

  3. (3)

    Calculate the number of occurrences of each number in all nine 3 × 3 grid.

  4. (4)

    If the row-wise, column-wise, and 3 × 3 grid count is equal to 81 the puzzle is solved.

Mutations - In this experiment, two mutations were considered – Random Resetting and Swap Mutation.

  • Random Resetting - If the value selected in each row is a fixed value then don’t randomize it, otherwise insert a random value into it.

  • Swap Mutation - Randomly select two genes, row-wise, and if both the elements do not belong to the set of fixed elements of the puzzle, then swap them; otherwise, continue, until both the selected elements are not fixed elements. The constraint is that the puzzle must contain at least two nonfixed elements in each row.

Crossovers - The three crossover operators deliberated in this study were a one-point crossover, two-point crossover, and uniform crossover.

  • One-point crossover - In this procedure, a point is selected at random, which is said to be the crossover point; by dividing the chromosome, and swapping the genes of the chromosome concerning crossover point, new off-springs are produced.

  • Two-point crossover - In this procedure, two points are selected at random, which are said to be the crossover points; genes of the parents between the two crossover points are swapped, and the genes, before the first crossover point, will be from the first parent, and genes from second crossover point, will be from the second parent. By combining these, new off-springs are generated.

  • Uniform Crossover - In this procedure, the crossover points are randomly generated, and the genes of the parents are exchanged, at that particular point. No division of chromosome is done in this process, but the genes are replaced at the crossover points. There can be more than one crossover point in a chromosome.

4 Results and Discussions

The results of all the six combinations and mutations and crossovers used with GA to solve the Sudoku are explained in this section. The combinations of mutations and crossover are as follows: Random Resetting Mutation and One-Point Crossover, Random Resetting Mutation and Two-Point Crossover, Random Resetting Mutation and Uniform Crossover, Swap Mutation and One-Point Crossover, Swap Mutation and Two-Point Crossover and Swap Mutation and Uniform Crossover.

The optimal score: Each element in 9 × 9 Sudoku is to be counted one time and since there are 9 numbers in 9 rows, 9 columns, 9 grids, the optimal fitness score of Sudoku, of size 9 × 9, considered in the experiment, is 81, row-wise and column-wise. The optimal fitness score for the 3 × 3 grid is also 81. Summing up all the three fitness scores, a total value of 243 is the optimum score for the solution of Sudoku.

The GA, with each of the above-noted combinations of mutation and crossover, was applied to solve Sudoku puzzles, for 10 different runs and the average performance of GA is presented and discussed.

The results presented in Table 1 consist of the run number, whether or not the Sudoku puzzle was solved, Number of generations, Optimum score of each execution and the Time taken to complete execution. Table 1 depicts the performance of GA in solving Sudoku puzzles when Random Resetting Mutation and One-point crossover were used. An average number of generations obtained was 1091.6; the average optimum score was 244.40, and the average execution time was 54.71 s. The success ratio is 7:10 i.e., 7 out of 10 times the algorithm solved Sudoku perfectly.

Table 1. Sudoku results - GA with random resetting mutation and one-point crossover.

The results, using GA with Random resetting mutation and two-point crossover, are shown in Table 2. An average number of generations obtained was 1149.8, the average optimum score was 234.90, and average execution time was 47.15 s. The success ratio was 4:10, i.e. 4 out of 10 times, the GA algorithm solved Sudoku puzzles, successfully.

Table 2. Sudoku results - GA with random resetting mutation and two-point crossover.

Table 3 depicts the performance of GA when Random mutation and Uniform crossover was used. An average number of generations obtained was 1096.80, the average optimum score was 244, and the average execution time is 47.47 s. The success ratio was 8:10 implies that this combination of mutation and, crossover with GA was able to solve Sudoku in 8 out of 10 runs. The performance in solving Sudoku with Swap mutation and One-Point crossover is presented in Table 4. As seen from the results, the average number of generations obtained was 2000, the average optimum score was 263.20, and average execution time was 96.33 s. The success ratio was 0:10. It is worth noting that this combination of mutation and crossover does not support GA to solve the Sudoku problem in all cases of runs. This gives an insight that the impact of this combination to be studied further to understand the reason for such performance.

Table 3. Sudoku results - GA with random resetting mutation and uniform crossover.
Table 4. Sudoku results - GA with random swap mutation and one-point crossover.

Table 5 displays the performance of GA, with Swap mutation and Two-Point crossover. Results indicate that in all cases, GA uses the maximum generation of 2000, without reaching the solution. The average optimum score it obtained was 256, and average execution time was 95.06 s. The success ratio is 0:10. Table 6 delineates that the GA with Swap mutation and Uniform crossover also failed to attain the solution for Sudoku puzzle, in any of the runs, even with a maximum number of generations. The average optimum score was 260.66, and average execution time was 112.12 s.

Table 5. Sudoku results - GA with random swap mutation and two-point crossover.
Table 6. Sudoku results - GA with random swap mutation and two-point crossover.

The experimental results have established that the Swap Mutation routine is inadequate for GA to solve the Sudoku problem, irrespective of the associated crossover study. Hence, the comparative study was extended to probe the Random Resetting mutation, with all the three types of crossovers. The results were compared by the Success Ratio (SR), an average number of generations taken for successful runs (AnG#), and the Execution Time. The results are presented in Table 7.

Table 7. Comparison of random resetting mutation.

Test observations show that Random Setting mutation with Uniform crossover captured the top position, with higher SR, by yielding more number of successful runs. However, the Two-point crossover led the top position, for its speed, by achieving the solutions, with a minimal number of generations. Although its SR was 4, its AnG# was 299.61. These conflicting performances of Uniform and Two-point crossover need to be investigated further.

5 Conclusions

This paper presented evaluations of solving Sudoku problems by the Genetic Algorithm, using various combinations of Random mutations and crossover operations. Each blend of mutation and crossover was found to furnish different performance results. Empirical evidence of solving Sudoku problems, by various mixes of mutation and crossovers, has shown that deployment of Random mutation with Uniform crossover turned out more successful runs, whereas the same commingled with Two-Point crossover was effective in the speed of convergence.