0% found this document useful (0 votes)
62 views

Solving The N-Queens Problem Using A Tuned Hybrid Imperialist Competitive Algorithm

fffffff

Uploaded by

Warley Gramacho
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Solving The N-Queens Problem Using A Tuned Hybrid Imperialist Competitive Algorithm

fffffff

Uploaded by

Warley Gramacho
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

550 The International Arab Journal of Information Technology, Vol. 11, No.

6, November 2014

Solving the n-Queens Problem Using a Tuned


Hybrid Imperialist Competitive Algorithm
Ellips Masehian1, Hossein Akbaripour1, and Nasrin Mohabbati-Kalejahi2
1
Industrial Engineering Department, Tarbiat Modares University, Iran
2
Faculty of Industrial Engineering, Amirkabir University of Technology, Iran

Abstract: The n-queens problem is a classical combinatorial optimization problem which has been proved to be NP-hard. The
goal is to place n non-attacking queens on an n×n chessboard. In this paper, the Imperialist Competitive Algorithm (ICA),
which is a recent evolutionary metaheuristic method, has been applied for solving the n-queens problem. As another variation,
the ICA was combined with a local search method, resulting the Hybrid ICA (HICA). Since, the parameters of heuristic and
metaheuristic algorithms have a great influence on the performance of the search, parameter tuning is used for handling the
problems in an efficient manner. Hence, a TOPSIS-based parameters tuning is proposed, which not only considers the number
of Fitness Function Evaluations (FFE), but also aims to minimize the running time of the presented heuristics. In order to,
investigate the performance of the suggested approach, a computational analysis on the n-queens problem was performed.
Extensive experimental results showed that the proposed HICA outperformed the basic ICA in terms of average runtimes and
average number of FFE. The developed algorithms were also compared to the Cooperative PSO (CPSO) algorithm, which is
currently the best algorithm in the literature for finding the first valid solution to the n-queens problem, and the results showed
that the HICA dominates the CPSO by evaluating the fitness function fewer times.

Keywords: n-queens problem, ICA, local search, parameter tuning, TOPSIS method.

Received May 20, 2012; accepted May 13, 2013; published online March 13, 2014

1. Introduction There are three variants of the n-queens problem [1]:


Finding all solutions of a given n×n chessboard,
The n-queens problem is a classical combinatorial generating one or more, but not all solutions, and
optimization problem in Artificial Intelligence [7]. The finding only one valid solution. In the first variant,
objective of the problem is to place n non-attacking finding all solutions may be possible for small sizes,
queens on an n×n chessboard by considering the chess but the number of feasible solutions increases
rules. Although, the problem itself has an exponentially with the problem size, such that the
uncomplicated structure, it has been broadly utilized to largest instance solved to date is for n = 26 with a total
develop new intelligent problem solving approaches. number of 2.23×1016 solutions, calculated within 271
Despite the fact that the n-queens problem is often days on parallel supercomputers in [20]. A solution
studied as a ‘mathematical recreation’, it has found to the 8-queens problem (out of 92 solutions) is
several real-world applications such as practical task illustrated in Figure 1, with the permutation presented
scheduling and assignment, computer resource as (5, 1, 8, 4, 2, 7, 3, 6).
management (deadlock prevention and register
allocation), VLSI testing, traffic control,
communication system design, robot placement for
maximum sensor coverage, permutation problems,
parallel memory storage schemes, complete mapping
problems, constraint satisfaction, and other physics,
computer science and industrial applications [19]. The
variety of these applications indicates the reason of the
wide interest on this well-known problem.
The earliest paper on the general n-queens problem
was presented by Lionnet [14], and the first proof of Figure 1. A solution to the 8-queens problem.
the possibility of placing n non-attacking queens on an
n×n chessboard is credited to Pauls [17]. A thorough According to the extensive bibliography of n-queens
review on the problem and its applications is presented problems in [13] many mathematical and statistical
in [4]. The n-queens problem belongs to the class of techniques, heuristic and metaheuristic algorithms, both
Constraint Satisfaction Problems (CSP), and is known exact and approximate, have been proposed for solving
as an NP-hard problem [10]. the problem [7, 15, 18].
Solving the n-Queens Problem Using a Tuned Hybrid Imperialist Competitive Algorithm 551

