Isomorphic Solutions of the N-queens Problem

ffi*,
a APr*offi2on
rttrift:

W*c.

'{Fr

A(:cq:'

Mergfl.t"rl

rssN 2089-1083
SNATIKA 20LL, Volume 01

DAFTAR ISI
Halaman

i*ffirnan Judul

1*& Fengantar

Srnnbutan Ketua STIKI

ilt

iv
v-ix

Dffiar lsi
i!!

lmplementasi Struktur Tree Untuk Pemodelan Sistem
lnformasi Bebantenan On-Line Dalam Upacara Yadnya

Anak Agung Kompiang
Oka Sudana, lda Ayu
Gde Kurnia Jayanti

Agama Hindu

ZainulArham


Evaluasi Kesesuaian Lahan Buah Pisang Kepok

1-6

Didasarkan Agroklimat Dengan Pendekatan Sistem
lnformasi Geografis
Mochamad Wahyudi,
Muanam

Rancangan Aplikasi Sistem lnformasi Keuangan Pada
Universitas Sains Dan Teknologi Jayapura (Ustj)

10-15

Mochamad Wahyudi,
Miwan Kurniawan
Hidayat

Rancangan Aplikasi Sistem lnformasi Manajemen Aset

Pada Universitas Sains Dan TeknologiJayapura (Ustj)

L7-21

Yusuf Durachman,

Pengembangan Framewerk Sisfo Kampus Berbasis Web
Menggunakan Metodologi Fast (Studi Kasus Stmik lij)

Arini, Ryan Sofyan
Nur Aeni Hidayah

Sistem tnformasi Studi Pelacakan Jejak Alumni (Tracer
Study) Program Studi Sistem lnformasi Fakultas Sains
Dan Teknologi (Studi Kasus : Uin Syarif Hidayatullah

29-33

Jakarta)


7

Nur Aeni Hidayah

Sistem lnformasi Penunjang Keputusan Penerimaan
Nasabah Pembiayaan Murabahah Menggunakan
ModelAhp (Studi Kasus : Bnisyariah)

34-39

Marson James
Budiman, Jufri

Klasifikasi Penilaian Kinerja Dosen Dengan
Menggunaka n Algoritma Backpropagation

39-44

HusniThamrin, Susilo
VeriYulianto,

Julpitriadi

Model Pengembangan Sistem lnformasi Pengelolaan
Pondok Pesantren Mahasiswa

45-51

10

Juni Nurma Sari,
Febriliyan Samopa

Pem

buatan Prototi pe Apli kasi Wi reless M enggu na ka n
TeknologiJava Pada Sistem lnformasi Akademik
Politeknik Caltex Riau

52-57


Ll

Puji Rahayu, Bandi
Ashari

Aplikasi Pengunduh Dan Pembaca Data NilaiJual Objek

58-53

Pajak (NJOP) Pada DirektoratJenderal Pajak

-,erra F. Palandi

Desain Sistem Toefl Untuk Membantu Persiapan Tes

64-70

Toefl

-*


Adaptasi Search Engine Yahoo Dan Google: Analisis
Diskriminan Dengan Pendekatan Technology
Acceptance Model (TAM) Dan Usability

71-78

Pengkajian Peraturan Bank lndonesia No 9lt5/PBl/20A7
Tahun 2007 Sebagai Pedoman Tata Kelola Teknologi
lnformasi (lT Governance) Bank Umum Di lndon'esia

79-83

Uji Bilangan Acak Dari Fungsi Pembangkit Bilangan Acak
Pada Bahasa Pemrograman Java

84-87

Ketut Agustini


Pengembangan Simulasi Binary Tree Berbasis CAI Untuk
Pembelajaran Matematika Diskrit

88-91

Sawalludin, Opim

lsomorphic Solutions Of The N-Queens Problem

92-97

T Evelina, Tias A.

mcbruv'ati

tsarnbang Hariyanto,

Hirin DuiiAgustin

loko Lianto Buliali,

Ahmad Saikhu

Salim Sitompul, Erna

Budhiarti Nababan
Eko Budi Cahyono,

Mochamad Hariadi

lnteraksi Gerak Tangan Alami Dengan Lingkungan
Augmented Reality Berbasis Metoda Projective

98-101

Reconstruction

1.9 Taufiq, Rahmadi

Penerapan Fuzzy Multi Criteria Decision Making
(Fmcdm) Untuk Pemilihan LokasiSpbu Pada Kota


102-108

Banjarbaru

20

Endah Purwanti

Logika Fuzzy Untuk Uji Kelayakan Lahan Singkong
Sebagai Bahan Baku Bioetanol

109-114

27

Jufri Wahyudi, Taufik
FuadiAbidin

Penentuan Secara Otomatis Akronim Dan Ekspansinya

Dari Data Teks Berbahasa lndonesia

115-119

22

Muhammad Ainur

120-124

Rony

Sistem Pakar Untuk Mengidentifikasi Kerusakan Kulkas
Lg Tlpe Gr-S512 Menggunakan Aplikasi Mobile

Galan Tri Suseno, lna

AplikasiSistem Pakar Untuk Diagnosa Penyakit Menular

125-130

Agustina, Firman
Anindra

Pada Kambing

24

Gunawan Putrodjojo

Aplikasi Multimedia Untuk Pembelajaran Berbasis
Simulasi Heuristik Dengan Konektifitas Scorm

131-138

25

lda Ayu Made

Pengembangan Aplikasi E-Learning Berbasis Model
Pembelajaran Kooperatif Tipe Tgt (Teams Game

L39-L44

23

Widiadnyani Pertiwi,
MadedWindu Antara

Tournament)

Kesiman, I Made Agus

Wirawan

VI

Isomorphic Solutions of the N-queens Problem

Isomorphic Solutions of the N-queens Problem
Sawaluddin1, Opim Salim Sitompul2, Erna Budhiarti Nababan3
1

University of Sumatera Utara, Dept. of Mathematics, Medan 20155, Indonesia
sawal@usu.ac.id
2
University of Sumatera Utara, Dept. of Mathematics, Medan 20155, Indonesia
opim@usu.ac.id
3
University of Sumatera Utara, Dept. of Information Technology, Medan 20155, Indonesia
ernabrn@usu.ac.id

Abstract. The N-queens problem is a classic

example in mathematics as well as computer
science that receives many attentions from
researches for nearly two centuries. Despite its
usefulness
in
teaching
computational
intelligence algorithms, another interesting
features of the N-queens problem is the notion
of isomorphism and transformation groups.
Once a solution of the N-queens problem is
found, the isomorphic solutions can be
transformed easily by performing two kinds of
permutations, i.e. rotation and reflection. In this
paper, we proposed a two-stage approach to
find the isomorphic solutions to the N-queens
problem. In the first stage, a genetic algorithm
is used to find a solution of the N-queens
problem. In the second stage, the solution is
transformed into seven isomorphic solutions.
Using this approach, a complete solution for
the N-queens problem can be obtained. The
results obtained show how the complete
isomorphic solutions of 5-, 6-, 7-, 8-, and 9queens can be generated in a very short
execution time.

that A={1,2, … , N } . Define B as the Cartesian
product of A, i.e., B= A × A . Then B = {(1,1),
(1,2), …, (2,1), …, (N,1), …, (N,N)}. Select N
elements of B and call this set as C. The set C
represents a solution to the problem if for the
Cartesian product of C = C ×C , each element
((i k , j k ),(i l , j l )) , either satisfies all of the
following conditions or fails all of them (for all l, k =
1, 2, …, N).
1.
2.
3.
4.

ik ≠ il {not on the same column}
jk ≠ jl {not on the same row}
ik + jk ≠ il + jl {not on the same diagonal}
ik - jk ≠ il - jl {not on the same diagonal}

As an example, Fig. 1 illustrates a solution of an 8queens problem. As can be seen from the figure, each
queen is located in different column and no queens are
located on the same rows or on the same diagonals.

Keyword: object-oriented approach, genetic algorithm,
N-queens problem, isomorphism.

1.

Introduction

The N-queens problem is a classic example in
mathematics as well as computer science that receives
many attentions from many researches for nearly two
centuries. For the last two decades and more recent
years, the N-queens problem has been solved using
some heuristic algorithms, especially genetic
algorithm (see for examples [1-7]). Despite its
usefulness in teaching computational intelligence
algorithms, another interesting features of the Nqueens problem is the notion of isomorphism and
transformation groups [8, 9]. The problem can be
stated algebraically by the following definition (as
adapted from [1]): Let A be the set of integers such

Fig. 1. Example of solution for the 8-queens
One of the many interesting features of the Nqueens problem is the notion of isomorphism of its
solutions. Among many of the solutions, we can
identify that several of them are isomorphic form of
the others. The isomorphic solutions can be obtained
from a current solution by means of permutation.
There are seven different permutations that can be
performed to obtain complete isomorphic solutions,
three of them are clock-wise rotations of 90 o, 180o,
and 270o. The other four permutations are reflections
of the horizontal middle axes, vertical middle axes,
left diagonal axes, and right diagonal axes (see Fig. 2).
SNATIKA 2011, ISSN 2089-1083 | 92

Isomorphic Solutions of the N-queens Problem

Fig. 2 Permutations of the original position
In this paper, we proposed a two-stage approach
to find the isomorphic solutions of the N-queens
problem. In the first stage, a genetic algorithm is
used to find a solution and in the second stage the
seven permutations are performed to the initial
solution in order to get the isomorphic solutions.
The structure of this paper is organized as
follows: in section 2 we briefly describe the
characteristics of the group of permutation in which
the N-queens problem is formulated. In section 3,
we describe the class data structure used by the
genetic algorithm to solve the problem. In section 4
we provides an overview of the genetic algorithm
approach used in this paper and discuss the
properties of the three main operations in the
genetic algorithm, i.e. selection, reproduction, and
mutation. Section 5 presents some results and
discusses the output obtained for several cases of N,
and finally in section 6 we will summarize the work
and present the conclusion.

2.

The N-queens problem of Group of
Permutations

In algebra, the solutions of the N-queens problem
are one example of a group of permutations that can
be represented as a group of symmetries of
geometric figures (symmetries of the squares) [10].
The set of transformations for N-queens is a
dihedral group Δ4, i.e. the group of symmetries of
the squares of 4 sides. Elements of the group can be
obtained by the operations of rotation R through
360o/4, and reflection M about some side [9, 10].
As a group of permutation, we can find among
the solutions of the problem that the permutation
operations are closed, has an identity element, has
an inverse, and associative. The closed properties
can be shown from the fact that a permutation of a
set C of the solutions of the N-queens problem is a
bijective function from a cartesian product of
C=C ×C . Thus, for a solution C0 = {(3,1),

(6,2), (8,3), (1,4), (4,5), (7,6), (5,7), (2,8)} of the 8queens, the permutation yields:
C1 = {(5,1),(1,2),(8,3),(4,4),(2,5),(7,6),(3,7),(6,8)}
(rotation 90o clockwise)
C2 = {(3,1),(6,2),(2,3),(5,4),(8,5),(1,6),(3,7),(6,8)}
(rotation 180o clockwise)
C3 = {(3,1),(6,2),(2,3),(7,4),(5,5),(1,6),(8,7),(4,8)}
(rotation 270o clockwise)
C4 = {(2,1),(5,2),(7,3),(4,4),(1,5),(8,6),(6,7),(3,8)}
(reflection on vertical axis)
C5 = {(6,1),(3,2),(1,3),(8,4),(5,5),(2,6),(4,7),(7,8)}
(reflection on horizontal axis)
C6 = {(4,1),(8,2),(1,3),(5,4),(7,5),(2,6),(6,7),(3,8)}
(reflection on left diagonal)
C7 = {(6,1),(3,2),(7,3),(2,4),(4,5),(8,6),(1,7),(5,8)}
(reflection on right diagonal)
The identity element is a special transformation,
namely a rotation of 0 o that doesn’t do anything.
The inverse element of the solutions is an act to
undo the transformation. In this case, the inverse
can be formed by taking the inverses of the
transformation in reverse order for any sequence of
rotation and mirror images. The associativity of the
transformation can be shown by composition
operation, such that the following equation holds:
(C1 ○ C2) ○ C3 = C1 ○ (C2 ○ C3) [11].

3.

The N-queens Class Data Structure

The class structure for the N-queens problem is
depicted in Fig. 3. The class consists of two
members, i.e. the variable and function members.

SNATIKA 2011, ISSN 2089-1083 | 93

Isomorphic Solutions of the N-queens Problem

the individual as well as the number of non
attacking queens and their fitness.

Fig. 3. The N-queens class structure
The member variable maintain a private
population list, which points to the head of an
orthogonal list used to store the population and the
individual data. The member function consists of
the operations necessary for the genetic algorithm
processing, namely creating an initial population,
calculating non attacking queen, calculating fitness
of each individual, and the three main operations of
genetic algorithm: random selection, reproduction,
and mutation.
The private variable member of the N-queens
class points to a structure consisting of two lists of
nodes representing a list of population which points
to a list of individuals. The two lists form an
orthogonal list as shown in Fig. 4, where the
horizontal lists are representing the individuals and
the vertical lists are representing the population.
Each node of the individual lists maintains the
column and row position information of the queen,
whereas each node of the population list maintains

Fig. 4. Orthogonal list of the N-queens data
structure
Each queen is placed into a fixed column
ranging from 1 to N. During the initial creation of
the individuals, the row position for each individual
node is generated randomly. Each column is
initialized with a number between 1 and N, showing
the row position of the queens. Fig. 5 shows an
example of the 8-queens problem with an initial
population of four individuals, where the rows are
positions of each queen in each column position of
1 to 8.

Fig. 5. An instance of an initial population with four individuals

4.

Overview of the Genetic Algorithm
Approach

The N-queens class has several public member
functions for the main operations of the genetic
algorithm. Function create initial population

performs the initialization of the population. After
the initial population has been populated with
individuals, then the non attacking queens are
calculated using the following simple rule:
• Two queens are attacking each other
whenever:
SNATIKA 2011, ISSN 2089-1083 | 94

Isomorphic Solutions of the N-queens Problem



Each queen located at the same
row
 Each queen located at the same
column
 Each queen located at the same
diagonal
For example, let X = Column and Y = Row. Two or
more queens located on the same row whenever Yi
= Yi+1 =… = Yj, where Yi and Yj are row positions of
the ith and jth queens. Furthermore, two or more
queens are located on the same diagonal if |Xi – Xj|
= |Yi – Yj|, where i, j = 1, 2, …, N. Location of
queens on the same column, however, can be
omitted since each queen will be placed on a
different column, labeled from 1 to N.
Function calculate fitness is then used to
calculate the fitness of each individual. The fitness
function is determined in the following steps:
• Determine the maximum number of nonattacking pairs of queens

where Qi is a queen located on row i and
A´ Qi is the number of non-attacking
queen for a queen located on row i.
The next three member functions of the class
are for the main operation of the genetic algorithm,
i.e. random selection, reproduction, and mutation.
The random selection function chooses a pair of
different individual from the population randomly.
Each pair of individuals is then undergoes a
reproduction process in which some genes from one
individual are exchanged with genes from another
individual. The crossover point is randomly chosen
from the positions in the strings of genes [11]. By
this means, two new individuals are reproduced
with combination of genes inherited from the two
parents. The reproduction step is illustrated in Fig.
7.

´ Q )= N ×( N −1)
max ( A
2
i



´ Q denotes the number nonwhere A
i
attacking queens and N is the number of
queens.
Calculate the number of attacking queens (
A Qi ), which located on the same rows
and/or the same diagonals. The queens are
attacking each other either directly or
indirectly. Fig. 6 illustrates the attacking
queens.

Fig. 7. Reproduction step with crossover point (c)
randomly chosen

The last process of the genetic algorithm is
mutation, where one or more genes from the new
created individual are altered into different genes.
The mutation point denoting which gene will
undergo the alteration is chosen randomly from the
string of genes of each new individual.

5.

Fig. 6. Attacking queens



Calculate the number of non-attacking
queens: max



A´ Q ) - A .
Q
¿

