Prabhas Chongstitvatana 1 Backtracking Eight queens problem 1 try all possible C 64 8 = 4,426,165,368 2 never put more than one queen on a given row, vector.

Slides:



Advertisements
Similar presentations
DS.GR.14 Graph Matching Input: 2 digraphs G1 = (V1,E1), G2 = (V2,E2) Questions to ask: 1.Are G1 and G2 isomorphic? 2.Is G1 isomorphic to a subgraph of.
Advertisements

Chapter Matrices Matrix Arithmetic
1 Finite Constraint Domains. 2 u Constraint satisfaction problems (CSP) u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized.
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
5-1 Chapter 5 Tree Searching Strategies. 5-2 Satisfiability problem Tree representation of 8 assignments. If there are n variables x 1, x 2, …,x n, then.
Branch & Bound Algorithms
Data Structures Using C++
Mathematics. Matrices and Determinants-1 Session.
Maths for Computer Graphics
Branch and Bound Searching Strategies
6 - 1 § 6 The Searching Strategies e.g. satisfiability problem x1x1 x2x2 x3x3 FFF FFT FTF FTT TFF TFT TTF TTT.
Branch and Bound Similar to backtracking in generating a search tree and looking for one or more solutions Different in that the “objective” is constrained.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
CS420 lecture ten BACKTRACK. Solution vectors In optimization problems, or more general in search problems, a set of choices are to be made to arrive.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
1 Branch and Bound Searching Strategies 2 Branch-and-bound strategy 2 mechanisms: A mechanism to generate branches A mechanism to generate a bound so.
1 Matrices Rosen 6 th ed., §3.8 2 Matrices A matrix is a rectangular array of numbers.A matrix is a rectangular array of numbers. An m  n (“m by n”)
Ch 13 – Backtracking + Branch-and-Bound
5-1 Chapter 5 Tree Searching Strategies. 5-2 Breadth-first search (BFS) 8-puzzle problem The breadth-first search uses a queue to hold all expanded nodes.
Linear Programming Applications
ECE669 L10: Graph Applications March 2, 2004 ECE 669 Parallel Computer Architecture Lecture 10 Graph Applications.
MATRICES. Matrices A matrix is a rectangular array of objects (usually numbers) arranged in m horizontal rows and n vertical columns. A matrix with m.
Lecture 17: Spanning Trees Minimum Spanning Trees.
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Branch & Bound UPPER =  LOWER = 0.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.
Chapter 12 Coping with the Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
DISCRETE COMPUTATIONAL STRUCTURES CS Fall 2005.
Contents of Chapter 7 Chapter 7 Backtracking 7.1 The General method
If A and B are both m × n matrices then the sum of A and B, denoted A + B, is a matrix obtained by adding corresponding elements of A and B. add these.
Matrices Matrices A matrix (say MAY-trix) is a rectan- gular array of objects (usually numbers). An m  n (“m by n”) matrix has exactly m horizontal.
2009/9 1 Matrices(§3.8)  A matrix is a rectangular array of objects (usually numbers).  An m  n (“m by n”) matrix has exactly m horizontal rows, and.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Module #9: Matrices Rosen 5 th ed., §2.7 Now we are moving on to matrices, section 7.
1 Branch and Bound Searching Strategies Updated: 12/27/2010.
COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Prabhas Chongstitvatana1 Las Vegas algorithm The answer obtained is always correct but sometime no answer. Modified deterministic algorithm by using randomness.
Meeting 18 Matrix Operations. Matrix If A is an m x n matrix - that is, a matrix with m rows and n columns – then the scalar entry in the i th row and.
Divide and Conquer Optimization problem: z = max{cx : x  S}
Matrices Section 2.6. Section Summary Definition of a Matrix Matrix Arithmetic Transposes and Powers of Arithmetic Zero-One matrices.
An Algorithm for the Traveling Salesman Problem John D. C. Little, Katta G. Murty, Dura W. Sweeney, and Caroline Karel 1963 Speaker: Huang Cheng-Kang.
Latin squares Def: A Latin square of order n is a quadruple (R, C, S; L) where R, C and S are sets of cardinality n and L is a mapping L: R × C → S such.
Flow in Network. Graph, oriented graph, network A graph G =(V, E) is specified by a non empty set of nodes V and a set of edges E such that each edge.
Irina Utkina.  Goal is to find the optimal partitioning of machines and parts into groups (production cells, or shops), in order to minimize the inter-cell.
Matrices and Determinants
Analysis & Design of Algorithms (CSCE 321)
Chapter 13 Backtracking Introduction The 3-coloring problem
CSCE350 Algorithms and Data Structure Lecture 21 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
Branch and Bound Searching Strategies
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Paths and circuits.
A very brief introduction to Matrix (Section 2.7) Definitions Some properties Basic matrix operations Zero-One (Boolean) matrices.
MATRICES A rectangular arrangement of elements is called matrix. Types of matrices: Null matrix: A matrix whose all elements are zero is called a null.
CSG3F3/ Desain dan Analisis Algoritma
MA/CSSE 473 Day 27 Dynamic Programming Binomial Coefficients
Edit from old slide since 2000 P. Chongstitvatana 26 Nov 2010
Design and Analysis of Algorithm
Search
Algorithm Design and Analysis (ADA)
The Greedy Approach Winter-2004 Young CS 331 D&A of Algo. Greedy.
Prabhas Chongstitvatana
Back Tracking.
Graphs All tree structures are hierarchical. This means that each node can only have one parent node. Trees can be used to store data which has a definite.
Branch and Bound.
Neural Networks Chapter 4
Prabhas Chongstitvatana
The Network Simplex Method
We have the following incomplete B&B tree:
Presentation transcript:

Prabhas Chongstitvatana 1 Backtracking Eight queens problem 1 try all possible C 64 8 = 4,426,165,368 2 never put more than one queen on a given row, vector representation : each row specify which column (3,1,6,2,8,6,4,7)

Prabhas Chongstitvatana 2 (3,1,6,2,8,6,4,7) X X X X X X X X

Prabhas Chongstitvatana 3 Queen1 for i 1 = 1 to 8 do for i 2 = 1 to 8 do.... for i 3 = 1 to 8 do sol = [i 1, i 2,... i 8 ] if solution ( sol ) then write sol stop write “ there is no solution ” Num. Of positions = 8 8 = 16,777,216 (first soln after 1,299,852 )

Prabhas Chongstitvatana 4 3 Never put queen on the same row (different numbers on soln vector) Queen2 sol = initial-permutation while sol != final-permutation and not solution(sol) do sol = next-permutation if solution(sol) then write sol else write “ there is no solution ”

Prabhas Chongstitvatana 5 Permutation T[1.. n] is a global array initialize to [1,2,.. n] initial call perm(1) Perm(i) if i = n then use T else for j = i to n do exchange T[i] and T[j] perm(i+1) exchange T[i] and T[j] Number of positions 8! = 40,320 (first soln after 2830)

Prabhas Chongstitvatana 6 8-queen as tree search a vector V[1..k] of integers between 1 and 8 is k-promising, if none of the k queens threatens any of the others. A vector V is k-promising if, for every pair of integers i and j between 1 and k with i != j, we have V[i] - V[j] is-not-in {i-j, 0, j-i}. Solutions to the 8-queen correspond to vectors that are 8-promising.

Prabhas Chongstitvatana 7 Let N be the set of k-promising vectors, k: Let G = (N,A) be the directed graph such that (U,V) is-in A iff there exists an integer k, k:0..8, such that U is k-promising V is (k+1)-promising, and U[i] = V[i] for every i in [1..k]... k = 0 k = 8 Number of node < 8! (node 2057, first soln after 114 )

Prabhas Chongstitvatana 8 General Template for backtracking Backtrack ( v[1..k] )// v is k-promising vector if solution ( v ) then write v else for each (k+1)-promising vector w such that w[1..k] = v[1..k] do backtrack( w[1.. k+1] )

Prabhas Chongstitvatana 9 Branch and bound The assignment problem, n agents are to be assigned n tasks, each agent having exactly one task. If agent i, i:1..n, is assigned task j, j: 1..n, then the cost of performing this task is c ij. Given the cost matrix, the problem is to assign agents to tasks so as to minimize the total cost of executing the n tasks.

Prabhas Chongstitvatana 10 Upper bound on the answer : a:1, b:2, c:3, d:4 = = 73 Lower bound (sum smallest elements) = 58 answer [ ] a b c d

Prabhas Chongstitvatana 11 Explore a tree whose nodes correspond to partial assignment. Use lower bound to guide the search. a:1 a:2 a:3 a: * a:1 ; = 60

Prabhas Chongstitvatana a b c d

Prabhas Chongstitvatana 13 a:1 a:2 a:3 a: * a:2,b:1 a:2,b:3 a:2,b:

Prabhas Chongstitvatana 14 a:1 a:2 a:3 a: * 78 * a:2,b:1 a:2,b:3 a:2,b:4 68 * 64 * a:2,b:3,c:1,d:4 a:2,b:3,c:4,d: *

Prabhas Chongstitvatana 15 a:2 a:3 a:4 a:1 65 * 78 * a:2,b:1 a:2,b:3 a:2,b:4 68 * 64 * a:2,b:3,c:4,d:1 a:2,b:3,c:1,d:4 64 a:1,b:4 a:1,b:3 a:1,b:2 a:1,b:3,c:4,d:2 61 a:1,b:3,c:2,d:4 69* 68* 66* 65*