The main advantage of metaheuristics compared to Function Evaluation (FFE) and runtime for solving the
exact methods is their ability in handling large-scale problem. Using the tuned parameters, HICA
instances in a reasonable time [23], but at the expense outperformed the original ICA in terms of average
of losing a guarantee for achieving the optimal runtimes and average number of FFE.
solution. Therefore, due to the NP-hardness of the n- The rest of the paper is organized as follows:
queens problem, metaheuristic techniques are Section 2 presents the basic ICA and its components
appropriate choices for solving it. for solving n-queens problem, section 3 presents the
In designing met heuristics two criteria are details of the HICA method, and section 4 provides
important that create two different classes of TOPSIS-based parameter tuning. The numerical results
algorithms: Exploitation (intensification) versus of Design of Experiments to find the best setting of
exploration (diversification) [21]. The first class is the alternative parameters, as well as comparison between
algorithms which are able to intensify the search in the performance of basic ICA and the suggested HICA
local regions. They are called Single-solution based for various sizes of the problem are presented in
metaheuristic (S- metaheuristic), and improve a single section 5. Finally, conclusions are in section 6.
solution in solving an optimization problem.
Population based metaheuristic (P-metaheuristic) are 2. The Basic Imperialist Competitive
the second class, which explore the search space and
introduce diversity in found solutions. Simulated
Algorithm
Annealing (SA) and Tabu Search (TS) are examples of The ICA was first introduced by Atashpaz-Gargari and
S-metaheuristic, and Genetic Algorithm (GA), Lucas [3] as an Evolutionary Computation method
Differential Evolution Algorithm (DEA) and Ant based on a social-political evolution. The ICA begins
Colony Optimization (ACO) are examples of P-met with generating an initial population of ‘countries’
heuristics, which have been used for solving n-queens (counterparts of chromosomes in GAs or particles in
problem in the literature. For instance, Homaifar et al. PSO). Then, according to a fitness function value,
[8] determined how well the operators of GA handled some of the best countries are determined as
very difficult combinatorial and constraint satisfaction ‘imperialists’, and remaining ones as the ‘colonies’ of
problems such as the n-queens problem. Results are these imperialists, which altogether form some
presented for n<200. Also, three metaheuristic ‘empires’.
algorithms (SA, TS and GA) are used to solve the n- Assimilation and Revolution are the two main
queens problem by Martinjak and Golub [15]. They operators of this algorithm: The colonies of each
presented test results and upper bound complexity for empire get closer to its imperialist by the assimilation
the problem. Many problem instances with large operator (a concept akin to the recombination operator
dimensions are solved and the efficiencies of in other evolutionary algorithms), and random changes
algorithms are compared. happen to the colonies according to the Revolution
Dirakkhunakon and Suansook [6] compare the operator (a concept akin to the mutation operator in
results of the classical SA algorithm with Iterative other evolutionary algorithms) which may modify the
Improvement Simulated Annealing (IISA) algorithm position of colonies in the search space. These
for the n-queens problem. The numerical results show operators may improve the solutions of the problem
that the modified scheme provides better results than and increase the power of the colonies to take the
the classical algorithm. Khan et al. [12] proposed a control of the empire. If so, they swap their positions
solution for the n-queens problem based on ACO. The with their imperialists.
proposed solution is applied to 8-queens problem and Imperialistic competition among these empires is
they supposed that it can very easily be extended to the another part of the ICA, which forms the basis of this
generalized form of the problem for large values of n. evolutionary algorithm. During this competition,
Their paper contains detailed discussion of the problem powerful empires survive and take possession of the
background and complexity, ACO and experimental colonies of weaker empires. This procedure eliminates
graphs. all the imperialists except for one, which yields the
In this paper, the Imperialist Competitive Algorithm final solution. The details of the algorithm’s steps
(ICA) evolutionary method developed in 2007 is tailored for the n-queens problem are described below.
applied for the first time to solve the third variant of
the n-queens problem, that is, to find the first 2.1. Generating Initial Empires
encountered valid solution. Also, the ICA was
combined with a local search, resulting in the Hybrid In the n-queens problem, each country is represented
ICA (HICA) method. Because heuristics are parameter by a solution encoded in the form of a permutation
sensitive for finding the best solution, a parameter [π(1), π(2),..., π(n)], in which the value of π(i) indicates
tuning approach based on the TOPSIS method is the row number and i specifies the column number of a
proposed to obtain the optimal set of parameters. It queen on the chessboard as shown in Figure 1.
follows two goals of reducing the number of Fitness Through this scheme, we can easily generate initial
552 The International Arab Journal of Information Technology, Vol. 11, No. 6, November 2014