Result and Discussion

The genetic algorithm appoach is written using
GNU C/C++ and implemented on Intel CPU T2130
@1.86GHz, 2.0 GHz of RAM with GNU C/C++
running on Windows XP. In the first stage, a set of
data consisting of several chess board size are
tested by executing the program ten times for each
data set of certain chess board sizes. A complete
results obtained from the test for several number of
queens is shown in Table 1.

i

i

Calculate fitness:

Fitness ( Qi )=

´Q
A

i

N

∑ A´ Q

j

j=1

SNATIKA 2011, ISSN 2089-1083 | 95

Isomorphic Solutions of the N-queens Problem

Table 1. Results of ten times execution for several
number of queens
Ave
# of
Ave
Exec
Ave #
Queen Max
# of
Time
of
s
Gen #Pop Gen
(sec)
Exec
4 100
20
1.1
0
10.4
5
20
7.3 0.015625
1
6
20
42.8 0.078125
35.8
7
20
48.5 0.140625
7.9
8
20
48.7
0.125
92.8
9
20
60.5 0.203125 151.1
10 200
20 103.9 0.421875
92.2
11 300
20 155.6 0.640625 142.5
12
20 180.7 0.734375 311.7
13 400
20 230.1 1.078125 413.4
Table 1 shows some parameters that are used in
the program, namely the number of queens (# of
queens), maximum number of generations (Max
Gen), the number of population (#Pop), the average
number of generations (Ave # of Gen), the average
execution time (Ave Exec Time) in seconds, and the
average number of execution in order to obtain the
first solution (Ave # of Exec).
From the experiment performed, it was found
that the complexity of the program is increasing as

the number of the queens is increased. This fact can
be illustrated by the number of executions
performed in order to obtain the first solution, since
the solution is not always obtained in every
execution (see Fig. 8). The number of executions
are increasing exponentially as the number of
queens increases.

Fig. 8. Complexity of the problem as the number of
queens increases

As for the second stage, the program is executed
in order to obtain the isomorphis solutions for each
number of queens setup in the first stage. Results of
the execution for the number of Queens of 4, 5, 6,
7, and 8 can be seen in Fig. 9.

Fig. 9. Isomorphic solutions for several N-queens

SNATIKA 2011, ISSN 2089-1083 | 96

Isomorphic Solutions of the N-queens Problem

6.

Conclusion

Even though the N-queens problem is often
considered as a toy problem, the solution to this
problem is in fact a difficult one. The N-queens
problem is an instance of the contraint satisfaction
problem (CSP) that can be setup for classroom
demonstration purposes as an NP-complete
problem. The nature of isomorphic solutions of the
problem can also be used as a tool to teach student
about the concepts of isomorphism, transformation
groups, as well as equivalence classes.

References
[1]

[2]

[3]

[4]

[5]

Erbas, C., Sarkhesik, S., Tanik, M. M.:
Different
perspectives of the N-queens
problem. CSC ’92: Proc. of the 1992 ACM
Annual Conference on Communications, 99108 (1992)
Crawford, K.D.: Solving the N-queens
problem using genetic algorithm, SAC ’92:
Proc. Of the 1992 ACM/SIGAPP
Symposium on Applied Computing, 10391047 (1992)
Homaifar, A., Turner, J., Ali, S.: The Nqueens problem and genetic algorithm,
Proc. IEEE Southeastcon ’92, 262-267
(1992)
Bozikovic, A., Golub, M., Bodin, L.:
Solving N-queens problem using global
parallel genetic algorithm, The IEEE Reg. 8
EUROCON 2003, 104-107 (2003)
Bozinovski, A., Bozinovski, S.: N-queens
pattern generation: an insight into space
complexity of a backtracking algorithm,
Proc. of the 2004 International Symposium
on Information and Communication
Technologies (ISICT ’04), 281-286 (2004)

[6]

[7]

[8]

[9]

[10]
[11]

Martinjak, I.: Comparison of heuristic
algorithms for the N-Queen problem. Proc.
Of the ITI 2007 29th Int. Conf. on
Information Technology Interfaces, Cavtat,
Croatia, 759-764 (2007).
Turkey, A.M., Ahmad, M.S.: Using genetic
algorithm for solving N-queens problem.
Proc. of the 2010 International Symposium
in Information Technology (ITSim), Kuala
Lumpur, 745-747 (2010)
Eastridge, R., Schmidt, C.: Solving Nqueens with a genetic algorithm and its
usefulness in a computational intelligence
course. J. of Computing Sciences in
Colleges 23, 223-230 (2008)
Cull, P., Pandey, R.: Isomorphism and the Nqueens problem. SIGCSE Bulletin 26, 29-44
(1994)
Pinter, C.C.: A Book of Abstract Algebra.
McGraw-Hill: New York (1982)
Russel, S., Norvig, P.: Artificial Intelligence
A Modern Approach. 2nd Edition, Prentice
Hall: New Jersey (2003)

SNATIKA 2011, ISSN 2089-1083 | 97