The n queens problem Many solutions to a classic problem:

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.
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.
Algorithm Strategies Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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.
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.
CSE 589 Applied Algorithms Spring Colorability Branch and Bound.
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.
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.
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.
1 Combinatorial Problem. 2 Graph Partition Undirected graph G=(V,E) V=V1  V2, V1  V2=  minimize the number of edges connect V1 and V2.
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
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.
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.
1 Combinatorial Problem. 2 Graph Partition Undirected graph G=(V,E) V=V1  V2, V1  V2=  minimize the number of edges connect V1 and V2.
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
The A* Algorithm Héctor Muñoz-Avila.
Back Tracking.
Branch and Bound.
Graph Searching.
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
Hard Problems Some problems are hard to solve.
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 Queen threatens next piece in any row, column or diagonal 4 x 4 Board 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

formulation 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: 164 = 65536 (n2)n Queens on different squares: 16x15x14x13 = 43680 n2!/(n2-n)! Queens in separate columns: 44 = 256 nn Queens in separate cols, rows: 4x3x2x1 = 24 n!

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

Partial state formulation 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: 160+161+162+163+164 i=0,n (n2)i = 69905 (c/w 65536) Any queen on empty square: 47296 (43680) i=0,n n2!/(n2-n)! Queens in separate columns: 341 (256) i=0,n ni Queens in separate rows/cols: 40 (24) i=1,n n!/(n-i)!

Partial state formulation How many neighbours: branching factor Place a queen anywhere: 4x4 = 16 n2 Place queen on open space: 12 < b ≤ 16 n(n-1)<b≤n2 Place queen in column: 4 n 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 spaces 1 2

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

Example algorithm from Peter Alfeld <http://www. apl. jhu Analyze this algorithm Complete / incremental? How many states? Branching factor? Heuristic evaluation of fitness?

Example algorithm from Peter Alfeld <http://www. apl. jhu Complete / incremental? How many states? Branching factor? Heuristic evaluation? Incremental O(Σi=0,n ni) n No conflict

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