solutions with no two queens on the same row or is produced by copying the substring into its
column, letting the conflicts occur merely along the corresponding position. Then, these selected elements
diagonals of the chessboard. are deleted from the Parent B (a colony). The resulting
The algorithm starts by producing a population of sequence contains the elements that the offspring
countries, which for the sake of improving the quality needs. The crossover is finished by placing the
of initial solutions, a large number of them are created remaining elements into the vacant positions of the
and then sorted in order of their objective function offspring from left to right, according to the order of
values to form the initial population with a desired their appearance in the Parent B. This procedure is
size. From this new list, a number (say N) of them with demonstrated in Figure 3.
the highest qualities are considered as imperialists, and
the remaining solutions are sequentially assigned to the Parent A: 8 7 2 5 1 4 6 3
imperialists as their colonies. In our problem the value Parent B: 2 5 8 7 4 1 3 6
Offspring: 2 8 7 5 1 4 3 6
of a solution is equal to the number of queen attacks
(conflicts) and so lower values mean higher quality. Figure 3. OX operator illustration.
As an example, assuming that the sorted initial
population of size 16 with N = 3 imperialists is: [1, 2, Regardless of the type of applied crossover, the next
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], the generation will be selected from the best solutions of
resulting three empires with their imperialists shown in the pool, with the size of the population maintained.
bold will be {[1, 4, 7, 10, 13, 16]; [2, 5, 8, 11, 14]; [3,
6, 9, 12, 15]}. 2.3. Revolution Within an Empire
The Revolution operator brings about radical changes
2.2. Assimilation Within an Empire in a colony in hope for a better fitness value and also
In the real political world, imperialists try to promote diversifying the population. This unary operator is
the life standards of their colonies by assimilating and applied to colonies with a constant rate Revolution
absorbing them. In the ICA, this fact is simulated by Rate (RR) and acts like the mutation operator in GAs.
moving each colony toward its respective imperialist. In our method the Revolution operator is
For the assimilation phase, we have utilized two types implemented by randomly swapping the values of
of Crossover operators: The Partially Matched chromosomes at one or two positions. The colony is
Crossover (PMX) and Order Crossover (OX). updated if a better fitness value is obtained. Figure 4
In PMX operator, two genotypes (solution shows an example of this operator for the 8-queens
encodings) are selected as parents, and two crossover problem.
positions are picked randomly along the solutions.
Then, all chromosomes of Parent A lying between Colony (state 0): 8 7 2 5 1 4 6 3
Colony (state 1): 8 7 3 5 1 4 6 2
these two points are exchanged with the chromosomes
of Parent B at the same positions, and vice versa. Figure 4: An example of the revolution operator.
For example, for the 8-queens strings in Figure 2,
taking the Parents A and B, the two crossover limits 2.4. Power Struggle
are fixed at 4th and 6th positions, and the dark area
indicates the pairs which must undergo exchange. As a While moving toward the imperialist, a colony may
result, in both parents, the following swaps take place: achieve a position with lower cost (or equivalently,
7↔4, 3↔1, and 8↔2, which create two new children. higher power) than its imperialist. In such a case, the
Now, in our method, the first parent is permanently imperialist will be toppled and superseded by that
assumed to be the imperialist solution, and the second colony. The colony becomes the new imperialist
parent rotates among all colonies. Thus, the generated starting from the next iteration. This act is similar to
offspring will somewhat inherit the nature and power shifting the best global experience (gbest) in the swarm
of their imperialist parent, which can be interpreted as from a particle to another particle in the PSO method.
a kind of assimilation.
2.5. Imperialistic Competition
Parent A: 2 4 6 7 3 8 5 1
Parent B: 8 5 3 4 1 2 7 6
Through the imperialistic competition step, weaker
empires lose their power further by losing their
Child 1: 8 7 6 4 1 2 5 3 colonies, and powerful empires become more powerful
Child 2: 2 5 1 7 3 8 4 6
by owning new colonies.
Figure 2. An example of parents and children in the PMX. The total power of an empire is calculated by adding
the power (i.e., fitness function value) of the
In the OX method, one offspring is generated from imperialist country to a percentage of the mean power
two parents. First a substring from the Parent A (which of its colonies. Mathematically:
is an imperialist) is selected randomly and an offspring
Solving the n-Queens Problem Using a Tuned Hybrid Imperialist Competitive Algorithm 553

ξ ni ability. This local search is applied on a solution to


P(E i ) = P(I i ) + ∑ P(C i j ) (1)
ni j =1 improve it as much as possible (i.e., until reaching a
local optimum) through a neighborhood generation and
in which P(Ei) is the power of Empire i, P(Ii) is the selection procedure.
j
power of the Imperialist country of Empire i, P(C i) is A common method for generating neighbors of a
the power of the j-th colony of Empire i, ni is the given solution is Random Swap, which exchanges the
number of colonies in Empire i, and 0 < ξ < 1 is a places of two randomly-selected queens. This action
constant determining the importance and impact of the may or may not decrease the number of conflicts
colonies in each empire. We found ξ = 0.1 a proper among queens. So, to make the neighborhood
value as suggested by Nazari-Shirkouhi et al. [16]. generation more goal-directed, we propose a new
For a minimization problem, the normalized total variant of the swap operator, called Effective Swap,
which acts more intelligently than the Random Swap
power of Empire i is obtained by subtracting the lowest
since, it selects the exchange rows by also considering
power among all empires from its power, as in the number of attacks rather than just choosing them
Equation 2. Note that a high power corresponds to a randomly. The following details illustrate the function
low cost: of this new operator.
{
N P(E i ) = P(E i ) - min P(E i )
i
} (2) The Effective Swap operator starts with counting
the number of conflicts on the main diagonal of the
Thus, the normalized total power of the weakest chessboard. If this number is nonzero, it marks that
empire will be zero, and for others, a positive value. diagonal for further operations. Otherwise, it proceeds
The Possession Probability (PP) of each Empire is with the sub diagonals immediately above and below
based on its total power and should be calculated at the the main diagonal. Conflict counting is repeated for
start of the imperialistic competition step, according to these diagonals too, and if no conflicts are found, it
Equation 3, in which N is the total number of empires: proceeds with farther sub diagonals parallel to the main
diagonal. In case that still no conflicts are identified,
NP(E i )
PPi =
N (3) the above procedure is repeated for the secondary
∑ NP(E ) diagonal and its parallel sub diagonals until a
j =1 j

conflicting diagonal is found and marked for further


