Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern ...csphil/CS335/appendixB.pdf ·...

6
Appendix B Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern Databases In this appendix we look at admissible heuristic functions for the Rubik’s cube puzzle and the 15 and 24 tile puzzle based on pattern databases. A pattern database is a heuristic function stored as a lookup table which stores the lengths of optimal solutions for instances of subproblems. The results are from papers by Korf. B.1 Rubik Cube If we consider Rubik’s cube, it can be categorised using a state of 20 elements. This consists of representations of the orientations of the sub–cubes which move. There are 8 corners and 12 edges. Each corner has 3 orientations and each edge 2 orientations. Thus a state is a 20 element vector. Typical a human solving the puzzle takes about 50 – 100 moves. This is done by using learnt algorithms for manipulating pieces leaving others static (e. g. turning an edge cube over while leaving others fixed). There are 8! permutations of the 8 corners and 12! permutations of the 12 edges. Each corner can have 3 orientations and each edge 2, so altogether the total number of states is 8! × 3 8 × 12! × 2 12 . But these permutations are split into 12 mutual classes, so that one can only transform between states in the same class. So from one state there are 8! × 3 8 × 12! × 2 12 /12 states reachable. This is 4.3 × 10 19 . Compared with the 15 puzzle – 1013 states. (16!/2). Take as basic moves 90 clockwise, 90 counter–clockwise and 180 in each of the six planes of the Rubik cube. We consider the centre of the cube as fixed in space and so don’t rotate the three central planes – this determines the colours of the faces for the goal state. The search tree then has 18 (6) way branching initially. Then 15 way branching since rotating the same face consecutively results in a state which appears elsewhere in the tree. However, twisting opposite faces commutes so we can reduce the branching further. It can be shown that the average branching factor is 13.3. xi

Transcript of Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern ...csphil/CS335/appendixB.pdf ·...

Page 1: Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern ...csphil/CS335/appendixB.pdf · Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern Databases In this appendix

Appendix BKorf’s Optimal Solution to Rubik’s CubePuzzle and Pattern Databases

In this appendix we look at admissible heuristic functions for the Rubik’s cube puzzleand the 15 and 24 tile puzzle based on pattern databases. A pattern database is a heuristicfunction stored as a lookup table which stores the lengths of optimal solutions for instancesof subproblems. The results are from papers by Korf.

B.1 Rubik Cube

If we consider Rubik’s cube, it can be categorised using a state of 20 elements. Thisconsists of representations of the orientations of the sub–cubes which move. There are 8corners and 12 edges. Each corner has 3 orientations and each edge 2 orientations. Thusa state is a 20 element vector.

Typical a human solving the puzzle takes about 50 – 100 moves. This is done by usinglearnt algorithms for manipulating pieces leaving others static (e. g. turning an edge cubeover while leaving others fixed).

There are 8! permutations of the 8 corners and 12! permutations of the 12 edges. Eachcorner can have 3 orientations and each edge 2, so altogether the total number of statesis 8! × 38 × 12! × 212 . But these permutations are split into 12 mutual classes, so thatone can only transform between states in the same class. So from one state there are8!× 38 × 12!× 212/12 states reachable. This is 4.3× 1019.

Compared with the 15 puzzle – 1013 states. (16!/2).Take as basic moves 90◦ clockwise, 90◦ counter–clockwise and 180◦ in each of the six

planes of the Rubik cube. We consider the centre of the cube as fixed in space and sodon’t rotate the three central planes – this determines the colours of the faces for the goalstate. The search tree then has 18 (6) way branching initially. Then 15 way branchingsince rotating the same face consecutively results in a state which appears elsewhere in thetree. However, twisting opposite faces commutes so we can reduce the branching further.It can be shown that the average branching factor is 13.3.

xi

Page 2: Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern ...csphil/CS335/appendixB.pdf · Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern Databases In this appendix

Depth Nodes1 182 2433 3,2404 43,2545 577,3686 7,706,9887 102,876,4808 1,373,243,5449 18,330,699,168

10 244,686,773,80811 3,266,193,870,72012 43,598,688,377,18413 581,975,750,199,16814 7,768,485,393,179,32815 103,697,388,221,736,96016 1,384,201,395,738,071,42417 18,476,969,736,848,122,36818 246,639,261,965,462,754,048

Table B.1: Nodes in Search Tree

From table B.1 we see that there must be some problems requiring at least 18 moves(could be much bigger), since number of reachable states using 17 moves is still less thanthe total number of states possible.

