Download Probability-based solution to N-Queen problem

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Inductive probability wikipedia , lookup

Transcript
ISSN: 2319-5967
ISO 9001:2008 Certified
International Journal of Engineering Science and Innovative Technology (IJESIT)
Volume 3, Issue 3, May 2014
Probability-based solution to N-Queen
problem
Madhusudan1, Rachana Rangra2
Abstract-This paper proposes the novel solution to N-Queen using CONDITIONAL PROBABILITY and BAYES
THEOREM. N-Queen problem is a type of NP-hard problem, which aims at placing the queen in n*n chessboard in such
a manner that no queen should kill another diagonally, horizontally and vertically. Earlier solutions have been provided
using ACO (ant colony optimization), Genetic algorithm and DNA Sticker algorithm. The BAYES THEOREM updates
the prior probability of theory being true to arrive at the posterior probability on the basis of given evidence, that is to find
that present position is the safe position. By applying CONDITIONAL PROBABILITY the number of safe states in the
next row with respect to the present position will be calculated. This algorithm will increase the reliability of the solution
obtained.
Index items-ACO, Bayes Theorem, DNA Sticker, Genetic Algorithm, NP–Hard Problem.
I. INTRODUCTION
N-Queen problem is a polynomial time problem defined as placing n queens on nxn chessboard, so that no
queen attacks the other n-1 queens. This problem is categorized as 4 queen,8 queen and 16 queen problems. In 8
queen problem we are given with an 8x8 chessboard and the problem definition is placing all the 8 queens on
the board such that no queen attacks each other [1].The solution state is achieved by placing these queens on the
board by different mechanism like backtracking [2],Anti Colony Optimization, DNASticker, and Genetic
Algorithm etc. [3]. In Backtracking we start with placing a given queen on the board and then check the safes
tates and repeat the algorithm till no safe states are left for the rest of the queens. When there are no safe states
we backtrack by removing the last placed queen and again try to find the safe states by altering its position. If no
safe state is discovered then we move back to the queen who resulted in the unsafe state for the rest of the
queens. This algorithm generally works on a set of safe states and unsafe states. A safe state is defined as a
position on the board where a queen can be placed without any danger, and an unsafe state is apposition where
no queen can be placed since it is attacked by some other queen [4].Similarly the 4 queen and 16 queen
problems are defined with 4x4chessboard and 16x16 chessboards respectively with the problem definition and
solution state definition being the same. Solution to n queen problem by ACO is such that we need to find the
shortest path from source to destination with the condition that no two positions should be marked on one row.
The idea is derived from the behavior of ant colony [5]. To apply ACO on n queen problem there are slight
modifications. The vertices in search space are organized as
rows * n column grid. Every vertex in a column
is connected to all vertices in the next column through directed edges, except vertices in the nth column. An ant
during a tour visits only „n‟ nodes (8 for 8-queen).The label of nodes in the tour cannot be the same. The node in
a tour represents a cell of chessboard where a queen is to be placed. This restriction is added as if two nodes
have same labels then 02 queens will be placed in same cell which is illegal. This essentially means that no two
nodes in a tour will be in the same row of the search space [5]. We are proposing a solution to the given n queen
problem using conditional probability and Bayes theorem.
II. OBJECTIVES OF THE STUDY
To study the existing solutions to the n queen problem and implement the probability theory to find a feasible
solution that is reliable and consumes less time and space.
III.
PROPOSED SOLUTION
In mathematical science probability is defined as the measure of occurrence of any event. The value of
probability lies between 0 and 1 where 0 designates no occurrence of that event and 1 designates the total
occurrence of that event. For example in a throw of die, the probability of occurrence of any of the number is
1/6. We are interested in the likelihood of an event which is defined as the favorable occurrence. Greater the
value of likelihood better will be the solution [6].
The second concept used is that of conditional probability. In this case we find the probability of a given event
on the basis of previous event. This is generally used when the events are dependent on the occurrence of some
426
ISSN: 2319-5967
ISO 9001:2008 Certified
International Journal of Engineering Science and Innovative Technology (IJESIT)
Volume 3, Issue 3, May 2014
other events. For example, if there is head then a die will be thrown else a coin will be tossed. So the probability
of throwing a die is ½ and that of toss is also ½.The Bayes theorem defines the occurrence of an event A based
on the occurrence of the events E1, E2, E3and so on [7].
P (A|E1) =
We proposed a solution using Conditional Probability and Bayes Theorem, for the given nxn chessboard. We
find the probability of the safe states on the basis of placing a queen in the previous row/column. In the first
row, since there is no danger, we can place the queen at any position. Then on the basis of the placement, we
find the no of safe states and probability of safe states for the next row along with the maximum number of safe
states for (n-2) queens. We discuss it with the help of 4x4. Let us assume that Q1, Q2, Q3, Q4 be the positions
in which the queens will be placed in future after finding the complete solution.
Procedure:-Starting from the Row 1, since there is no danger and all the columns have equal probability that is
0.25, we can assume that queen is placed in any position which is Column 1, Column 2, Column 3,and Column
4.
Step A: Assuming that in future the queen is placed in position Q1 (Column1 of Row 1) as shown in Fig.1.Now
we calculate the number of safe states in the Row 2 corresponding to the position Q1.
Q1
S1
S2
Fig 1. Number of safe states for Q1 position
The shaded portion indicates the unsafe states for the next position with respect to position Q1.As the Fig.1,
indicates only two unshaded cells for Row 2.
The number of safe states left are 2(S1 and S2)
Probability of each safe states = 1/4= 0.25
Since the probability of safe state is same for both Column 3(S1) and Column 4(S2) in Row 2 with respect to
position Q1.
A.1
We can move further by assuming that the second queen will be placed in the position (Q2) (Column 2
of Row 2) as shown in Fig.2, which is the safe state (S1) in Row 2 with respect to position Q1.Now we
calculate the number of safe states in Row 3 with respect to position Q2 in Row 2.
Q1
Q2
427
S2
ISSN: 2319-5967
ISO 9001:2008 Certified
International Journal of Engineering Science and Innovative Technology (IJESIT)
Volume 3, Issue 3, May 2014
Fig 2. Number of safe states for Q2 position
The shaded portion indicates the unsafe states for next position with respect to position Q2.As the Fig.2,
indicates no unshaded cells for row 3.
The number of safe states left is 0.
Probability of safe states =0.
A.2
If we assume that the second queen will be placed in position Q21(Column 4 of Row 2) as shown in
Fig.3 ,which is the safe state (S2) in Row 2 with respect to position Q1.Calculating the number of safe states in
Row 3 with respect to position Q21 in Row 2.
Q1
Q21
S3
Fig 3. Number of safe states for Q21 position
The shaded portion indicates the unsafe states for next position with respect to position Q21. The Fig.3,
indicates one unshaded cell in row 3 (S3).
The Number of safe state left for Third queen=1(S3).
Probability of safe state=1/4=0.25
A.2.1 Since we are left with only one safe state (S3) for third queen, we assume that next position of queen
will be Q3 (Column 2 of Row 3) as shown in Fig.4.
Q1
Q2
Q3
Fig 4. Number of safe states for Q3 position
428
ISSN: 2319-5967
ISO 9001:2008 Certified
International Journal of Engineering Science and Innovative Technology (IJESIT)
Volume 3, Issue 3, May 2014
The shaded portion indicates the unsafe states for next position with respect to position Q3. The Fig.4 indicates
no unshaded cell in row 4 which indicates no safe state.
The number of safe states left Fourth Queen=0
Probability of safe sate=0.
Step B: Assuming that in future the queen is placed in position Q1( Column 2 of Row 1) as shown in Fig.5.
Now we calculate the number of safe states in the Row 2 corresponding to the position Q1.
Q1
S1
Fig 5. Number of safe states for Q1 position
The shaded portion indicates the unsafe states for the position of next queen in Row 2 with respect to position
Q1.From the Fig.5, we can see that only one unshaded cell is left (S1).
The number of safe states left for Second queen =1(S1)
Probability of safe states = ¼=0.25
B.1
Since we are left with only one safe state (S2) for second queen, we assume that next safe position of
queen will be Q2 (Column 4 of Row 2) as shown in Fig.6. Calculating the number of safe sates for next queen in
Row 3 corresponding to position Q2.
Q1
Q2
.
S2
Fig 6. Number of safe states for Q2 position
The shaded portion indicates the unsafe states for the placement of next queen in Row 3 with respect to position
Q2.The above Fig.6 shows only one unshaded cell remaining (S2).
429
ISSN: 2319-5967
ISO 9001:2008 Certified
International Journal of Engineering Science and Innovative Technology (IJESIT)
Volume 3, Issue 3, May 2014
The number of safe states left for Third queen =1(S2)
Probability of safe states = ¼=0.25
B.2
We move further by assuming that the third queen will be placed in the position Q3(Column 1of Row
3) as shown in Fig.7, which is the safe state (S2) with respect to position Q2.Calculating the number of safe
sates for next queen in Row 4 corresponding to position Q3 in Row 3.
Q1
Q2
Q3
S3
Fig 7. Number of safe states for Q3 position
The shaded portion indicates the unsafe states for the placement of next queen in Row 4 with respect to position
Q3.The above Fig.7 shows only one unshaded cell remaining (S3).
The no of safe states left for Fourth queen =1(S3)
Probability of safe states = ¼=0.25
B.3
Since we are left with only one safe state S3 for the fourth queen, hence we assume that the last queen
will be placed in position Q4 (Column 3 of Row 4) as shown in Fig.8, which is the safe state(S3) with respect to
position Q3 in Row 3.
Place the queen Q4 in state S3 (Column 3, row4).
Q1
Q2
Q3
Q4
Fig 8. Position of 4 queens
Step C: Assuming that in future the queen is placed in position Q1 (Column 3 of Row 1) as shown in Fig.9.
Now we calculate the number of safe states in the Row 2 corresponding to the position Q1.
430
ISSN: 2319-5967
ISO 9001:2008 Certified
International Journal of Engineering Science and Innovative Technology (IJESIT)
Volume 3, Issue 3, May 2014
Q1
S1
Fig 9. Number of safe states for Q1 position
The shaded portion indicates the unsafe states for the position of next queen in Row 2 with respectto position
Q1.From the Fig.9. We can see that only one unshaded cell is left (S1).
The number of safe states left for Second queen =1(S1)
Probability of safe states = ¼=0.25
C.1
Since we are left with only one safe state (S1) for second queen, we assume that next safe position of
queen will be Q2(Column 1 of Row 2) as shown in Fig.10. Calculating the number of safe sates for next queen
in Row 3 corresponding to position Q2
Q1
Q2
S2
Fig 10. Number of safe states for Q2 position
The shaded portion indicates the unsafe states for the placement of next queen in Row 3 with respect to position
Q2.The above Fig. 10 shows only one unshaded cell remaining (S2).
The number of safe states left for Third queen =1(S2)
Probability of safe states = ¼=0.25
431
ISSN: 2319-5967
ISO 9001:2008 Certified
International Journal of Engineering Science and Innovative Technology (IJESIT)
Volume 3, Issue 3, May 2014
C.2
We move further by assuming that the third queen will be placed in the position Q3(Column 4 of Row
3) as shown in Fig.11, which is the safe state (S2) with respect to position Q2.Calculating the number of safe
sates for next queen in Row 4 corresponding to position Q3 in Row 3.
Q1
Q2
Q3
S3
Fig 11. Number of safe states for Q3 position
The shaded portion indicates the unsafe states for the placement of next queen in Row 4 with respect to position
Q3.The above Fig.11 shows only one unshaded cell remaining (S3).
The number of safe states left for Fourth queen =1(S3)
Probability of safe states = ¼=0.25
C.3
Since we are left with only one safe state S3 for fourth queen, hence we assume that the last queen will
be placed in position Q4 (Column 2 of Row 4) as shown in Fig.12, which is the safe state(S3) with respect to
position Q3in Row 3
Place the queen Q4 in state S3(Column 3, row4).
Q1
Q2
Q3
Q4
Fig 12. Position of 4 queen
Step D: Assuming that in future the queen is placed in position Q1(Column 4 of Row 1) as shown in Fig.13
.Now we calculate the number of safe states in the Row 2 corresponding to the position Q1.
432
ISSN: 2319-5967
ISO 9001:2008 Certified
International Journal of Engineering Science and Innovative Technology (IJESIT)
Volume 3, Issue 3, May 2014
Q1
S1
S2
Fig 13. Number of safe states for Q1 position
The shaded portion indicates the unsafe states for the placement of next queen with respect to position
Q1.Fig.13 indicates only two unshaded cells remaining.
The number of safe states left are 2(S1 and S2)
Probability of each safe state=1/4=0.25
Since the probability of safe state is same for both Column 1(S1) and Column 2(S2) in Row 2 with respect to
position Q1
D.1.
We can move further by assuming that the second queen will be placed in position Q2(Column 1 of
Row 2) as shown in Fig.14, which is the safe state (S1) in Row 2 with respect to position Q1.Now Calculate the
number of safe states in Row 3 with respect to position Q2 in Row 2.
Q1
Q2
S2
S3
Fig 14. Number of safe states for Q2 position
The shaded portion indicates the unsafe states for next position with respect to position Q2.As we can see from
the Fig.14 only one unshaded cell is left in row 3.
The number of safe states left for Third Queen is 1(S3)
Probability of safe states =1/4=0.25.
D.1.1. Since we are left with only one safe state (S3) for third queen, we assume that next position of queen
will be Q3 (Column 3 for Row 3) as shown in Fig.15.
433
ISSN: 2319-5967
ISO 9001:2008 Certified
International Journal of Engineering Science and Innovative Technology (IJESIT)
Volume 3, Issue 3, May 2014
Q1
Q2
S2
Q3
Fig 15. Number of safe states for Q3 position
The shaded portion indicates the unsafe states for next position with respect to position Q3.As we can see from
the Fig.15 there is no unshaded portion left in row 4 which indicates no safe state.
Q1
S1
Q21
Fig 16. Number of safe states for Q21 position
The number of safe states left Fourth Queen=0
Probability of safe sate=0.
D.2.
If we assume that the second queen will be placed in position Q21(Column 2 of Row 2) as shown in
Fig.16, which is the safe state (S2) in Row 2 with respect to position Q1.Calculating the number of safe states in
Row 3 with respect to position Q21 in Row 2
The shaded portion indicates the unsafe states for next position with respect to position Q21.As we can see from
the Fig.16 there is no unshaded cellleft in row 3.
The Number of safe state left for Third queen=0
Probability of safe state=0
IV.RESULTS
I.
Probability table for Row 1 Column 1
Row
Column
2
4
No of
safe
state
1
434
Probability
Of safe
state
0.25
ISSN: 2319-5967
ISO 9001:2008 Certified
International Journal of Engineering Science and Innovative Technology (IJESIT)
Volume 3, Issue 3, May 2014
3
2
1
0.25
No of
safe
state
Probability
Of safe state
II. Probability table for Row 1 Column 1
`
Row
Column
2
3
1
0.25
Probability
Of safe
state
0.25
III. Probability table for Row 1 Column 2
2
4
No of
safe
state
1
3
1
1
0.25
4
3
1
0.25
Row
Column
IV. Probability table for Row 1 Column 3
Row
Column
2
1
No of safe
state
1
Probability
Of safe state
0.25
3
4
1
0.25
4
2
1
0.25
V. Probability table for Row 1 Column 4
Row
Column
2
2
No of
safe
state
1
Probability
Of safe state
0.25
VI. Probability table for Row 1 Column 4
Row
Column
2
1
3
3
No of
safe
state
1
1
Probability
Of safe
state
0.25
0.25
VII. Total probability of safe states for each column in Row 1
Table I
Table II
Table III
Table IV
Table V
Table VI
0.50
0.25
0.75
0.75
0.25
0.50
435
ISSN: 2319-5967
ISO 9001:2008 Certified
International Journal of Engineering Science and Innovative Technology (IJESIT)
Volume 3, Issue 3, May 2014
Feasible solution:-We will choose the set of columns which maximizes the total probability of safe states. From
the above table we can find that the maximum probability of safe states is given by Column 2 and Column 3
that is 0.75.
The solution set is given by following combination of columns
i)2, 4, 1, 3
ii)3, 1, 4, 2
V. CONCLUSION & FUTURE SCOPE
The solution we proposed provides a reliable and time efficient results to the 4 queen problem, and the solution
can be spanned for any values of n except n=2 and n=3.Calculating the total probability of all the safe states for
the present state, and then selecting the solution set with the maximum total probability, provides the set of safe
states for the N-Queen problem. Contrary to placing the queen and then checking for the safe state, we first
search for all the safe states with their probability and then chooses the set of safe states which has highest
probability.
REFERENCES
[1] Prabhakar. Gupta, Vineet.Agarwal and Manish.Varshney, “Design and Analysis of Algorithms”, Second Edition, PHI
Learning Private Ltd., 2012.
[2] Elaine. Rich, Kevin. Knight and Shivashankar.Nair, “Artificial Intelligence”, McGraw Hill Education, Third Edition,
2009.
[3] S.Pothumani, “Solving N Queen Problem Using Various Algorithms-A Survey”, IJARCSSE, Vol. 3, Issue 2, Feb 2013.
[4] Prabhakar. Gupta, Vineet. Agarwal and Manish.Varshney, “Design and Analysis of Algorithms”, Second Edition, PHI
Learning Private Ltd., 2012.
[5] Salabat.Khan, Mohsin.Bilal, M.Sharif, Malik. Sajid and Rauf.Baig, “Solution of n-Queen Problem Using ACO”, In
Proceedings of Multitopic Conference, 2009. INMIC 2009, IEEE 13th International Source: IEEE Xplore.
[6] Dan W. Patterson, “Introduction to Artificial Intelligence and Expert Systems”, PHI Learning Private Ltd., Reprint
1990.
[7] Dan W. Patterson, “Introduction to Artificial Intelligence and Expert Systems”, PHI Learning Private Ltd., Reprint
1990.
436