n -queens via relaxation labeling

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

Upload: macy

Post on 11-Jan-2016

63 views

Category:

Documents


0 download

DESCRIPTION

N -Queens via Relaxation Labeling. Ilana Koreh ( 307247262 ) Luba Rashkovsky ( 308820695 ). N -Queens problem. Place N queens on a NxN chessboard, so that no queens can take each other. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: N -Queens via  Relaxation Labeling

1

NN-Queens via -Queens via Relaxation Relaxation LabelingLabeling

Ilana Koreh ( 307247262 )

Luba Rashkovsky ( 308820695 )

Page 2: N -Queens via  Relaxation Labeling

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.

Page 3: N -Queens via  Relaxation Labeling

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.

Page 4: N -Queens via  Relaxation Labeling

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

Page 5: N -Queens via  Relaxation Labeling

5

Examples of solution for this Examples of solution for this problemproblem

4 Queens 6 Queens5 Queens

Page 6: N -Queens via  Relaxation Labeling

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

Page 7: N -Queens via  Relaxation Labeling

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

Page 8: N -Queens via  Relaxation Labeling

8

Relaxation Labeling Relaxation Labeling AlgorithmAlgorithm

and and NN-Queens Problem -Queens Problem

Page 9: N -Queens via  Relaxation Labeling

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.

Page 10: N -Queens via  Relaxation Labeling

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

Page 11: N -Queens via  Relaxation Labeling

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

Page 12: N -Queens via  Relaxation Labeling

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.

Page 13: N -Queens via  Relaxation Labeling

13

SimulatorSimulator

• Running the algorithm on different Ns.

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

• Show visual and textual results of each iteration.

• Statistics

Page 14: N -Queens via  Relaxation Labeling

14

DemoDemo

Page 15: N -Queens via  Relaxation Labeling

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

Page 16: N -Queens via  Relaxation Labeling

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.

Page 17: N -Queens via  Relaxation Labeling

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).

Page 18: N -Queens via  Relaxation Labeling

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.

Page 19: N -Queens via  Relaxation Labeling

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.

Page 20: N -Queens via  Relaxation Labeling

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.

Page 21: N -Queens via  Relaxation Labeling

21

The End.The End.