Tải bản đầy đủ (.pdf) (39 trang)

solving exact cover problem on distributed computing system

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1022.37 KB, 39 trang )



VIETNAM NATIONAL UNIVERSITY, HANOI
UNIVERSITY OF TECHNOLOGY AND ENGINEERING


Tuan Anh Nguyen


SOLVING EXACT COVER PROBLEM ON
DISTRIBUTED COMPUTING SYSTEM






BACHELOR THESIS

Faculty: Information technology




















HA NOI - 2010

1


VIETNAM NATIONAL UNIVERSITY, HANOI
UNIVERSITY OF TECHNOLOGY AND ENGINEERING


Tuan Anh Nguyen


SOLVING EXACT COVER PROBLEM ON
DISTRIBUTED COMPUTING SYSTEM






BACHELOR THESIS


Faculty: Information technology
Department of Networks and Computer Communications



Instructor: M.Sc. Phuong Ho Dac













HA NOI - 2010

2

ABSTRACT

This thesis depicts detail the way to design and implement a distributed
computing system to solve exact cover problems based on Donald E. Knuth’s Dancing
Links algorithm. A variation of these algorithms is developed which enables the
problems to be distributed to a global network of computers using the JPPF Parallel
computing framework. The ability of parallel and grid computing allow more complex

and bigger problems to be solved in acceptable time. Exact cover is known as a
general type of problem which can be represented to solve wide range ones such as N-
queens, Pentomino tiling, Latin square puzzles, Sudoku, etc. The details of the
modified Dancing Links algorithm and the implementation will be explained in detail
as follows. A cluster of computers is used to examine the speed and efficiency of the
algorithm.


3

TABLE OF CONTENTS

CHAPTER 1: INTRODUCTION 6
1.1 OVERVIEW 6
1.2 RELATED WORK 6
1.3 N-QUEEN PROBLEM 6
CHAPTER 2: DANCING LINKS ALGORITHM 10
2.1 EXACT COVER 10
2.2 GENERALIZED COVER 11
2.3 ALGORITHM X 13
2.4 DACING LINKS ALGORITHM 16
2.4.1 DATA STRUCTURE 16
2.4.2 ALGORITHM 18
CHAPTER 3: IMPLEMENTATION DETAILS 23
3.1 A BRIEF VIEW ABOUT JPPF PARALLEL COMPUTING FRAMEWORK 23
3.2 ARCHITECTURE DETAILS 24
3.3 PARALLEL DANCING LINKS ALGORITHM 27
3.4 TRANSFORMS 28
3.4.1 N-QUEEN 28
3.4.2 MATRIX FILE FORMAT 30

3.4.3 BUILDING BOOLEAN MATRIX 30
CHAPTER 4: EXPERIMENTAL RESULTS 32
CHAPTER 5: CONCLUSION AND FUTURE WORK 37
5.1 CONCLUSION 37
5.2 FUTURE WORKS 37
Implement a new load-balancing algorithm 37
Implement more transforms 37
REFERENCES 38


4

TABLE OF FIGURES

Figure 1 Board where the queens at B1 and H7 attack each other 7
Figure 2 One solution of the 8-queen problem 8
Figure 3 The two solutions S1 (left) and S2 (right) to the four4-queens problem 13
Figure 4 Algorithm X search tree for the example matrix 16
Figure 5 Doubly-linked list 17
Figure 6 Doubly-linked list with element x removed 17
Figure 7 Circular quad-linked list representation of the example matrix 18
Figure 8 The matrix before column A is covered 19
Figure 9 The matrix after column A has been covered. 20
Figure 10 JPPF network topology 23
Figure 11 JPPF Monitoring and Administration Tool 24
Figure 12 Simple architecture without Parallel computing framework. 25
Figure 13 DNS System full architecture. 26
Figure 14 Simulation Architecture 32
Figure 15 Non-parallel execution time 33
Figure 16 Execution time of parallel test compare with non-parallel test 33