The PP is used to update the distribution of the operations.
colonies among the empires. For each empire i, by Next, suppose that the marked diagonal has m
subtracting a uniform random number randi ∈ U(0, 1) conflicts. Then, the operator performs m-1 Random
from its PPi, a new vector is formed, defined as: Swaps, such that in each swap, one of the queens is
D = [PP1 − rand1, PP2 − rand2, ..., PPN − randN] (4) selected from the conflicting queens, and the other is a
randomly-selected queen not causing any conflict in
In the vector D, the empire that has the least value the marked diagonal. It is worthy to note that
among others loses its weakest colony, which is performing an Effective Swap does not guarantee an
reassigned to the most powerful empire. improvement in the fitness function; however, as
The Assimilation, Revolution, and Imperialistic indicated by our extensive experiments it reduces the
Competition steps are repeated until the weakest number of conflicts far better than the Random Swap
empire loses all of its colonies, in which case it is operator.
discarded and its imperialist becomes a colony of the As an example of Effective Swap, consider a
most powerful empire. configuration of 8-queens displayed in Figure 5-a,
In our n-queens problem, the stopping criterion is where there are m=2 conflicting queens on the marked
satisfied when there are no conflicts (attacks) among main diagonal, namely π(1) and π(8), of which one
the queens. queen is selected randomly, e.g., π(8). Now, another
queen which does not cause conflicts in this diagonal is
3. The Hybrid ICA randomly selected, e.g., π(7), and the selected rows are
swapped by π(7) ↔ π(8), as shown in Figure 5-b.
As described earlier, the ICA utilizes random numbers After applying an Effective Swap, a neighbor
in almost all of its steps: Initial population creation, solution is generated, and we check whether any
assimilation, revolution, and imperialistic competition. improvement has occurred in the fitness function or
This randomness can be quite effective in diversifying not. If yes, then this neighbor solution is kept;
the solutions and adequately exploring the search otherwise, a new one is generated. This procedure
space. However, we noticed that this fact weakens the iterates until a stopping criterion is satisfied.
algorithm’s ability to intensify its search around a good The stopping criterion contains a parameter T to
solution, which leads to a slow convergence to a control the depth of the local search, set by:
suboptimal solution.
As a result, we decided to add a local search T=k·n (5)
component to the ICA and reinforce its intensification
554 The International Arab Journal of Information Technology, Vol. 11, No. 6, November 2014

Begin

Initialize the empires

Move the colonies to their relevant


imperialist

I =1

a) Before applying the Effective b) After applying the Effective


Swap on the chessboard. Swap on the chessboard. S = Country (I)
Figure 5. Applying an effective swap as a neighborhood generation
method.
Substitute S with its best neighbor S′ using the
Effective Swap and repeat until T < Tmin
Where k is a constant and n is the size of the problem.
After each iteration of the local search, the value of T
is updated by:
Is the cost of S′ = 0?
T = 0.99 · T (6) Yes
No
The local search procedure iterates until T reaches a
lower bound like Tmin. On the other hand, the n-queens I =I +1
problem has multiple optimal solutions (with a fitness
function value of zero, meaning no conflicts), and the Yes
I ≤ Pop_size
number of these solutions increases exponentially as n
grows. Therefore, if the local search is given more time No
to transform an initial solution, it can converge to an
optimal solution much faster. For this purpose,
Is there a colony in an empire that
whenever the newly generated neighbor causes an dominates its imperialist?
improvement in the fitness function value, a rewarding
No
mechanism is enforced to update the T by: Yes
T = 1.01 · T (7)
Exchange the positions of that colony
Output
and the imperialist
Note that, the 1.01 coefficient delays the convergence
and causes the search to deeply exploit seemingly good
solutions. As a result, such a dynamic definition of T Compute the total cost of all empires
causes an effective search of the space, as the
algorithm spends more time on exploring an
Pick the weakest colony from the weakest empire and
appropriate solution, and less time on non-promising give it to the strongest empire
ones.
We name the ICA with the abovementioned local
No
search procedure as “HICA”. Figure 6 shows the Is there an empire with no
colonies?
flowchart of the HICA.
The HICA has another advantage over the basic Yes
ICA: As noticed in Equation 4, the empire having the Eliminate this empire
largest value in the vector D will possess the weakest
colony of the weakest empire. On the other hand, we Unite similar empires
know that the most powerful empire (e.g., E*) has the
largest PP index calculated in Equation 3. But, since No
Stopping condition
the vector D is obtained by subtracting random satisfied?
numbers from the PPi indices, there is no guarantee
that the E* will still be selected for accommodating the Yes

weakest colony.
Figure 6. Flowchart of the HICA.
Although, we used the Equation 4 for our basic ICA
to keep the authenticity of the algorithm presented by
Atashpaz-Gargari and Lucas [3] we discarded the 4. Parameter Tuning
random number subtraction in Equation 4 in the HICA As stated before, the parameters of metaheuristic
and used the following vector D instead: algorithms have a significant effect on the efficiency
D = [PP1, PP2, ..., PPN] (8) and effectiveness of the search for a particular
problem. There may be many options for these factors
Solving the n-Queens Problem Using a Tuned Hybrid Imperialist Competitive Algorithm 555

for a given problem. Therefore, using an appropriate c. Multiplying the Performance Matrix by its Related
approach like parameter tuning in order to find the best Weights: Each column of the matrix P is multiplied
choice from many alternatives can produce better by weights associated with each objective FFE
solutions for the given problem. In this section, some (wFFE) and runtime (wT). The weighted
levels of the parameters for the ICA and HICA are performance matrix V is obtained as follows:
introduced. There are two goals in solving the n-
 w FFE p11 w T p12   v 11 v 12 
