1 N -Queens via Relaxation Labeling Ilana Koreh ( 307247262 ) Luba Rashkovsky ( 308820695 )

21
1 N N -Queens via -Queens via Relaxation Relaxation Labeling Labeling Ilana Koreh ( 307247262 ) Luba Rashkovsky ( 308820695 )

Transcript of 1 N -Queens via Relaxation Labeling Ilana Koreh ( 307247262 ) Luba Rashkovsky ( 308820695 )

1

NN-Queens via -Queens via Relaxation Relaxation LabelingLabeling

Ilana Koreh ( 307247262 )

Luba Rashkovsky ( 308820695 )

2

NN-Queens problem-Queens problem

• Place N queens on a NxN chessboard, so that no queens can take each other.

• Queens can move horizontally, vertically, and diagonally only one queen can stand per row and per column and no two queens can find themselves on the same diagonal.

• Computationally expensive problem - NP-Complete.

3

Naïve Solution for Naïve Solution for NN--QueensQueens

• Building a search tree, where each node represents a valid position of a queen on the chessboard.

• Nodes at the first level correspond to one queen on the board. Nodes at the second level represent boards containing two queens in valid locations, and so on.

• When a tree of depth N is found then we have a solution for positioning N queens on the board.

4

Queens are added on successive rows of the board, so as the search

progresses down, we cover more rows of the board. When the search reaches a leaf at the Nth level, a

solution has been found.

Partial search tree for 8-queen Partial search tree for 8-queen problemproblem

5

Examples of solution for this Examples of solution for this problemproblem

4 Queens 6 Queens5 Queens

6

Relaxation labeling Relaxation labeling algorithmalgorithm

• Relaxation labeling is a general name for group of methods for assigning labels to set of objects using contextual constraints.

• Works with set of objects - Each object should get one of the possible labels -

• Initialization of this algorithm sets value for each object labeled by each label. This value is the measured confidence that object should be labeled by label .

bb nB ,...,

1

m,...,2,1

pi

0

bi

im

i

i

p

p

1

0

1

0

0

7

Formulas used by the Formulas used by the algorithmalgorithm

- the strength of compatibility between hypotheses " has label " and “ has label “.

For each iteration the algorithm calculates the support for label for object :

Update rule – probability for labeling object with label

Average Local Consistency of the assignment -

,r ijbi b j

bi

mk

i

k

i

k

i

k

ik

i

sp

spp

1

1

n

j

m

jiji prs1 1

,

bi

i

ii sppA

8

Relaxation Labeling Relaxation Labeling AlgorithmAlgorithm

and and NN-Queens Problem -Queens Problem

9

• Relaxation labeling algorithm - vision world

• N-Queens problem - computer science world

• This project is an implementation of reduction from algorithm from vision world to problem from other world.

10

The ReductionThe Reduction

• Objects the queens, what means the algorithm will work with N objects.

• Labels assignments of queens. The labels that will be choose by the algorithm, will determine does the problem has consistent solution.

• for the first queen we choose the assignment randomly. This label will get the highest probability.

All other queens will get some label (also randomly)

that is consistent with the first queen.

pi

0

11

The Reduction (cont)The Reduction (cont)

• this value between queen i and queen j, calculated accordingly to the given constraints for N-Queens problem.

• the “stop” condition of the algorithm.

,r ij

otherwise 0

consistent are sassignment two those1,r ij

pA

12

How do we decide what will How do we decide what will be the assignment for the be the assignment for the

queensqueens??• For each queen we choose the best label.

• This label is the assignment this queen will get.

• Best label is chosen by maximal probability for each queen. In case that there are more than one label that got same probability, best label will be chosen randomly.

13

SimulatorSimulator

• Running the algorithm on different Ns.

• Running “step by step” or “until convergence”.

• Show visual and textual results of each iteration.

• Statistics

14

DemoDemo

15

ResultsResults• Running of the simulator for different Ns (from 4

to 15), 100 problems for each.

N-Queens via Relaxation Labeling on 100 problems

0

20

40

60

80

100

120

0 2 4 6 8 10 12 14 16

N (number of queens)

Nu

mb

er

of

so

lved

pro

ble

ms

16

• As N increases, the number of solved problems decreases. The main reason for this is different purpose of the two problems (will be explained in "Problems" part).

• As N increases, the time to converge (or solving) the problem increases also.

17

ProblemsProblems

1. Different purposes of two algorithms

N-Queens - find consistent solution. The algorithm should stop when it finds at least one consistent solution.

Relaxation Labeling - find some assignments of labels to objects, such that the solution will converge to max average local consistency.

This difference causes to the relaxation labeling algorithm to stop (when it converges) even if current assignment of labels to queens doesn't make consistent solution (in terms of N-Queens problem).

18

Problems - contProblems - cont

2. In N-Queens problem, each object is affected by all other objects. In that case, the support for assignment of label to queen can be very high (if it consistent with most of the queens), even if it doesn't consistent with all the queens.

When the support is high, there is no reason for the relaxation labeling algorithm to change the probability for next iteration, and the problem can converge, but in terms of N-Queens the solution doesn't consistent.

19

Problems - contProblems - cont

3. Many possibilities for equal values Relaxation labeling algorithm don't handle this problem. We solved this problem by using the random method (but maybe it's not the best method).

4. Solution != ConvergenceSolution of the problem doesn't means convergence for the relaxation labeling, so the algorithm will continue running, even if the solution was found.

5. Random in C# - not really random.

20

ConclusionConclusion

• For make a decision if relaxation labeling algorithm is good for the N-Queens problem, many another experiments should be done.

• Probably Relaxation labeling algorithm not the best choice algorithm for solving N-Queens problem. Solving it with backtracking methods gave much better results. But for being sure, many additional experiments are needed.

21

The End.The End.