Search.

Slides:



Advertisements
Similar presentations
BackTracking Algorithms
Advertisements

State Space 3 Chapter 4 Heuristic Search. Three Algorithms Backtrack Depth First Breadth First All work if we have well-defined: Goal state Start state.
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
Branch and Bound Optimization In an exhaustive search, all possible trees in a search space are generated for comparison At each node, if the tree is optimal.
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.
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Branch & Bound Algorithms
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Chapter 8, Part I Graph Algorithms.
Graph Search Methods Spring 2007 CSE, POSTECH. Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. A search method.
Graph Algorithms Mathematical Structures for Computer Science Chapter 6 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesGraph Algorithms.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move.
State Space Search 2 Chapter 3 Three Algorithms. Backtracking Suppose We are searching depth-first No further progress is possible (i.e., we can only.
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.
1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree.
Using Search in Problem Solving
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Blind Search-Part 2 Ref: Chapter 2. Search Trees The search for a solution can be described by a tree - each node represents one state. The path from.
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.
Using Search in Problem Solving
Ch 13 – Backtracking + Branch-and-Bound
1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
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.
Backtracking.
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.
Solving Problems by Searching CPS Outline Problem-solving agents Example problems Basic search algorithms.
Dr. Jouhaina Chaouachi Siala
Artificial Intelligence Lecture 9. Outline Search in State Space State Space Graphs Decision Trees Backtracking in Decision Trees.
Lecture 5: Backtracking Depth-First Search N-Queens Problem Hamiltonian Circuits.
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.
BackTracking CS335. N-Queens The object is to place queens on a chess board in such as way as no queen can capture another one in a single move –Recall.
Contents of Chapter 7 Chapter 7 Backtracking 7.1 The General method
Graph Traversal BFS & DFS. Review of tree traversal methods Pre-order traversal In-order traversal Post-order traversal Level traversal a bc d e f g hi.
Search exploring the consequences of possible actions.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
1 Branch and Bound Searching Strategies Updated: 12/27/2010.
COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Algorithms April-May 2013 Dr. Youn-Hee Han The Project for the Establishing the Korea ㅡ Vietnam College of Technology in Bac Giang.
1 Solving problems by searching Chapter 3. Depth First Search Expand deepest unexpanded node The root is examined first; then the left child of the root;
Ricochet Robots Mitch Powell Daniel Tilgner. Abstract Ricochet robots is a board game created in Germany in A player is given 30 seconds to find.
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
Ch22.Branch and Bound.
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
February 11, 2016Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 1 State-Space Graphs There are various methods for searching.
Branch and Bound Searching Strategies
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
Brute Force II.
Chapter 6 Branch & Bound (B & B).
BackTracking CS255.
Depth-First Search N-Queens Problem Hamiltonian Circuits
A vertex u is reachable from vertex v iff there is a path from v to u.
Backtracking And Branch And Bound
Csc 2720 Instructor: Zhuojun Duan
Design and Analysis of Algorithm
Search
Backtracking And Branch And Bound
Analysis and design of algorithm
Back Tracking.
Branch and Bound Searching Strategies
Backtracking and Branch-and-Bound
Unit –VII Coping with limitations of algorithm power.
Backtracking And Branch And Bound
Lecture 4: Tree Search Strategies
Presentation transcript:

Search

Outline Problem space/ State space Exhaustive search Backtracking Depth-first search Breadth-first search Backtracking Branch-and-bound Jaruloj Chongstitvatana Search

Problem Space or State Space

Problem Space General problem statement Given a problem instance P, find answer A=(a1, a2, …, an) such that the criteria C(A, P) is satisfied. Problem space of P is the set of all possible answers A. Jaruloj Chongstitvatana Search

Example: Shortest path Given a graph G=(V,E), and nodes u and v, find the shortest path between u and v. General problem statement Given a graph G and nodes u and v, find the path (u, n1, n2, …, nk, v), and (u, n1, n2,…, nk, v) is the shortest path between u and v. Problem space Set of all possible path between u and v. {(u, n1, n2, …, nk, v)| ni is in V, for 1ik}. Jaruloj Chongstitvatana Search

Example: 0/1 Knapsack Given a set S of n objects, where the object i has value vi and weight wi , and a knapsack with weight capacity C, find the maximum of value of objects in S which can be put in the knapsack. General problem statement Given vi and wi , for 1  i  n , find the set K such that for each i in K, 1  i  n,  vi is maximum while  wi  C. iK iK Problem space Any subset of S. Jaruloj Chongstitvatana Search

Example: n Queens Given an nxn board, find the n squares in the board to put n queens so that no pair can attack. General problem statement Find (p1, p2, …, pn) where pi = (xi, yi) is a square on the board, where there is no pair (xi, yi) and (xj, yj) such that xi = xj or yi = yj. Problem space A set of any n positions on the board. Jaruloj Chongstitvatana Search

Exhaustive Search

Exhaustive Search Generate every possible answer Test each answer with the constraint to find the correct answer Inefficient because the number of answers in the problem space can be exponential. Examples: Shortest path n! paths to be considered, where n is the number of nodes. 0/1 Knapsack 2n selections, where n is the number of objects. n Queens n2!/n! (n2-n)! Jaruloj Chongstitvatana Search

State-Space Tree Let (a1, a2, …, an) be a possible answer. Suppose ai is either 0 or 1, for 1  i  nใ (?, …, ?) (0, ?, …, ?) (1, ?, …, ?) (0, 0, ?, …, ?) (0, 1, ?, …, ?) (1, 0,?, …, ?) (1, 1, ?, …, ?) (0,0,0, …, ?) (0,0,1, …, ?) (0,1,0, …, ?) (0,1,1, …, ?) Jaruloj Chongstitvatana Search

State-Space Tree: Shortest Path 8 (1) 3 5 2 5 2 (1,2) (1,3) 1 1 -6 -1 (1,2,3) (1,2,4) (1,3,4) (1,3,5) 2 2 4 (1,2,3,4) (1,2,3,5) (1,2,4,5) (1,3,4,5) (1,2,3,4,5) Jaruloj Chongstitvatana Search

Generating Possible Paths Let {1,2,3, …, n} be a set of nodes and E[i][j] is the weight of the edge between node i and j. path(p) last = last node in the path p for next = 1 to n do np = p if next is not in np and E[last][next] != 0 then np = np || next path(np) else return Jaruloj Chongstitvatana Search

State-Space Tree : 0/1 Knapsack Given a set of objects o1, …, o5. { } {1} {2} {3} {4} {5} {1,2} {1,3} {1,4} {1,5} {1,2,3} {1,2,4} {1,2,5} {1,3,4} {1,3,5} {1,4,5} {1,2,3,4} {1,2,3,5} {1,2,4,5} {1,3,4, 5} {1,2,3,4,5} Jaruloj Chongstitvatana Search

State-Space Tree : n Queen Jaruloj Chongstitvatana Search

Depth-first Search Traverse the tree from root until a leaf is reached. Then, traverse back up to visited the next unvisited node. depthFirst(v) visited[v] = 1 for each node k adjacent to v do if not visited[k] then depthFirst(k) Jaruloj Chongstitvatana Search

0/1 Knapsack: Depth-first Search Global: maxV=0 maxSack={} DFknapsack(sack, unchosen) for each object p in unchosen do unchosen=unchosen-{p} sack=sack U {p} val=evaluate(sack) if unchosen is empty ► A leaf is reached. then maxV=max(maxV, val) if maxV=val then maxSack=sack return else DFknapsack(sack, unchosen) Jaruloj Chongstitvatana Search

Breadth-first Search Traverse the tree from root until the nodes of the same depth are all visited. Then, visited the node in the next level. breadthFirst(v) Q = empty queue enqueue(Q, v) visited[v] = 1 while not empty (Q) do u = dequeue(Q) for each node k adjacent to u do if not visited[k] then visited[k] = true enqueue(Q, k) Jaruloj Chongstitvatana Search

0/1 Knapsack: Breadth-first Search BFknapsack Q = empty queue maxV=0 sack = { } unchosen = set of all objects enqueue(Q, <sack, unchosen>) while not empty (Q) do <sack, unchosen> = dequeue(Q) if unchosen is not empty then for each object p in unchosen do enqueue(Q,<sackU{p}, unchosen-{p}>) else maxV = max(maxV, evaluate(sack)) if maxV=evaluate(sack) then maxSack = sack Jaruloj Chongstitvatana Search

Backtracking

Backtracking Reduce the search by cutting down some branches in the tree Jaruloj Chongstitvatana Search

0/1 Knapsack: Backtracking {} 0,0 Sack Current weight, current value Node {1} 2,5 {2} 1,4 {3} 3,8 {4} 2,7 {1,2} 3,9 {1,3} 5,13 {1,4} 4,12 {2,3} 4,12 {2,4} 3,11 {3,4} 5,15 object weight value 1 2 5 4 3 8 7 {2,3,4} 6,19 {1,2,3} 6, 17 {1,2,4} 5, 16 Capacity = 5 Jaruloj Chongstitvatana Search

0/1 Knapsack: Backtracking BTknapsack(sack, unchosen) for each object p in unchosen do unchosen=unchosen-{p} if p can be put in sack then sack = sack U {p} ► Backtracking occurs when p cannot be put in sack. val=evaluate(sack) if unchosen is empty ► A leaf is reached. then maxV=max(maxV, val) maxSack=sack return else BTknapsack(sack, unchosen) Jaruloj Chongstitvatana Search

Branch-and-Bound

Branch-and-bound Use for optimization problems An optimal solution is a feasible solution with the optimal value of the objective function. Search in state-space trees can be pruned by using bound. Jaruloj Chongstitvatana Search

State-Space Tree with Bound Jaruloj Chongstitvatana Search

Branch and Bound From a node N: If the bound of N is not better than the current overall bound, terminate the search from N. Otherwise, If N is a leaf node If its bound is better than the current overall bound, update the overall bound and terminate the search from N. Otherwise, terminate the search from N. Otherwise, search each child of N. Jaruloj Chongstitvatana Search

0/1 Knapsack: Branch-and-Bound Global: OvBound=0 BBknapsack(sack, unchosen) if bound(sack, unchosen)>OvBound ► Estimated bound can be better than the overall bound. then for each object p in unchosen do unchosen=unchosen-{p} if p can be put in sack then sack = sack U {p} ► Backtracking occurs when p cannot be put in sack. val=evaluate(sack) if unchosen is empty ► A leaf is reached. then maxV = max(maxV, val) maxSack = sack OvBound = max(evaluate(sack), OvBound) return else ► A leaf is not reached. Jaruloj Chongstitvatana Search

0/1 Knapsack: Estimated bound Current value available space * best ratio value:space of unchosen objects Jaruloj Chongstitvatana Search

0/1 Knapsack: Branch-and-bound {} 20 0,0 Sack estimated bound Current weight, current value Node {1}17 2,5 {2}18 1,4 {3}16 3,8 {4}19 2,7 {1,2}16 3,9 {1,3} 13 5,13 {2,3}15.5 4,12 {2,4}16.3 3,11 {3,4}15 5,15 object weight value ratio 1 2 5 2.5 4 3 8 2.67 7 3.5 {1,2,4} 16 5, 16 Overall bound 16 Capacity = 5 Jaruloj Chongstitvatana Search

Jaruloj Chongstitvatana Search