Korf used variant of manhattan distance – distance is min number of moves to correctposition and orientation. To be admissible we divide by 8 as 1 basic move moves 4 othercorners and 4 edges. He actually used IDA* – the variant of A* called iterative deepeningA*. It is also possible to take a simpler heuristic – just use consider the edge cubes onlyand divided by 4.

In general, the basic Manhattan distance gives too low a value and so in general there istoo much computation using this directly even if the values are precomputed. ComputingIDA* tree to a depth 14 would take 3 days , to 18 250 years. (on a Sparc Ultra).

A modified admissible heuristic was evaluated as follows:

h(n) = max{hcorners(n), he1(n), he2(n)}

where hcorners computes the minimum number of moves to ensure the all 8 corners are inthe correct position Figure B.1. This is precomputed using a breadth-first search from thegoal state. The last cube is determined by the others, and so there are 8!37 possibilities.Each value can be stored using 4 bits since the maximum value is 11. 42M is needed forthis table.

xii

Page 3: Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern ...csphil/CS335/appendixB.pdf · Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern Databases In this appendix

Figure B.1: Corner Database

(a) Edge Set1 (b) Edge Set2

Figure B.2: Two Edge Sets

The 12 edges are split into two groups of 6 Figure B.2. he1 then evaluates the minimumnumbers of moves to position the first set of edges cubes and he2 for the second set. Thenumber of possible combinations is 12!/6! · 26. The maximum number of moves to orient 6edges is 10 and so 4-bits can be used per position. Hence 20M is required for each table.So altogether 82M is required for all tables.

The stored table is also called a pattern database. It took about 1 hour to computethe table. This table needs to be stored in RAM for the IDA* algorithm, but this is nowpossible with a reasonable workstation.

Korf performed experiments on states produce by making 100 random basic moves.The table B.2 shows the statistics for 10 such cases. All had solutions within 18 movesand 1 only 16 moves. It is thought that 20 moves is sufficient for all start states, but thishas not been proved.

So by careful choice of a heuristic it is possible to tackle these large combinatorialproblems where brute search would clearly be useless.

xiii

Page 4: Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern ...csphil/CS335/appendixB.pdf · Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern Databases In this appendix

No. Depth Nodes Generated1 16 3,720,885,4932 17 11,485,155,7263 17 64,837,508,6234 17 126,005,368,3815 18 262,228,269,0816 18 344,770,394,3467 18 502,417,601,9538 18 562,494,969,9379 18 626,785,460,346

10 18 1,021,814,815,051

Table B.2: Table of Results

B.2 15 and 24 Tile Puzzle

Pattern databases for the 15 puzzle were first introduced by Culberson and Schaeffer.One example of splitting the 15 puzzle into subproblems is indicated in Figure B.3.

Figure B.3: 15 Puzzle Pattern Database

The 8 blue (light grey) tiles are in one set and the 7 red (dark grey) in the other.The two databases are computed (offline) using a backward breadth first search from thegoal state. The non-pattern tiles are not distinguished but their moves are counted. Theheuristic for the 15 puzzle is then taken as the maximum of these two heuristics. So in theabove example, 31 moves can solve the red tiles and 22 the blue. So the heuristic valuefor the configuration on the left is taken as 31. This is then clearly an admissible heuristicsince both sets of tiles have to be put into their final positions. Other divisions of the tilesis possible as alternative for the pattern databases (they could even overlap). Figure B.4shows another possible split.

xiv

Page 5: Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern ...csphil/CS335/appendixB.pdf · Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern Databases In this appendix

Figure B.4: Alternative 15 Puzzle Pattern Database

Korf changed the way he counted the moves so that the moves of non-pattern tiles areignored. As long as the subsets don’t overlap, then instead of maximising the two heuristicvalues they can be added as any one tile will only belong to one set.

Taking the configuration in Figure B.5, 20 moves are needed to position the red tilesand 25 moves for the blue. Hence the heuristic value for the configuration will be takenas 20+25 = 45 which will be a lower bound on the minimal number of moves to solve thepuzzle and so is admissible. The 7-tile database has about 58 million entries and the 8-tilesdatabase about 519 million entries.

Figure B.5: Configuration with Goal

xv

Page 6: Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern ...csphil/CS335/appendixB.pdf · Korf’s Optimal Solution to Rubik’s Cube Puzzle and Pattern Databases In this appendix

Korf used an additive pattern database for the 24 puzzle based on the subsets indicatedin Figure B.6. All subsets have six tiles and the pattern databases contain about 128 millionentries. IDA* can solve optimally random 24-puzzle configurations using this heuristic(sum of the four heuristics on the subsets) in about 100 moves. The running time in hisexperiments were 18 seconds to 10 days with an average of about 1.5 days.

Figure B.6: 24 Puzzle Subsets

xvi