Figure 17 Simulation Charts 34
Figure 18 Jobs executing in system 35
Figure 19 System settings. 36

5

ACKNOWLEDGEMENTS

Firstly, I would like to express my gratefulness to my supervisor, M.Sc. Ho Dac
Phuong, Department of Networks and Computer Communications, for his guidance,
inspiration, and encouragement during the time I work on this thesis. Without his great
help, I couldn’t finish my thesis.

Secondly, I would like to thank the University of Technology and Engineering –
Hanoi, Vietnam National University, where I have a chance to work and study in a
good environment for four years.

Last but not least, I would like to give my thanks to my family as well as my
friends who always support, stand by me and encourage me a lot throughout my
student life. They have been always the endless source of encouragement, ambition of
my life.

Ha Noi, June 2010
Nguyen Tuan Anh

6

CHAPTER 1: INTRODUCTION

1.1 OVERVIEW

Exact cover is known as a general type of problem which can be represented to
solve wide range ones such as N-queens, pentomino tiling, Latin square puzzles,
Sudoku, etc. Solving high complexity exact cover problems is an interesting topic in
mathematic field as well as computer science. Dr. Donald Knuth invented an algorithm
called Dancing Links (DLX) [1] to solve them. Algorithm X is a recursive,
nondeterministic, depth-first and backtracking algorithm that can find all solutions to
any exact cover problem. However, a huge of computations must be process when the
complexity of the problem increases. This cannot implement on a single computer
system at a reasonable time. That is the reason why designing and implementing a
distributed computing system for solving exact cover is the aim of this thesis.
1.2 RELATED WORK
In recent years, there have been a large number of implementations of the
Dancing Links algorithm available. In addition to Knuth’s own implementation, in
CWEB [2] there are source codes for Java, Python, C, C++, Ruby, Lisp, Haskell,
MATLAB, etc. Most of the implementations were aimed for a specific application:
Sudoku and all these implementations share the common that none of them was
designed for parallel processing.
Alfred Wassermann and Matthew Wolff developed their own parallel algorithm
to solve Knuth’s algorithm in [3] the n + k queen problem [6] by using PVM [4] and
MPI [5]. However, they only published the solutions to their respective problems and
not the actual implemented their research. The only available open source parallel
version is written by Owen O’Malley for the Apache Hadoop project [7] in May 2007.
His implementation used Hadoop, an implementation of MapReduce framework [8], a
programming model suggested by Google for large-data processing, to do the
computations in parallel. However, that what this implementation is and how it divides
the problem into smaller pieces has not been published.
1.3 N-QUEEN PROBLEM
Eight-queen problem is the classic problem, which has become very familiar
with the field of computer science. However, we should also revise about eight-queen
problem as well as tend to expand the problem.

Historically, the problem was introduced in 1948 by Max Bezzel player, and
many mathematicians later, like Gauss and Georg Cantor, have worked on the problem
and its generalized-queens problem. The first algorithm was given by Franz Nauck in
1850 and he is also the person who generalized to N-queen problem. In 1874, S.
Gunther offered a method for finding the solution by using the formula, and JWL
Glaisher completed this method.
7

The eight-queen puzzle is the problem of placing eight chess queens on an 8×8
chessboard so that none of them is able to capture any others using the standard chess
queen's moves. The queens must be placed in such a way that no two queens can
attack each other. Thus, the solution requires that not any two queens share the same
row, column, or diagonal. The eight-queen puzzle is an example of the more general n-
queen problem of placing n queens on an n×n chessboard.
Figure 1 shows an invalid solution because the queens at B1 and H7 attack each
other. Figure 2 shows a valid solution to the eight-queen problem.

Figure 1 Board where the queens at B1 and H7 attack each other
8


