0% found this document useful (0 votes)
326 views3 pages

Parallel Rubik's Cube Solver: Abstract-This Report Investigates Parallel Processing For

IIT Bombay ME 766 - Course Project

Uploaded by

Tejas Ladhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
326 views3 pages

Parallel Rubik's Cube Solver: Abstract-This Report Investigates Parallel Processing For

IIT Bombay ME 766 - Course Project

Uploaded by

Tejas Ladhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Parallel Rubik’s Cube Solver

Nambilakshmi Ramachandran Tejas Ladhe Mohd. Zakir Hussain


Mechnical Engineering Mechanical Engineering Mechanical Engineering
IIT Bombay IIT Bombay IIT Bombay
Mumbai, India Mumbai, India Mumbai, India
rnambilakshmi@iitb.ac.in tejasladhe24@gmail.com zakirhussain@iitb.ac.in

Sanjev T Vishnu
Metallurgical Engineering and
Materials Science
IIT Bombay
Mumbai, India
vishnutsanjevofficial@gmail.com

Abstract—This report investigates parallel processing for facelets that are a unique subset of the colours, which makes
solving the 3 x 3 x 3 Rubik’s Cube. The parallel processing it distinct from the others.
approach is based on IDA* using a pattern database as the
underlying heuristic because of its well-established
effectiveness. The parallel algorithm is an extension of the
Michael Reid algorithm which is sequential. The parallel
algorithm exhibits good speedup and scalability. Parallel
processing helps in solving a Cube with initial cube
configurations having solutions at a higher depth level in the
search tree.

Keywords—Rubik’s cube, Kociemba’s algorithm, Korf’s


algorithm, Reid’s algorithm, IDA*, Parallel processing, OpenMP

I. INTRODUCTION
Improving an algorithm to solve a Rubik’s cube requires
a thorough analysis of past efforts in both multi-processor Figure 1: The Rubik’s Cube
algorithms and sequential solutions to the problem. From
previous research papers, it became clear that Manhattan A. Singmaster notation
distance heuristic, was not the best approach. During the Singmaster notation devised by David Singmaster
course of the work done, it became clear that pattern describes a sequence of moves. Clockwise turns of the six
databases as modified by Michael Reid is perhaps the best outer layers, or slices, are denoted by the capital letters where
existing heuristic for this problem. The use of pruning and F is front, B is back, U is up, D is down, L is left and the
symmetry improve the pattern database and hence the right face is denoted by an R.
performance of the algorithm. Also, parallelization of the B. The Metrics
search would maximize the success of the algorithm being
used while reducing the time required in finding a solution To reach the goal state from any random configuration, a
for larger depths. Hence all the necessary issues related to the sequence of moves is applied. The minimum number of these
parallel approach like the load balancing techniques and the moves required to solve the Cube is known as the distance
task distribution and scalability would need to be considered. from the goal state while the maximum distance is the
Although the heuristic used is improved, the algorithm used diameter of the Cube. These moves or distances are
for searching remains the same, IDA*. measured using either the Half Turn Metric (HTM) or the
Quarter Turn Metric (QTM). In the first metric, only half
II. THE 3X3X3 CUBE turns are allowed while in the quarter turn metric, only
Rubik’s cube is considered to be one of the most famous quarter turns are allowed. Such a sequence of moves used to
combinatorial puzzles of its time. Erno Rubik of Hungary get to the goal state is known as a macro-operator or a macro.
invented it in the late 1970s. The standard version of this The Cube can be represented by a graph in which a
cube consists of a 3 X 3 X 3 cube, with a different colour on vertex represents a unique state and an edge represents a
each face: red, blue, green, yellow, white and orange. The transition between adjacent states. Since there are 18
faces are divided into 9 squares each, which can be elementary moves, there are 18 possible adjacent states. The
scrambled by rotating a row (or column) at a time. It is branching factor is considered to be the ratio of the number
divided into three 3×3×1 slices along each of x, y, and z axes of nodes explored at a given depth (d+1) over the number of
such that each slice can be rotated a quarter turn clockwise or nodes explored at a depth d.
counter clockwise with respect to the rest of the cube. The
slices divide each face of the Cube into 9 facelets. The slices III. THE SEARCH ALGORITHM
also divide the Cube into 3 3 = 27 pieces, or sub cubes, 26 of A standard 3 X 3 X 3 Rubik’s cube can have 4.3252 X
which are visible. In its goal state, each of the six sides has 1019 different states from a given configuration. The search
its own colour. Each visible piece has one, two or three algorithm used was the Iterative Deepening A* (IDA*)
algorithm which is an optimal, memory bounded heuristic