queens problem by the proposed algorithms: Reducing w p w T p 22  v v 22 
the number of FFE and reducing the runtime. The V =  FFE 21  =  21  (11)
TOPSIS method is used to cope with both objectives at  ... ...
  ... ... 
w FFE p m1 w T p m2  v m1 v m2 
the same time. Finally, the results of the TOPSIS-based
parameter tuning are displayed for both algorithms. in which vij represents the weighted normalized
performance of Ri with respect to Xj for i = 1, 2, …,
m and j = 1, 2.
4.1. Parameters Levels in ICA
d. Determination of Ideal and Negative-Ideal
Four factors are considered as the most important Solutions: The ideal value set V+ and the negative-
parameters in the two algorithms. The first is the initial ideal value set V− are determined in Equations 12
population which is randomly generated and then 10 and 13 for minimizing both objectives
solutions are considered as initial solutions, divided simultaneously, in which J′ = { j = 1, 2 | vij, a smaller
into empires and colonies. It’s possible levels are {100, response is desired}:
300}. The second is the crossover type in two levels
{PMX, OX}. Third is the RR presented in four levels
{0.3, 0.4, 0.5, 0.6}, and the fourth parameter (k) is
V {( minv ij | j ∈ J ′) , i = 1, 2,..., m } = {v 1+ ,v +2 }
+
= (12)

V = {( maxv ij | j ∈ J ′ ) , i = 1, 2,..., m } = {v 1 ,v 2 }
used only in the HICA with the levels {1, 5, 10, 20}. - - - (13)

4.2. TOPSIS e. Calculation of Separation Measures: The separation


+
Hwang and Yoon [9] developed the TOPSIS to assess of each alternative from the ideal solution (Si ), as
alternatives prior to multiple-attribute decision making. well as the separation of −each alternative from the
In the TOPSIS, the distance to the ideal solution and negative-ideal solution (Si ) is given as follows:
negative-ideal solution according to each alternative is
( ) ( )
2 2
+
Si =
2 +
∑ v ij − v j , −
Si =
2 −
∑ v ij − v j (14)
considered, and then the best alternative is selected j =1 j =1

which is the nearest one to the ideal solution and the


farthest one from the negative-ideal solution. The f. Calculation of Relative Closeness to the Ideal
TOPSIS structure for aggregating the more important Solution and Ranking the Preference Order: The
objectives in solving the n-queens problem can be relative closeness Ci to the ideal solution can be
explained as follows [22]: expressed as follows:

Si
a. Alternative Performance Matrix Creation: The Ci = + − (15)
structure of the alternative performance matrix can Si + Si

be expressed as follows:
Where Ci lies between 0 and 1. The closer Ci is to 1,
FFE Runtime the higher is the priority of the i-th run experiment.
R1  x 11 x 21  Because of the multiple levels of each parameter, is
R2  x x 22  C calculated as the mean of relative closeness to the
D =  12  (9) i

...  ... ...  ideal solution for each parameter per level.
R m  x 1m x 2 m  Numerical results of using the TOPSIS for the n-
queens problem with tuned parameter are presented
In the proposed problem, the number of FFE and in the next section.
runtime are the objectives (Xj, j = 1, 2) which are
related to alternative performances. Possible
alternatives (run experiments) are denoted as Ri, i = 1, 5. Experimental Results
..., m; and xij is the performance of Ri with respect to It is clear from the Table 1 that the first two parameters
the objective Xj. have 2 levels and last two factors have 4 levels. Thus, it
b. Normalization of the Performance Matrix: For this is required 2 × 2 × 4 × 4 = 64 experiments for the full
purpose, the transformation Equation 10 is used, in factorial design. But, considering the computational cost
which pij represents the normalized performance of and time and based on statistical theories, there is no
Ri with respect to the objective Xj. The matrix form need to test all the combinations of factors. Therefore,
of pij is represented as P, with i = 1, 2, ..., m and j =
the Taguchi method is used to design the experiments.
1, 2.
The number of degrees of freedom should be calculated
x ij
P =  p ij  , pij =
in order to, select an appropriate Taguchi orthogonal
  2 (10)
∑im=1 x ij array. By considering 1 degree of freedom for the first
556 The International Arab Journal of Information Technology, Vol. 11, No. 6, November 2014