Figure 2 One solution of the 8-queen problem
Depending on the symmetry of each solution, we can find out seven other
solutions by rotating the board 90, 180, and 270 degrees. By transforming the upper
and lower board and applying the rotation, we can find another four solutions. The
eight-queen problem has total 92 solutions.
N-Queen problem is the problem which is generalized from eight-queen problem.
The problem set asks for the location n queens post on the board size n × n so that two
queens cannot attack themselves. To solve the problem completely, we must use
recursive method to find exhaustively possible outcomes of the problem. There do

have many mathematicians as well as computer scientists researching and giving N-
queen algorithm to the problem; one of the most common and simplest algorithms is
backtrack searching algorithm. One of the characteristics of rotating backward search
algorithm bases on the model search on the tree, and the number of nodes required
have to increase as exponentially as the number of the depth of search tree do. Thus,
the numbers of calculations to browse all the nodes on a tree are very large.

In the process of finding and developing grid-computing applications, we chose
N-Queen problem by the following compatible characteristics:
 Be a simple, single solution algorithm and easy to install.
 Be able to implement huge amount of computation.
 Be able to compute parallel
The remaining of my thesis is divided into four chapters:
 Chapter 2: Dancing Links Algorithms
I would like to give an overview of exact cover problem, Dr. Knuth’s algorithm X and
its advantages and efficiencies when we use it to solve exact cover problem.
9

 Chapter 3: Implementation Details
This chapter describes about JPPF parallel computing framework protocol and detail
architecture of Distributed N-Queen Solver (DNS).
 Chapter 4: Testing and Results
This chapter shows the results of my simulation in order to check the efficiency of the
algorithm and DNS system.
 Chapter 5: Conclusion and Future work
The last chapter is the summary of this thesis and discuss about some work will be
done in near future.

10


CHAPTER 2: DANCING LINKS ALGORITHM

In computer science, Dancing Links (also known as DLX) is an algorithm
invented by Donald Knuth to implement his Algorithm efficiently X [1]. Algorithm X
is a recursive, nondeterministic, depth-first and backtracking algorithm that can find
all solutions to any exact cover problem. It was firstly described in [1] where Donald
Knuth looked at the details of the algorithm and used it to solve some concrete
problems. Before looking at the DLX algorithm in detail, we need to explain what an
exact cover problem is.
2.1 EXACT COVER
To represent an exact cover problem we use a binary matrix which each element
is either zero or one (non-zero). This type of matrix is also called Boolean matrix,
logical or {0, 1} matrix. The word “matrix” in the rest of this thesis can be understood
as a Boolean matrix that prevents ambiguity; the word “non-zero” is used instead of
“one” to represent the value of matrix element.

Definition: Given a collection of subsets E of a set U, an exact cover is a subset
S of E so that each element of U appears once in S.
The set U is the collection of columns U = {1, 2, …, n}. E is the collection of
rows where each set contains the number of the columns, which has non-zero values.
The idea mentioned here is to?. For the general m × n matrix:

=






1,1


1,2

1,3
 
1,

2,1

2,2

2,3
 
2,

3,1

3,2

3,3
 
3,
    

,1

,2

,3
 

,






a
i,j
is an element in the matrix at row i, column j where a
i,j
∈ {0, 1}. The dimension of
matrix is m x n that means the number of rows is m and the number of columns is n. A
set of rows from of the matrix A is an exact cover i if and only if each column has
exactly one non-zero element. We can consider set S a subset of matrices; the matrix A
consists of k rows and n columns. Let R
A
and R
S*
be the set of rows in matrix A and
S* respectively. Then S* forms the following k× n matrix:
=






1,1


1,2

1,3
 
1,

2,1

2,2

2,3
 
2,

3,1

3,2

3,3
 
3,
    

,1

,2

,3
 
,








11

k ≤ m so that S* is a reduced matrix of A or, in case where k = m, the two matrices are
identical.
Intuitively, we see that the subset R
S*
is an exact cover if the following equation
is satisfied.



,

=1
= 1 {1,2, , }

Example: Given a binary matrix A, find the set of all satisfied that an extract
found cover. Take the following matrix as an example:








1 0 0 0
0 1 1 0
1 0 0 1
0 0 1 1
0 1 0 0
0 0 1 0