XXX-X-XXXX-XXXX-X/XX/$XX.00 ©20XX IEEE


search. A heuristic function provides an estimate of the However, he simplified it down to a mere 2 groups using the
distance of a particular state from a goal state. The heuristic IDA* code. The IDA code is a general search algorithm that
used was the one Richard Korf had suggested. The simplifies the steps required to travel from the root to the
performance of the search can be improved by using parallel solution. First, he identified a number of sub problems that
hardware. But the choice of heuristic is another main factor are small enough to be solved optimally:
affecting the performance of the algorithm. Heuristics 1. The cube restricted to only the corners, not looking
functions should be chosen properly to avoid inherent at the edges
problems pertaining to high time complexity. If there is no 2. The cube restricted to only 6 edges, not looking at
overestimation of depth then the proposed method is
the corners or at the other edges.
guaranteed to improve the performance of IDA* algorithm.
3. The cube restricted to the other 6 edges.
IV. STANDARD ALGORITHMS
V. ITERATIVE DEEPENING A*
Michael Reid’s optimal cube solver is based on ideas
developed by Herbert Kociemba and Professor Richard Korf. Iterative-Deepening A*, also known as IDA*, was
This is supposed to be a practical implementation of "God's introduced by Richard Korf in 1985. It has since become the
Algorithm" for Rubik's Cube. He has made some dominate method to solve this class of permutation puzzles
improvements in the Korf’s method. to which Rubik’s Cube belongs. Where A* fails, IDA* tends
to succeed given strong enough admissible heuristic. IDA*
A. God’s Algorithm is simply A* with iterative deepening. This reduces the
God’s algorithm uses a lookup table that is keyed over the memory complexity from O(bd) to O(bd). It does this by
various instances of the problem. Rather than giving the keeping track of the maximum depth explored from the last
solution, it gives the minimum number of moves remaining iteration and incrementally increases it. By doing so, it no
to reach the goal state. Then to solve a particular instance longer needs to store all the states in memory. The
one simply chooses the next move that is one closer to the optimality of A* still applies, so IDA* also gives an optimal
goal state. The lookup table can be further refined to only solution. The Manhattan distance is less useful as a heuristic
store the number of moves left modulo 3, which only for the Cube since if one were to total the number of moves
requires 2 bits per entry. This is sufficient in picking the necessary to place each cubie, one must divide that total by
next move since any adjacent move is one less, the same or eight since eight cubies are moved for each rotation of a
one more towards the solution. slice of the Cube. This results in a very low heuristic value.
B. Thistlethwaite's algorithm VI. SOLUTION
The way the algorithm works is by restricting the positions A. IDA* with Pattern Databases
of the cubes into groups of cube positions that can be solved
using a certain set of moves. The key idea is to take a subset of the goals of the
original problem, precompute and store the exact number of
Group Description moves needed to solve these sub goals from all possible
Group 0 This group contains all possible positions of the initial states. Then the exact solution to the sub goals is used
Rubik's Cube as a lower bound heuristic for an IDA* search of the original
Group 1 Positions that can be reached from the solved problem. The idea behind the pattern database was to avoid
state with quarter turns of the left, right, front the runtime computation of the heuristic, at the expense of
and back faces of the Rubik's Cube, but only the extra memory storage. Since we have a large
double turns of the up and down sides. computational engine in the form of a cluster, we don’t need
Group 2 Restricted to turns that can be reached with only to worry about the extra runtime computation.
double turns of the front, back, up and down
faces and quarter turns of the left and right faces
Group 3 Positions in this group can be solved using only
double turns on all sides.
Group 4 The final stage, completely solved

