The n queens problem Many solutions to a classic problem: On an n x n chess board, place n queens so no queen threatens another.

Slides:



Advertisements
Similar presentations
Informed search algorithms
Advertisements

Local Search Algorithms
Local Search Jim Little UBC CS 322 – CSP October 3, 2014 Textbook §4.8
Local Search Algorithms Chapter 4. Outline Hill-climbing search Simulated annealing search Local beam search Genetic algorithms Ant Colony Optimization.
1 Finite Constraint Domains. 2 u Constraint satisfaction problems (CSP) u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized.
Adversarial Search We have experience in search where we assume that we are the only intelligent being and we have explicit control over the “world”. Lets.
Problem Solving by Searching Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 3 Spring 2007.
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
The N-Queens Problem lab01.
1 Solving problems by searching Chapter 3. 2 Why Search? To achieve goals or to maximize our utility we need to predict what the result of our actions.
Problem Solving by Searching
Local search algorithms
Local search algorithms
Two types of search problems
Problem Solving by Searching Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 3 Spring 2004.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
1 Chapter 5 Advanced Search. 2 Chapter 5 Contents l Constraint satisfaction problems l Heuristic repair l The eight queens problem l Combinatorial optimization.
Search I Tuomas Sandholm Carnegie Mellon University Computer Science Department [Read Russell & Norvig Chapter 3]
Local Search and Stochastic Algorithms Solution tutorial 4.
1 Chapter 5 Advanced Search. 2 l
1 Solving problems by searching Chapter 3. 2 Why Search? To achieve goals or to maximize our utility we need to predict what the result of our actions.
1 Adversary Search Ref: Chapter 5. 2 Games & A.I. Easy to measure success Easy to represent states Small number of operators Comparison against humans.
Busby, Dodge, Fleming, and Negrusa. Backtracking Algorithm Is used to solve problems for which a sequence of objects is to be selected from a set such.
D Goforth - COSC 4117, fall Note to 4 th year students  students interested in doing masters degree and those who intend to apply for OGS/NSERC.
Lecture 17: Spanning Trees Minimum Spanning Trees.
Solving Problems by Searching CPS Outline Problem-solving agents Example problems Basic search algorithms.
Shortest Route, Minimal Spanning Tree and Maximal Flow Models
Vlad Furash & Steven Wine.  Problem surfaced in 1848 by chess player Max Bezzel as 8 queens (regulation board size)  Premise is to place N queens on.
Minimum Spanning Trees
Local Search CPSC 322 – CSP 5 Textbook §4.8 February 7, 2011.
Lecture 2: General Problem-Solving Methods. Greedy Method Divide-and-Conquer Backtracking Dynamic Programming Graph Traversal Linear Programming Reduction.
Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.
1 Chapter 5 Advanced Search. 2 Chapter 5 Contents l Constraint satisfaction problems l Heuristic repair l The eight queens problem l Combinatorial optimization.
1 Shanghai Jiao Tong University Informed Search and Exploration.
Informed search algorithms Chapter 4. Best-first search Idea: use an evaluation function f(n) for each node –estimate of "desirability"  Expand most.
Search by partial solutions.  nodes are partial or complete states  graphs are DAGs (may be trees) source (root) is empty state sinks (leaves) are complete.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Fall 2006 Jim Martin.
Local Search Pat Riddle 2012 Semester 2 Patricia J Riddle Adapted from slides by Stuart Russell,
1 Solving problems by searching 171, Class 2 Chapter 3.
Feng Zhiyong Tianjin University Fall  Best-first search  Greedy best-first search  A * search  Heuristics  Local search algorithms  Hill-climbing.
Local search algorithms In many optimization problems, the state space is the space of all possible complete solutions We have an objective function that.
Backtracking & Brute Force Optimization Intro2CS – weeks
Introduction to State Space Search
Chapter 5. Advanced Search Fall 2011 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.
Chapter 3.5 and 3.6 Heuristic Search Continued. Review:Learning Objectives Heuristic search strategies –Best-first search –A* algorithm Heuristic functions.
Lecture 2: Problem Solving using State Space Representation CS 271: Fall, 2008.
Constraints in Evolutionary Algorithms. Constraints: the big questions, page 233  how to evaluate and compare feasible and infeasible solutions  avoid,
Eight Queens Problem The problem is to place 8 queens on a chess board so that none of them can attack the other. A chess board can be considered a plain.
Constraints Satisfaction Edmondo Trentin, DIISM. Constraint Satisfaction Problems: Local Search In many optimization problems, the path to the goal is.
Local search algorithms In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution State space = set of "complete"
CSG3F3/ Desain dan Analisis Algoritma
Introduction to Artificial Intelligence
Sit-In Lab 1 Ob-CHESS-ion
Artificial Intelligence Lecture No. 6
Problem Solving by Searching
CS 188: Artificial Intelligence
The A* Algorithm Héctor Muñoz-Avila.
Back Tracking.
Branch and Bound.
The n queens problem Many solutions to a classic problem:
Chapter 5. Advanced Search
Russell and Norvig: Chapter 3, Sections 3.1 – 3.3
Solving problems by searching
CSE (c) S. Tanimoto, 2002 State-Space Search
Search.
CSE (c) S. Tanimoto, 2004 State-Space Search
Search.
Solving problems by searching
Instructor: Kris Hauser
Solving Problems by Searching
Presentation transcript:

The n queens problem Many solutions to a classic problem: On an n x n chess board, place n queens so no queen threatens another

Minimal example – 4 queens 4 x 4 Board Queen threatens next piece in any row, column or diagonal Problem: Place 4 queens so no queen is threatened

What kind of problem? Design state space for search nodes – how to represent state edges – what transformations to neighbouring state e.g., state: positions of four queens edge: move any queen to new position

Possible state spaces Every state has four queens: Neighbour state has one queen in different position

Start state is undecided: Random? Guess based on knowledge? Form of graph – all states are potential solutions Edges for neighbour relationship are undirected formulation

How many states?  Any queen anywhere: 16 4 = 65536(n 2 ) n  Queens on different squares: 16x15x14x13 = 43680n 2 !/(n 2 -n)!  Queens in separate columns: 4 4 = 256n n  Queens in separate cols, rows: 4x3x2x1 = 24n!

1. Complete state formulation What actions, branching factor  Move a queen anywhere: 4x16 = 64n x n 2  Move queen to open space: 4x12 = 48n x (n 2 -n)  Move queen in column: 4x3 = 12n x (n-1)  Exchange rows of two queens: 4x3/2 = 6n(n-1)/2

Fitness function: no queen threatened Operationalizing Heuristics for evaluating states: how (relatively) bad is the threat situation?  Number of unthreatened queens  Total pairwise threats Depends on the representation; e.g., need to count column threats?

Finding solution: local search repeat create random state find local optimum based on fitness function heuristic (e.g.,max number of unthreatened queens) until fitness function satisfied

Partial-solution spaces Every state has 0,1,2,3 or 4 queens Edges lead to states with one more queen

Start state is fixed: Empty board Form of graph – hierarchical, directed, multi-partite Actions/changes are directed edges that add one more queen into destination state Partial state formulation

How many states?  Any queen anywhere:  i=0,n (n 2 ) i = (c/w 65536)  Any queen on empty square: (43680)  i=0,n n 2 !/(n 2 -n)!  Queens in separate columns: 341 (256)  i=0,n n i  Queens in separate rows/cols: 40 (24)  i=1,n n!/(n-i)!

How many neighbours: branching factor  Place a queen anywhere: 4x4 = 16n 2  Place queen on open space: 12 < b ≤ 16n(n-1)<b≤n 2  Place queen in column: 4n  Place queen in col, row: 0 < b ≤ 4 0 < b ≤ n Partial state formulation

Heuristics for evaluating states: is there a threat? e.g., Total pairwise threats:0 0 Number of unthreatened spaces1 2 Partial state formulation

Search is globally controlled – spanning tree - Better for ‘optimizing’ - finding multiple solutions and choosing best Partial formulation

Complete / incremental? How many states? Branching factor? Heuristic evaluation of fitness? Example algorithm from Peter Alfeld Analyze this algorithm

Example algorithm from Peter Alfeld Complete / incremental? How many states? Branching factor? Heuristic evaluation? Incremental O( Σ i= 0,n n i ) n No conflict

An O(n) algorithmic solution ACM SIGART Bulletin, 2(2), page 22-24, finds one arrangement of queens solution by Marty Hall based on this algorithm: O(n) algorithm