This represents a specific exact cover problem.
In matrix A, we can easily see that the second and the third row is a correct solution
(as an extract cover) because of the subset of rows {2, 3}, and thus the reduced matrix:

0 1 1 0
1 0 0 1


has exactly one non-zero element in each column. By testing continuously, we can
find the full results of solutions for the matrix in (2.1) is:
{{1, 4, 5}, {2, 3}, {3, 5, 6}}.
2.2 GENERALIZED COVER
A generalized form of exact cover so-called generalized cover, is sometimes
more suitable to solve certain types of problems. In many cases, the problem
transformed to generalized cover form will be more convenient than the standard form

Extract Cover. Any generalized cover problem can be easily translated into an exact
cover problem by adding additional rows. The generalized cover problem divides the
matrix into two kinds of columns, i.e. primary columns and secondary columns, which
are subject to two different sets of constraints. Each primary column in the solution
must have exactly one non-zero element, as before. However, each secondary column
in the solution can have either zero or one non-zero element.
Let C
P
be the set of primary columns and C
S
the set of secondary columns in
matrix A and B. The subset of rows R
B
is an exact cover if both of the following
equations are satisfied
12



,

=1
= 1 




,

=1

1  



N-Queen problem (see Section 3.4.1) can be converted into Generalized Cover
problem. We can reduce the number of rows in the final matrix by creating a
secondary column for each diagonal on the chessboard. It means the level of matrix
will be smaller so the DLX algorithm will have to do less processing to find the
solutions that give us results in better performance. The DLX algorithm itself does not
require any modifications to solve generalized cover problems, but the matrix
construction procedure requires some minor adjustments (see Section 3.4.3).

Example:
To illustrate generalized cover problem, we review the four-queen puzzle. The
4×4 board will have four rows and four columns. Each of the four ranks (rows) and
four files (columns) on the chessboard corresponds to a primary column in the exact
cover matrix. Each of rank and file contains a maximum of only one queen post,
otherwise the queens would attack each other either horizontally or vertically at that
rank or file, so we can represent each row or column of the chessboard like a primary
column in the matrix. On the other hand, queen can also attack on the diagonal so each
diagonal (the diagonal from right to left, or diagonally from left to right) can contain
only a single queen post. However, the number of diagonals in the table is larger than
number of pieces, so there will be a diagonal line, which will not contain any queen.
So, the diagonal can be represented by secondary columns in the matrix of generalized
cover set. For example, 4 × 4 chessboard has 10 diagonals, so we will have 10
columns in the corresponding represented matrix. Therefore, our board size is 4 × 4 =
16 rows - corresponding to 16 queens’ positions, and 8 + 10 = 18 columns, including
columns from one to eight of the primary column, the columns from nine to eighteen
of the secondary column.
I can appreciate the convention in our matrix that columns from one to four

represent the ranks from 1-4 in the board, columns from five to eight show the
columns A - D in the board, eight columns from the set 1-8 are the primary columns.
On a 4 × 4 board, there are ten diagonals and if we ignore each of the four corners
diagonals, there is only a single square. The way each diagonal is numbered is not as
important as it is only needed to represent the problem and is not required to interpret
the final solutions. Therefore, the secondary columns from 9 to18 can represent 10
diagonal on the chessboard. So, in the matrix we have 16 rows, corresponding to 16
cell positions on the chessboard. Therefore, in the matrix we have 16 rows,
corresponding to 16 cell positions on the chessboard. Following the exact cover
definition the set U is the set of columns U = {1, 2, . . . , 18}. E is the collection of
rows where each set contains the column numbers with non-zero elements in that row.