C. Kociemba's Algorithm
Thistlethwaite's algorithm was improved by Herbert
Kociemba. He reduced the number of groups to only two
therefore making a substantial decrease in required moves to
a maximum of 29 moves and a minimum of 19.

Group Description
Group 0 All possible positions of the cube
Group 1 Split into the top half of the cube which uses the
IDA formula to subdivide and solve Figure 2: Data flow
Group 2 Split into the bottom half of the cube which uses
the IDA formula to subdivide and solve B. Creation of pattern database
A solved cube is represented as (12 edges, 8 corners):
D. Korf’s Algorithm UF UR UB UL DF DR DB DL FR FL BR BL UFR URB
UBL ULF DRF DFL DLB DBR
Korf’s algorithm is based on the works of Kociemba’s An example of scrambled cube is:
algorithm in terms of splitting the cube into subgroups.
UL BD LB UF FL FD UR RF DR BU LD BR BDL FRU which must be performed sequentially; this is known as the
BRD RFD BLU URB FUL FLD serial fraction, F. This serial fraction is calculated as:
The table is generated in a breadth-first "forward-search" F = (1/Speedup -1/P)/ (1-1/P)
manner. Depth 0 is stored at the position of the goal state
and all 18 moves are applied to this state. At the VIII.RESULT
corresponding positions depth 1 is stored. In the next pass Multiple experiments with different orientations were
the 18 moves are applied to all states corresponding to those carried out. The time taken to solve a complex and simple
positions in the pruning table which have an entry 1. And orientation is shown in Figure 4 (blue line – parallel, orange
the process continues. If there are not many empty entries – serial) and Figure 5 (blue line – parallel, red – serial ). We
left in the pruning table, we flip to "backward search". We can observe significant difference in the time taken to
apply the 18 moves to all permutations which belong to compile in a complex scenario as the number of threads
empty entries and look if the result is a permutation which increase whereas the difference is small in a simple
has a entry corresponding to the depth d of the last pass. In orientation.
this case we fill the entry with d+1. In this way we save a
considerable amount of time when generating the tables.

C. Pseudocode
This image showcases the pseuodocode used for the
algorithm. Programming is done with C with OpenMP API
for parallelizing.

Figure 4: Complex orientation

Figure 3: Pseudocode

VII. PARALLEL PROCESSING


A. Efficiency
Figure 5: Simple orientation
The relative efficiency is defined as
T1/ (P*Tp) REFERENCES
Where T1 is the execution time on one processor and Tp is
[1] Culberson, J.C., and Schaeffer, J., “Searching with Pattern
the execution time on P processors whereas the absolute Databases,” Proceedings of the 11th conference of the Canadian
efficiency is defined by making the time T1 as the execution society for the computational study of intelligence, Springer Verlag,
time on a processor of the fastest sequential algorithm. It is 1996.
sometimes possible to get efficiencies greater than 1. The [2] David Singmaster Notes on Rubik’s magic cub, Hillside, New Jersey,
1980.
efficiency values are calculated with varying numbers of
[3] Keith, H.R., “Solving Rubik’s Cube,” NE, pp. 43-207
processors for comparison purposes.
[4] Korf, R.E., “Depth-First Iterative-Deepening: An Optimal Admissible
B. Speedup Tree Search,” Artificial Intelligence, 1985, Vol. 27, pp. 97-109.
[5] Korf, Richard. “Finding optimal solutions to Rubik's Cube using
Relative speedup is defined as T1 / Tp, where T1 is the pattern databases”, Proceedings of the Fourteenth National
execution time on one processor and Tp is the execution time Conference on Artificial Intelligence (AAAI-97), Providence, RI, pp.
on P processors whereas the absolute speedup is defined by 700-705, July 1997
making the time T1 the execution time on a processor of the [6] Study Report titled “Implementing an IDA* search on a cluster of
fastest sequential algorithm. In certain conditions, a speedup workstations to solve a Rubik’s cube” by Sameer Abhyankar and
of greater than P can be achieved. Bimal Tandel. University of Texas at Arlington.
[7] Singmaster, David. Notes of the Rubik’s Magic Cube. Enslow, 1981
C. Serial fraction
According to the Amdahl’s Law, the speedup of a parallel
program is effectively limited by the number of operations

You might also like