• No results found

DESIGN METHODOLOGY

III. D Puzzle Combination

In order to fully realize the potential of using a genetic algorithm to solve Sudoku puzzles, ‘linked’ or ‘3-D’ puzzles were connected and generated while the solver and generator mentioned in the above sections.

First, a ‘seed puzzle’ is generated and is used as the base for the remainder of the puzzles that are placed around it. Rather than initializing the starting puzzle with three mini-grids, the algorithm initializes all four sides of the Sudoku grid. Each attached puzzle shares an edge with the main grid. This results in top, right, left, back, and bottom puzzles as well as the main (front) puzzle. The auxiliary puzzles (top, right, left, bottom, and back) share sides with each other as well as shown in Figure 19.

Figure 19: Overview of five linked puzzles. It is displayed like an unfolded cube. For clarity, the puzzle that would be the back of the cube is not shown.

If one were to imagine the puzzles folded into a cube, the sides that would join together to form an edge would contain the same numbers.

In order to create this linked puzzle setup, some constraints must be imposed upon the auxiliary puzzles. For example, in Figure 19, the top row of section 3 cannot contain the numbers 7, 8, 5, or 4 in the two cells immediately to the right of the 9. If it did

contain a 7 or an 8, the bottom right mini-grid in puzzle 1 would be unsolvable, and if it contained a 5 or a 4, the top left mini-grid in puzzle 3 would be unsolvable. Ensuring that the resulting auxiliary puzzles are solvable is imperative when generating a linked

Sudoku puzzle.

After the linked puzzles are initialized, the solver is applied to every puzzle, and the result is a set of six solved, linked Sudoku grids. This process is shown in Figure 20.

Figure 20: Initialization flow chart

A traditional Sudoku puzzle typically has a unique solution. When generating the 3D cubes, the proposed algorithm does not check for uniqueness of solutions. There are two reasons for this. First, checking for uniqueness would make the puzzle generation

process slower. Second, if each member within a set of six puzzles had a guaranteed unique solution, then they are essentially six different puzzles and can be solved

individually. If there is no guarantee of a unique solution for each side, then changing the values of any of the linked edges has a very real effect on a side’s four neighbors.

III.E 3D Representation – SudoKube III.E.1 SudoKube Introduction

In order to truly test the ability of genetic algorithms in the combinatorial arena, a method of solving six linked puzzles simultaneously was developed. Due to the lack of availability of a six sided Sudoku puzzle, a new brainteaser had to be created in order to provide the algorithm with something on which to operate. The previous sections of this thesis outlined the generation of the 3D puzzle (SudoKube). The following pages describe the solver algorithm and detail its effectiveness.

III.E.2 Genotype

In the previous section covering the 2D representation, the genotype was a 9  9 grid. Each population member was its own copy of the puzzle on which the genetic algorithm was operating. However, in the 3D solver, each population member is a 6  9  9 array – corresponding to the six sides of the generated puzzle and each of the nine rows and columns per side.

III.E.3 Operators

III.E.3.a Parent Selection

Originally, the algorithm selected a random member from the top half of the population and another member from the entire population to choose a pair of parents. As stated previously, this did not fully utilize the ability of a genetic algorithm to select the fittest members the majority of the time. Instead, the probability of selecting a population member k is given by equation 4, defined earlier and shown again below, which is a modified form of a selection probability equation that is found in [10].

<> ? 2 ^`^<`\_>`Ya (4)

III.E.3.b Crossover

The proposed algorithm initially employed uniform crossover, much like the 2D representation. However, after comparing uniform crossover to fitness based crossover, the performance of uniform crossover was not as effective. Also integrated into the proposed algorithm is the difference degree crossover method described above and as taken from [23].

The final version of the proposed algorithm utilizes a fitness based + difference degree crossover method. Two parents are selected based on the parent selection method described above. After selection, every cell in parent 1 is compared to every

corresponding cell in parent 2. The proposed algorithm tracks the total number of cells

that contain different values. For a SudoKube there are 81 * 6 <486) cells. The

difference degree equation is a simple ratio of the number of cells that differ to the total number of cells.

b ? ccd (5)

In the above equation, N is the total number of cells and Nd is the total number of cells that differ between parent 1 and parent 2.

Next, a crossover type is selected based on total grid, column, or row fitness. The probability of selection for each type is inversely proportional to the fitness values with respect to the first parent. For example, if parent 1 has an excellent row fitness total but an abysmal column fitness total, it is likely that row crossover will be selected over column crossover. Figure 21 describes the crossover operator.

Figure 21: Fitness dependent crossover with difference degree selection

After both parents and the crossover method are selected, each segment (row, column, or mini-grid, depending on the crossover type) from each parent is compared.

The segment with the better fitness is kept and passed on to the new generation. For example, if P1 has a first row with fitness 2, and P2 has a first row with fitness 9, the child would acquire the first row from P1. An example is below in table 3.

Table 3: Example of fitness-dependent crossover.

The mutation operator for the 3D representation is very similar to the operator for the 2D representation. However, there is a key difference. The operator is applied to all six sides of the cube, not just to one puzzle. If row mutation/growth is selected, the proposed algorithm applies row mutation/growth (as described previously) to each side in succession.

III.E.3.d Fitness Calculation

Fitness calculations for the 3D representation of Sudoku are calculated in much the same manner as the 2D representation. Duplicates in each row, column and mini-grid

are added together to acquire a total side fitness. Each population member goes through this process to calculate the number of duplicates for all six of its sides, and the total overall fitness is the sum of the total side fitness values.

The difference between the fitness calculation for the 3D representation and the one for the 2D representation is that two rows and two columns have a weighted fitness in the 3D representation. A row or column that is an edge of the cube has its fitness value multiplied by ten. For example, the top row of a side (which is the bottom row of an adjacent side) with two duplicates would have a fitness value of 20. If the fitness is zero, this obviously has no effect. Weighting helps ensure that the outer edges of each Sudoku puzzle will not have any duplicates.

III.E.4 Settings

There are several significant settings that have an effect on how well the proposed algorithm performs. Some of these settings, such as ‘population size’ and ‘maximum iterations,’ are common to any genetic algorithm. Others, such as ‘mutation ceiling’ and

‘mutation rate multiplier’ are not. These settings were optimized when testing the 2D solver, and the settings were carried over and used in the 3D representation.

III.E.4.a Mutation Ceiling

The mutation ceiling is the highest value that the mutation probability can attain.

Setting this number too high causes a chaotic placement of random numbers within puzzles for several iterations after the mutation probability is increased to its ceiling.

Setting this number too low greatly increases the chance that the algorithm will remain stuck in a basin once it enters one.

Figure 22 displays a segment of sample data. It shows that 10% is an value for the mutation ceiling. Using this value led to finding solutions quickly and effectively.

Figure 22: Time vs. mutation ceiling

Related documents