E = {{1, 5, 16}, {1, 6, 9, 17}, {1, 7, 10, 18}, {1, 8, 11},
{2, 5, 9, 15}, {2, 6, 10, 16}, {2, 7, 11, 17}, {2, 8, 12, 18},
{3, 5, 10, 14}, {3, 6, 11, 15}, {3, 7, 12, 16}, {3, 8, 13, 17},
13

{4, 5, 11}, {4, 6, 12, 14}, {4, 7, 13, 15}, {4, 8, 16}}
After running the Dancing Links algorithm, the two results we obtain are two
generalized cover sets:
S1 = {{1, 7, 10, 18}, {2, 5, 9, 15}, {3, 8, 13, 17}, {4, 6, 12, 14}}
S2 = {{1, 6, 9, 17}, {2, 8, 12, 18}, {3, 5, 10, 14}, {4, 7, 13, 15}}
Figure 3 shows the board layout of the two solutions.

Figure 3 The two solutions S1 (left) and S2 (right) to the four4-queens problem
2.3 ALGORITHM X
Exact cover is a type of problem known to be NP-complete [9], there are
several algorithms for finding all solutions of the problem Extract Cover. One of the
simplest methods is a direct examination of all subsets to list out all the answers.
However, direct testing methods showed no effect when the file size increases, while

the number of subsets to be inspected will increase exponentially. Given a matrix with
m unique rows, the total number of subset to test would be 2m−1. The eight-queen
problem, which has a matrix consisting of 64 rows, gives an immense 18 446 744 073
709 551 615 sets, it is a huge number. Given that only 92 of these are valid solutions,
this simple algorithm can hardly be recommended. Although the power of electronic
computers today still follow Moore’s law, hardly can any computer find out the results
of the N-Queen problem at an acceptable time by means of direct examination in a
very far future. Another approach is that, the two scientists, Oana Muntean and Mihai
Oltean [10] also propose a device for optical resolution of some cases Extract Cover
problem, their idea is to harness the massive parallelism of light but the method is still
being under construction and unfinished.
There is a simple approach which is quite familiar with computer science is
algorithm X (X-Algorithm) [1]. Algorithm X is backtracking that uses a more
intelligent elimination method to “wriggle” its way through the matrix, remove
undesirable results and find all the solutions. Thus, the number of test reduced much.
For example, looking back at matrix (2.1) we can easily see that row 1 and 3 can never
be in the same set because they are in conflict with each other, both of them have a
non-zero element in the first column. That is the reason why it must be exactly one
non-zero element in each column, so we can remove any set containing both row 1 and
3.
14


Algorithm 1 Algorithm X recursive search procedure
1:
2:
3:
4:
5:
6:

7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure search(A,H)
if H is empty then
Print solution and return. {Base case for the recursion}
Choose a column c.
foreach row r such that a
r,c
= 1 do
Add r to partial solution.
Save state of matrix A and list H.
foreach column j such that a
r,j
= 1 do
foreach row i such that a
i,j
= 1, except i = r do
Delete row i from matrix A.
Delete column j from matrix A and list H.
Delete row r from matrix A.
search(A,H)
Restore state of matrix A and list H.
Remove r from the partial solution.


This above is algorithm X. Look at the algorithm, we can easily identify that
algorithm X uses similar logic to recursively traverse the search tree by backtracking.
Backtracking is the process of browsing and searching all the branches on the search
tree to determine that the leaf node is the final result of the problem. When a branch of
the tree does not meet the requirements of the problem, the algorithm will remo ve the
branch and backtrack and start searching the next available path in the tree. A
modified version of Algorithm X is presented in Algorithm 1. Changes are made to
improve the readability, logical consistency and to make it easier to compare with the
Dancing Links algorithm.
Algorithm X is initialized with the matrix A and the list of columns of the matrix
A, called the set H = {1, 2,…, n}, where n is the number of columns of the matrix A. If
the set H is empty, then we find a result of the problem, and the procedure ends.
Otherwise, the algorithm chooses a column c and loops through each row r, which has
a non-zero element in column c. Any conflict between row r and the remaining rows
will be detected and processed in the algorithm in lines 8-12. The algorithm continues
recursively called (line 13) with the new status of the matrix A and the list H.
Any rule of selecting columns in row 4 will produce all the solutions, but there
are some methods of selecting help making the number of browse branch of the
algorithm greatly reduced. In his article [1] Donald E. Knuth has proposed to find the
best column method (heuristic search), which is to always choose the column with the
least amount of non-zero elements. The approaches of the professor Knuth and
experimental results proved to work very well when the number of branches increased
to search, so it is a reasonable rule to make use of it in practice.
For example: Let us implement the algorithm X on a matrix of the previous (2.1)
example to better understand the mode of operation of the algorithm X. The columns
15