two parameters, 3 degrees of freedom for the last two Table 2. Average results of 10 runs of the ICA for various sizes of
factors and 1 degree of freedom for the total mean, there the n-queens problem.
should be at least (2 × 1) + (2 × 3) + 1 = 9 experimental n
FFE
NCCA
Runtime (s)
Min Max Avg. Avg. SD
runs. As a result, L16 (22 × 42) is chosen as the orthogonal
8 17 330 159 0.36 0.05 0.06
array. The relative closeness to the ideal solution (Ci) 10 150 2315 785 2.17 0.14 0.13
are calculated for each experiment as Table 1. 25 1550 10880 6500 5.40 2.15 1.06
50 12215 116150 4402 10.95 26.48 17.43
Table 1. Taguchi orthogonal array L16 (22 × 42).
100 105870 542720 280014 22.28 348.51 162.39
Initial Crossover Mutation 200 1022990 1882564 1558751 50.15 3284.22 303.54
No. k Ci
Population Size Type Rate 300 2754111 4258966 3859979 143.51 21650.58 573.81
1 1 1 1 1 0.89
2 1 1 1 2 0.61 Table 3. Average results of 10 runs of the HICA for various sizes
3 2 2 1 3 0.31 of the n-queens problem.
4 2 2 1 4 0.00
5 1 2 2 1 0.88 FFE Runtime (s)
n NCCA
6 1 2 2 2 0.45 Min Max Avg. Avg. SD
7 2 1 2 3 0.31 8 0 445 96.3 2.20 0.05 0.05
8 2 1 2 4 0.40
10 21 940 408.3 11.33 0.14 0.11
9 2 1 3 1 1.00
10 2 1 3 2 0.69 30 184 5038 1657.6 13.74 0.67 0.62
11 1 2 3 3 0.41 50 323 5882 2327.6 11.61 1.20 1.03
12 1 2 3 4 0.24 75 525 5708 2265.2 11.21 1.28 0.88
13 2 2 4 1 0.77 100 1374 7006 2932.7 8.81 1.98 1.29
14 2 2 4 2 0.56
15 1 1 4 3 0.38 200 6060 9405 8893.6 13.70 9.38 1.10
16 1 1 4 4 0.40 300 10805 14624 12302.6 12.79 19.60 2.74
C 1 =0.60 C 1 =0.89 500 13717 24906 20962.4 16.47 148.74 29.82
C 1 =0.53 C 1 =0.58 C 2 =0.62 C 2 =0.58 750 23279 42164 33767.5 13.65 616.17 254.26
C 1000 31701 74877 43272.4 15.80 984.13 301.12
C 2 =0.51 C 2 =0.48 C 3 =0.59 C 3 =0.35
2000 79984 101571 89827.1 21.93 7023.87 545.54
C 4 =0.53 C 4 =0.26
150
n=50
For choosing the best level of each parameter, we n=100
n=200

should find the Ci that is closer to 1. As can be inferred n=300

from the Table 1, the parameters of the algorithms


Number of conflicts

100
were set as follows: Initial population size = 100,
Crossover type = PMX, RR = 0.4 and k = 1 (in (5)).
The algorithms with tuned parameters were coded in
Matlab® and run on an Intel™ Core i7 2.00 GHz CPU 50

with 4.00 GB of RAM.


Tables 2 and 3 show the experimental results of
solving the n-queens problem at different sizes. 0

Considering the randomness of the methods, each 0 1000 2000 3000 4000
Number of iterations
5000 6000 7000

Number of iterations
instance was run 10 times, and the mean and the
Figure 7. Convergence curves for the ICA run on n = 50, 100, 200,
Standard Deviation (SD) of runtimes and two other and 300 queens.
performance criteria, the FFE and Normalized
Convergence Curve Area (NCCA), are reported. Inspired by the behavior of the convergence curve,
The FFE criterion measures the total number of FFE we designed a new performance criterion to compare
during the whole search, and NCCA. The convergence the basic and HICA methods: The NCCA. In fact, by
curve plots the best-found fitness function value at each calculating the area under a convergence cure we can
iteration, until the final solution is reached. In the n- infer how fast a method reduces the number of
queens problem, this curve shows how the algorithm conflicts. A relatively small area implies that the
reduces the number of conflicts during its execution till algorithm succeeded in reducing the number of
it becomes zero. Figure 7 shows convergence curves of conflicts at its early iterations. The NCCA measures
the ICA for various sizes of the problem: n = 50, 100, the area under the convergence curve with the number
200 and 300. The number of conflicts and iterations are of conflicts plotted along the vertical axis and the
displayed along the vertical and horizontal axes, number of FFE along the horizontal axis; but since for
respectively. As can be seen, initial numbers of large problem sizes the area becomes too large, we
conflicts were about half the sizes of the problems, and divided it to a factor of n2 and eliminated the impact of
larger problems took much more iterations to converge problem size, obtaining a normalized value.
than smaller instances. Table 2 shows that the ICA spent about 6 hours of
computation averagely for the 300-queens problem,
Solving the n-Queens Problem Using a Tuned Hybrid Imperialist Competitive Algorithm 557

and so we stopped solving larger instances. On the [15] and outperformed all those met heuristics in terms
other hand, the HICA performed surprisingly well and of the number of FFE. The results of average FFE
could find a solution to the 2000-queens problem in values obtained by our proposed HICA and the CPSO
less than 2 hours. The number of FFE in the HICA algorithms are reported in Table 4 and plotted in
method was also significantly less than that of the Figure 9. It was observed that the HICA always
basic ICA method. For the NCCA criterion the evaluated the fitness function fewer times than the
behaviors are a bit different: For small sizes the ICA CPSO.
converges to a low number of conflicts faster than the
powerful HICA method, but then for n > 100 the HICA Table 4. Average number of FFEs for HICA and CPSO.
regains its superiority (with smaller NCCA index). n HICA CPSO Improvement (%)
This fact is due to the impact of the implemented local 8 96.3 225.8 57.4
search on the algorithm’s speed. 10 408.3 540.5 24.5
Figure 8 illustrates the superimposed convergences 30 1657.6 2020.5 18.0
of the two algorithms, which are plotted for n = 100 by 50 2327.6 2764.2 15.8
75 2265.2 3661.6 38.1
considering the best run in terms of convergence speed 100 2932.7 5063.6 42.1
out of 10 runs. Note, that here the horizontal axis 200 8893.6 9184.5 3.2
shows the number of FFE’s (and not iterations) since 300 12302.6 14559.6 15.5
the local search component in the HICA executes some 500 20962.4 23799.6 11.9
additional iterations which should not be compared to 750 33767.5 34765.2 2.9
the main iterations of ICA. 1000 43272.4 47299.8 8.5
2000 89827.1 95235.9 5.7
50
HICA (NCCA=0.86)

45
ICA (NCCA=1.12) 100000
90000
40
80000
Number of conflicts

35
70000
30 60000
25
50000
40000
20
30000
15
20000
10 10000
5 0
0
8 10 30 50 75 100 200 300 500 750 1000 2000
0 100 200 300 400 500 600 700 800 900
Number of Fitness Function Evaluations (FFE)
Number of Fitness Function Evaluation (FFE) HICA CPSO
Figure 8. A comparison of convergence curves for basic and hybrid Figure 9. Comparison of the number of FFE versus the problem size
ICAs on n = 100 queens. for the HICA and CPSO methods.

5.1. Comparisons
6. Conclusions
In order to evaluate the efficiency of the presented
In this paper the ICA, which is a recent evolutionary
HICA method, we compared it with an algorithm that
method, is used for finding the first encountered
had produced the best known results in finding the first solution to the n-queens problem. For improving the
solution to the n-queens problem. This method is called performance of the algorithm a local search is
Cooperative PSO (CPSO) and is introduced in [2] for incorporated into the algorithm, which we call HICA.
solving permutation problems, including the n-queens Due to the effect of the initial factors of metaheuristic
problem. Compared to the PSO method [11], the CPSO on effectiveness of the algorithms, TOPSIS-based
uses parallel searching to reduce calculation time. parameter tuning is proposed to select the best set of
For solving the n-queens problem by using the parameters for the algorithm. Experimental result
CPSO, an initial random population of particles is showed that the HICA is able to find the solution for a
generated, where each particle has initial information given number of queens faster than the basic ICA and
about the locations of n-queens on an n × n chessboard. can solve large instances through smaller numbers of
Each particle of the population is divided into n equal FFE. The HICA was also compared to the best
sub-swarms, and then each sub-swarm is changed into algorithm in the literature for solving this specific
one sub-particle. Sub-particles use the standard PSO to problem (i.e., CPSO), and outperformed it in terms of
update their velocities and positions according to the the number of FFE.
best local experience of each sub-particle and the best As a future work, the RR can be considered as an
position for each particle among all particles. adaptive parameter such that in initial iterations it takes
Through a number of experiments, Amooshahi et al. a relatively large value and decreases as the search
proceeds. The decreasing rate would be dynamic and
[2] compared the CPSO with implementations of
would depend on some information obtained from the
standard PSO, SA, TS and GA algorithms reported in
558 The International Arab Journal of Information Technology, Vol. 11, No. 6, November 2014