and rows have been numbered to make it easier to keep track of them when the matrix
is modified.







1 0 0 0
0 1 1 0
1 0 0 1
0 0 1 1
0 1 0 0
0 0 1 0







At the first step, we begin by choosing column 1. In column 1, we see only row 1
and 3 have a non-zero element in column 1. I select line 1 and put on the list of results.
Thus, the current result list is {1}. Row 1 only has one conflicting row, which is row 3,
which has a conflict in column 1. We delete column 1, row 1 and row 3, and the result
is as the following matrix:

1 1 0
0 1 1
1 0 0
0 1 0



At the second step, we choose column 2 and row 2 selected, the list of results is
{1, 2}. However, we noticed row 2 conflicts with all remaining rows, so after deleting
columns 2, row 2, 4, 5, 6, our matrix is empty while the H column list is not empty.
Therefore, the algorithm will recover the previous state of the matrix A and will
choose other branch of trees. At the next step, we select row fifth, its result is in the
partial solution {1, 5}. We see row 5 in conflict with row 2 in column 2, so we remove
the second column, row second, row 5, we get the following matrix:


1 1
1 0



Next, we select the columns 3 and row 4 and we put in the results list, the list of
results we are now {1, 5, 4}. Realize that row 4 conflicts with row 6, the row
remaining in the matrix. Therefore, after removing columns 3, row 4 and 6, the list H
is completely empty. This tells us that {1, 5, 4} is one of the solutions to this problem.
Recursive procedure will end and the results are printed.
Backtracking procedures continue to execute the one search tree until we find the
full results. Browsing and searching process is illustrated by the search tree (Figure 4).
Each node i, j, for row i and column j, indicates the choices made by the algorithm.
The rectangular node is where each of the solutions was found.
16


Figure 4 Algorithm X search tree for the example matrix
One issue when trying to implement Algorithm X is to save and restore the status
of the matrix A and H list multiple times during the backtrack process. Each time the

algorithm returns the old state; it must be restored before another path can be explored.
Otherwise, the process to find the non-zero elements on the matrix stored by two-
dimensional array will be very time consuming as well as much of storage space.
Therefore, Professor Donald E. Knuth suggested Dancing Links algorithm to solve the
above drawback of the algorithm X.
2.4 DACING LINKS ALGORITHM
Dancing Links algorithm is essentially the algorithm X. But thanks to organize
data efficiently and intelligently, Dancing Link algorithms inherited the strength of the
algorithm X, and at the same time overcome the disadvantages of X algorithm
performance as well as search storage space intermediate results.
2.4.1 DATA STRUCTURE
The method representing the matrix A by two-dimensional array is the main
cause to the limitations in terms of browsing speed as well as storage space of X. The
algorithm Dancing Links algorithm overcomes this drawback by performing a matrix
organization with adjacency matrices A. In the adjacency matrix, each non-zero value
in the matrix is represented by a node. The nodes are linked closely together with a list
of links double rotation. The advantage of the structure representing the matrix A by
the adjacency matrix is saving large amounts of memory space to store the state of the
matrix A because the number of zero elements usually outnumbers the non-zero
elements, especially when the matrix size increases. As an example the n-queens
17

problem for n = 10 has 396 non-zero elements, but they only account for 7.33% of the
total number of elements.
DLX is based on a simple, yet powerful technique, which allows one to reverse
any operation made to a doubly-linked list. If x is a component in double hook list, and
then x.left x.right will point to the element immediately before and immediately after
standing element x in the list. To remove element x from the list the following two
operations are applied:


x.right.left ← x.left
x.left.right ← x.right (2.3)

Applying these two operations to the linked list in Figure 5, the result is the list in
Figure 6. These operations modify the links pointing to element x so that an iteration
through the list will no longer traverse through this element, but instead of skipping
right past it.

Figure 5 Doubly-linked list

Figure 6 Doubly-linked list with element x removed
Because the link of element x to the elements before and after still hold, so if you
need to put x back to the list, the following two operations work as the inverse of the
operations in (2.3) by adding x back into the list.
x.right.left ← x
x.left.right ← x (2.4)

Thanks to the simplicity and convenience above, that the state archives and
restores the previous state of the matrix is very simple and effective. Thus, the
performance of the algorithm will increase substantially.
Each row and column in the matrix is represented by a separate list. Collection of
column headers is also stored in the list. Each element x in the linked list has six
attributes: x.left, x.right, x.up, x.down, x.column and x.row. X.row added new
attributes compared to the original algorithm of E. Knuth to provide the ability to
recognize position. The first four properties contain a pointer to the location of an
element in each list, x.right and x.left belong to a row list, x.down and x.up belong to a
column list. x.column is a pointer to the column headers, x.row is a non-negative
integer the column list containing the position of the element.
18


Each column header c has the additional c.name (name / number of columns) and
c.size (number of elements in the column). Secondary column headers used by the
generalized cover problem have their c.left and c.right attributes pointing to c (itself).
We define a special element h that acts as a root element of column headers of the
matrix. Given the nature characteristic of the links list, from the root node, we can
browse to any element of the matrix.
Figure 7 shows how the matrix in (2.1) can be represented using this data
structure.

Figure 7 Circular quad-linked list representation of the example matrix
2.4.2 ALGORITHM
In essence, the Dancing Links algorithm and algorithm X is absolutely identical.
The difference between the two algorithms is that the DLX algorithm uses a specific
intelligence data structure, along with methods to add and delete on a linked list to
maintain and restore the previous state of the matrix. Comparing Algorithm 1 and
Algorithm 2 reveals that they are very similar in nature.
Dancing Links algorithm implemented with a recursive function started with the
initial value k = 0 (recursion level 0) and a pointer to the header of the column of the
matrix h. The search result in a recursive step is the index of a row of the matrix
(determined by x.row). We will have a list O stored the set of results was found in a
recursive step. Printing a solution using the x.row attribute is done by printing O
i
.row
for all i  {1, 2, . . . , k}. When the algorithm encounters conditions stops (landmarks),
the result of branch search results is that O list. Then the algorithm will be called back
to continue search for results on other branches.
Column selection is done by using the S heuristic, which picks the column with
the lowest value for c.size. Algorithm 3 simply steps through each column header
looking for the lowest size.
19



The cover(c) and uncover(c) algorithms are the main differences between the
Dancing Links algorithm and Algorithm X. The aim of cover(c) is to remove the
column from the column headers from the list and resolve conflict in the column. To
remove the conflict, restore the status of the nodes in the list column, the cover and
uncover function we use modified method of connecting link as the cursor in the
formula (2.3) and (2.4).

Figure 8 The matrix before column A is covered
20


Figure 9 The matrix after column A has been covered.
The cover(c) algorithm also increments the value of updates which is used to
measure how many operations the search algorithm requires to complete. One update
equals four link modifications or one application of both the linked list removes and
adds operations. Attribute column header size is guaranteed by both cover and uncover
algorithm so that the best search algorithm based on the evaluation function can work
correctly. Algorithm 4 and 5 is cover procedures and uncover procedures. Note that
algorithm 5 goes up to the left of the list, while the algorithm 4 goes down and right. It
helps make sure that elements are placed back to back with the order is taken at. That
is the only way to all list places back in its original location.


21

Algorithm 2 Dancing Links recursive search
1:
2:

3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure search(k)
if h.right = h then
Print solution and return. {Base case for the
recursion}
c ← choose column()
cover(c)
foreach r ← c.down, c.down.down, . . . , while r ≠c do
O
k
← r
foreach j ← r.right, r.right.right, . . . , while j ≠ r do
cover(j.column)
search(k + 1)
foreach j ← r.left, r.left.left, . . . , while j ≠ r do
uncover(j.column)
uncover(c)

Algorithm 3 Column selection using the S heuristic
1:

2:
3:
4:
5:
6:
7:
function choose column()
s ← ∞
foreach j ← h.right, h.right.right, . . . , while j ≠ h do
if j.size < s then
c ← j
s ← j.size
return column c

Algorithm 4 Cover column c.
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure cover(c)
c.right.left ← c.left {Remove column c}
c.left.right ← c.right
foreach i ← c.down, c.down.down, . . . , while i ≠ c do
foreach j ← i.right, i.right.right, . . . , while j ≠ i do
j.down.up ← j.up {Remove element j}

j.up.down ← j.down
j.column.size ← j.column.size – 1
updates ← updates + 1


22

Algorithm 5 Uncover column c.
1:
2:
3:
4:
5:
6:
7:
8:
procedure uncover(c)
foreach i ← c.up, c.up.up . . . , while i ≠ c do
foreach j ← i.left, i.left.lseft, . . . , while j ≠ i do
j.column.size ← j.column.size + 1
j.down.up ← j {Add element j}
j.up.down ← j
c.right.left ← c {Add column c}
c.left.right ← c


23

CHAPTER 3: IMPLEMENTATION DETAILS


Distributed N-Queen Solver (DNS) has been implemented in the JAVA
programming language and the source code is available at
licensed under the GNU General Public
License version 3.
3.1 A BRIEF VIEW ABOUT JPPF PARALLEL COMPUTING FRAMEWORK
The Java Parallel Processing Framework (JPPF) [11] is an open-source cross-
platform tool set for controlling the execution of CPU-intensive tasks across multiple
execution nodes. JPPF enables applications that need huge processing power
requirements to run on any number of computers in order to significantly speed up
their execution. This is implemented by splitting an application into several smaller
parts so that they can be executed simultaneously on different machines. JPPF is
intended to use in the scientific data processing field. JPPF can be up and running in
minutes on any operating system or hardware platform. JPPF has an easy
programming model that abstracts the complexity of distributed and graphical user
interface tools for monitoring and administrating the reliability through redundancy,
recovery and failover capabilities and many programming and security features. Write
once, deploy once, and execute everywhere! That is also the reasons why I choose
JPPF to implement in my thesis.


Figure 10 JPPF network topology
24

Figure 10 show the structure of network topology of JPPF framework. Each
server can have several nodes connected to it. To achieve high scalability, system can
consist of many managers each of which will manage a small set of clients. Otherwise,
within network, one node (client) can communicate directly with other nodes or server.


Figure 11 JPPF Monitoring and Administration Tool


Figure 11 shows us the GUI tool for monitoring JPPF system. We can monitor
topology, job data, server stats, customize chart and some other features.

For more information about JPPF such as source code, binary distribution and
detail documentations for developing an application on JPPF framework, please visit
its homepage [11]
3.2 ARCHITECTURE DETAILS
All problems belong to Generalized Cover class that means the problems can be
converted to Generalized Cover problem and use common library Dancing Links to
find all results of Generalized Cover problem. The input of Dancing Links Library is a
generalized cover matrices and the output is a list of the rows of the matrix. For that
reason, for each problem, we need a transformation step to convert from initial input to
Generalized Cover matrix and a reversion convert from the results of the Dancing
Links algorithm (raw results) to the results we wish to search.
Architecture of the program without JPPF will include two layers, as shown
below in Figure 12. Those two layers are transforming library and calculating Dancing
Links library. Actually architectural model in Figure 12 is the general architecture of
all the problems in math class Generalized Cover.

×