course of the search. As a result, more diversification San Francisco, USA, vol. 3, pp. 1526-1531,
of solutions in the earlier iterations can be expected, 1993.
which may lead to faster convergence. Another [11] Kennedy J. and Eberhart R., “Particle Swarm
enhancement could be performing a landscape analysis Optimization,” in Proceedings of IEEE
for the n-queens problem, which probably can explain International Conference on Neural Networks,
the reason of the significant improvement caused by Perth, Australia, vol. 4, pp. 1942-1948, 1995.
hybridizing the ICA with a simple local search [12] Khan S., Bilal M., Sharif M., Sajid M., and Baig
compared to the basic ICA. R., “Solution of n-Queen Problem Using ACO,”
in Proceedings of the 13th IEEE International
References Multi-Topic Conference, Islamabad, Pakistan, pp.
[1] Abramson B. and Yung M., “Divide and Conquer 1-5, 2009.
under Global Constraints: A Solution to the n- [13] Kosters W., “n-Queens Bibliography,” available
at: http://www.liacs.nl/~kosters/ nqueens/, last
Queens Problem,” Journal of Parallel and
Distributed Computing, vol. 6, no. 3, pp. 649- visited 2012.
662, 1989. [14] Lionnet F., NouvellesAnnales de Mathématiques,
[2] Amooshahi A., Joudaki M., Imani M., and available at : http://archive.numdam.org/
Mazhari N., “Presenting a New Method Based on ARCHIVE/NAM/NAM_1869_2_8_/NAM_1869
Cooperative PSO to Solve Permutation _2_8__529_0/NAM_1869_2_8__529_0.pdf, last
Problems: A Case Study of n-Queen Problem,” in visited1869.
Proceedings of the 3rd International Conference [15] Martinjak I. and Golub M., “Comparison of
on Electronics Computer Technology, Heuristic Algorithms for the n-Queen Problem,”
Kanyakumari, India, vol. 4, pp. 218-222, 2011. in Proceedings of the 29th International.
[3] Atashpaz-Gargari E. and Lucas C., “Imperialist Conference on Information Technology
Competitive Algorithm: An Algorithm for Interfaces, Cavtat, Croatia, pp. 759-764, 2007.
Optimization Inspired by Imperialistic [16] Nazari-Shirkouhi S., Eivazy H., Ghodsi R.,
Competition,” in Proceedings of IEEE Congress Rezaie K., and Atashpaz-Gargari E., “Solving the
on Evolutionary Computation, Singapore, pp. Integrated Product Mix-Outsourcing Problem
4661-4667, 2007. Using the Imperialist Competitive Algorithm,”
[4] Bell J. and Stevens B., “A Survey of Known Expert Systems with Applications: An
Results and Research Areas for n-Queens,” International Journal, vol. 37, no. 12, pp. 7615-
Discrete Mathematics, vol. 309, no. 1, pp. 1-31, 7626, 2010.
2009. [17] Pauls E., “Das Maximalproblem Der Damen Auf
[5] Campos V., Laguna M., and Mart R., “Context- Dem Schachbrete, II, Deutsche Schachzeitung,”
Independent Scatter Search and Tabu Search for Organ fur das Gesammte Schachleben, vol. 29,
no. 9, pp. 257-267, 1874.
Permutation Problems,” INFORMS Journal on
Computing, vol. 17, no. 1, pp. 111-122, 2005. [18] Rivin I. and Zabih R., “A Dynamic Programming
[6] Dirakkhunakon S. and Suansook Y., “Simulated Solution to the n-Queens Problem,” Information
Annealing with Iterative Improvement,” in Processing Letters, vol. 41, no. 5, pp. 253-256,
Proceedings of International Conference on 1992.
[19] San-Segundo P., “New Decision Rules for Exact
Signal Processing Systems, Singapore, pp. 302-
306, 2009. Search in n-Queens,” Journal of Global
[7] Draa A., Meshoul S., Talbi H., and Batouche M., Optimization, vol. 51, no. 3, pp. 497-514, 2011.
“A Quantum-Inspired Differential Evolution [20] Sloane N., “The Online Encyclopedia of Integer
Algorithm for Solving the n-Queens Problem,” Sequences,” available at:
the International Arab Journal of Information http://oeis.org/A000170, last visited 2012.
Technology, vol. 7, no. 1, pp. 21-27, 2010. [21] Talbi E., Metaheuristics from Design to
[8] Homaifar A., Turner J., and Ali S., “The n- Implementation, John Wiley & Sons, USA, 2009.
Queens Problem and Genetic Algorithms,” in [22] Tong L., Wang C., and Chen H., “Optimization
Proceedings of IEEE Southeastcon, Birmingham, of Multiple Responses Using Principal
USA, vol. 1, pp. 262-267, 1992. Component Analysis and Technique for Order
[9] Hwang C. and Yoon K., Multiple Attribute Preference by Similarity to Ideal Solution,”
Decision Making-Method and Applications, A International Journal of Advance Manufacturing
State-of-the-Art Survey, Springer-Verlag, New and Technology, vol. 27, no. 3-4, pp. 407-414,
York, USA, 1981. 2005.
[10] Jagota A., “Optimization by Reduction to [23] Yang X., Nature-Inspired Metaheuristic
Maximum Clique,” in Proceedings of IEEE Algorithms, Luniver Press, UK, 2010.
International Conference on Neural Networks,
Solving the n-Queens Problem Using a Tuned Hybrid Imperialist Competitive Algorithm 559

Ellips Masehian is an assistant


professor at the Faculty of
Engineering, Tarbiat Modares
University, Iran. He received his
BSc and MSc degrees in industrial
engineering, both from Iran
University of Science and
Technology, Tehran, with honors, and a PhD degree
from Tarbiat Modares University in 2004. His research
is focused on applications of heuristic, metaheuristic
and intelligent methods to combinatorial optimization,
as well as single and multiple robot motion planning
problems. He has served in Editorial Boards of a
number of journals as member, reviewer, and guest
editor, and has been in steering and program
committees of many international conferences.

Hossein Akbaripour received his


BSc degree in engineering in 2010
from the University of Tabriz and a
MSc degree in industrial engineering
in 2012 from Tarbiat Modares
University. He has ranked first in
both undergraduate and graduate
levels. He is currently a PhD. student at Sharif
University of Technology, Iran. He has authored a
number of journal and conference papers in the fields
of combinatorial optimization and heuristic and
metaheuristic algorithms.

Nasrin Mohabbati-Kalejahi
received her BSc in industrial
engineering from University of
Tabriz, Iran, in 2010 and her MSc in
industrial engineering from
Amirkabir University of Technology,
Iran, in 2013 with a thesis titled
“Transportation scheduling in supply
chain environment with considering the maximum
supply of demand”. Her research interests include
applied operation research, mathematical
programming, sequencing and scheduling, heuristic
and metaheuristic algorithms, and supply chain
management.
Copyright of International Arab Journal of Information Technology (IAJIT) is the property of
Colleges of Computing & Information Society and its content may not be copied or emailed
to multiple sites or posted to a listserv without the copyright holder's express written
permission. However, users may print, download, or email articles for individual use.

You might also like