1 problem solving using search brute-force search heuristic search competitive search
TRANSCRIPT
![Page 1: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/1.jpg)
1
Problem Solving Using Search
Brute-force searchHeuristic searchCompetitive search
![Page 2: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/2.jpg)
Search 2
Copyright P. Doerschuk
Search cont.
Many problems can only be solved by searching
![Page 3: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/3.jpg)
Search 3
Copyright P. Doerschuk
Importance of efficient search algorithms
Tic tac toe state space of 9!:
9 possible first moves, followed by 8 possible second moves, followed by 7 possible third moves, etc., or 9x8x7x…x1 moves or 9!
Can use exhaustive searchChess
10120 possible paths
can’t use exhaustive search
![Page 4: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/4.jpg)
Search 4
Copyright P. Doerschuk
State Space Search
use a state space graph to represent the problem each node represents a partial solution state each arc represents transition between states
can be directed or undirected
tree - a graph in which 2 nodes have at most one path between them (no loops or cycles)
state space search - find a solution path from the start state to a goal state
![Page 5: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/5.jpg)
Search 5
Copyright P. Doerschuk
traveling salesperson
Fig 3.7O(N!) ; actually (N-1)!
![Page 6: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/6.jpg)
Search 6
Copyright P. Doerschuk
Tree-based search
tree representation is often used to search for a path from the initial state to the goal state (Ex: eights puzzle)
number of possible states: 9!
1 2 3 1 2 3
4 8 5 4 5 6
7 6 7 8
Initial state Goal state
![Page 7: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/7.jpg)
Search 7
Copyright P. Doerschuk
Eights puzzle state tree
1 2 34 8 57 6
1 2 3 1 2 3 1 2 34 8 5 4 5 4 8 5
7 6 7 8 6 7 6
![Page 8: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/8.jpg)
Search 8
Copyright P. Doerschuk
Graph search vs tree search
General graph search algorithm must detect and eliminate loops; this is done by ensuring that a state is only examined once
trees don’t need to do this because they don’t have loops
![Page 9: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/9.jpg)
Search 9
Copyright P. Doerschuk
Unguided (blind) search
does not use heuristic information during the search process
depth first search examines all descendants of a node before the nodes at the same level are examined
breadth-first search examines all nodes at a given level before the nodes of the descendants
![Page 10: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/10.jpg)
Search 10
Copyright P. Doerschuk
Unguided (blind) search cont.
Breadth first algorithm:1. create a queue and add the first node to it2. Loop:
If the queue is empty, quit.Remove the first node from the queue.If the node contains the goal state, exit with the node as the solution.For each child of the current node:
Add the new state (no duplicates) to the back of the queue.
![Page 11: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/11.jpg)
Search 11
Copyright P. Doerschuk
Breadth-first search
ABCDEFGHIJKL
QUEUE:
A
BC
CDE
DEFG
EFGHI
FGHIJK
GHIJKLM
HIJKLMNO
IJKLMNO
JKLMNO
KLMNO
LMNO
![Page 12: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/12.jpg)
Search 12
Copyright P. Doerschuk
Unguided (blind) search cont.
depth first algorithm:1. create a queue and add the first node
to it2. Loop:
If the queue is empty, quit.Remove the first node from the queue.If the node contains the goal state, exit with the node as the solution.For each child of the current node:
Add the new state (no duplicates) to the front of the queue.
![Page 13: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/13.jpg)
Search 13
Copyright P. Doerschuk
Depth-first search
ABDHIEJKCFL
QUEUE:
A
BC
DEC
HIEC
IEC
EC
JKC
KC
C
FG
LMG
...
![Page 14: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/14.jpg)
Search 14
Copyright P. Doerschuk
Breadth first vs depth first
Breadth firstguaranteed to find the shortest pathspace inefficient
• all unexpanded nodes for each level are kept in the queue
• if average branching factor is B, have Bn states on level n (root is level 0)
• if solution path is long or B is large, memory requirements large
depth firstnot guaranteed to find shortest pathspace efficient
• at each level, keeps only the children of a single node in the queue (B*n) states at level n
![Page 15: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/15.jpg)
Search 15
Copyright P. Doerschuk
Unguided (blind) search cont.
Depth-first search with iterative deepening perform depth-first search up to a maxDepth control loop continually deepens depth-first
search more efficient than breadth-first and depth-first
on large search spaces Russell and Norvig 1995
time behavior is the same as depth-first and breadth-first search: O(Bn)
Note: all unguided search techniques have worst case exponential time behavior
![Page 16: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/16.jpg)
Search 16
Copyright P. Doerschuk
Using state space to represent reasoning with predicate calculus
Use and/or graphs to represent implications of the form pqr
p q
r
![Page 17: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/17.jpg)
Search 17
Copyright P. Doerschuk
Two methods of searching graph: data-driven: find path from known true
facts to goal goal directed: start with the proposition
to be proved (the goal) and search backwards along arcs to find support for the goal among the true propositions
![Page 18: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/18.jpg)
Search 18
Copyright P. Doerschuk
Examples: p. 110, fig 3.21p. 112, fig 3.23financial advisor fig 3.24sentence parser p. 116, fig 3.25
![Page 19: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/19.jpg)
Search 19
Copyright P. Doerschuk
Guided (heuristic) search
uses additional information, often in the form of estimates, to guide the search
![Page 20: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/20.jpg)
Search 20
Copyright P. Doerschuk
Guided (heuristic) search cont.
hill-climbing each node has an associated value or
cost; move to the node with the highest value (or lowest cost)
uses no memory and backtracking can only find local maximum (minimum)
![Page 21: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/21.jpg)
Search 21
Copyright P. Doerschuk
Ex: Traveling Salesperson
Fig. 3.9
![Page 22: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/22.jpg)
Search 22
Copyright P. Doerschuk
Guided (heuristic) search cont.
Best-first algorithm:1. create a queue and add the first node to it2. Loop:
If the queue is empty, quit.Remove the first node from the queue.If the node contains the goal state, exit with the node as the solution.For each child of the current node:
if the child has not yet been visited or the child is reached by a path of lower cost than when visited previously, add the child node to the queue, in order of cost, eliminating any other higher cost paths to this child
![Page 23: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/23.jpg)
Search 23
Copyright P. Doerschuk
Guided (heuristic) search cont
Heuristic evaluation function may be the sum of two components: f(n) = g(n) + h(n)
g(n) measures cost from the start state to state n
h(n) estimates cost from state n to goal state
![Page 24: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/24.jpg)
Search 24
Copyright P. Doerschuk
Guided (heuristic) search cont
for the eight puzzle, g(n) = the number of moves from start to the
current state. H1(n) = the number of tiles that are out of
place; H2(n) = the sum of the Manhattan distances
(horizontal and vertical distances) for the tiles that are out of place
![Page 25: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/25.jpg)
Search 25
Copyright P. Doerschuk
Guided (heuristic) search cont.
A* searchuse evaluation function
f(n)=g(n)+h(n)where h(n) <=h*(n) //h*(n) is actual minimum cost from n to
goal
![Page 26: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/26.jpg)
Search 26
Copyright P. Doerschuk
Shortest path problem
Find the shortest path from a start node to a goal node
must keep track of paths and costs of paths
reject paths with loopsfor the shortest path problem, g(n) is the
total distance between the initial state and the state n, and h(n) is the estimated distance from state n to the goal state
A* also eliminates the more costly of redundant paths
![Page 27: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/27.jpg)
Search 27
Copyright P. Doerschuk
Shortest path problem cont.
A* shortest path algorithm1. create a queue and add the first node to it as a zero-length
path.2. Loop:
If the queue is empty, quit and announce failure.Remove the first path from the queue. If it ends at the goal
state, exit with this path as the solution. Otherwise, create new paths by extending the first path to all the neighbors of the terminal node.
Reject all new paths with loops.If two or more paths reach a common node, delete all those
paths except the one that reaches the common node with the minimum cost.
Sort the entire queue by the sum of the path length and a lower bound estimate of the cost remaining, with least-cost paths in front.
![Page 28: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/28.jpg)
Search 28
Copyright P. Doerschuk
Example: TSP
![Page 29: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/29.jpg)
Search 29
Copyright P. Doerschuk
Ex: robot path planning
P. 94-99, Winston 3rd Edition
![Page 30: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/30.jpg)
Search 30
Copyright P. Doerschuk
Competitive (Game) Search
Used for competitive gamesuses a move generator, a position
evaluator and a look-ahead strategygame states are represented as a
treeinitial state is the rootthe player (computer) is the
maximizer, and the opponent is the minimizer; 'minimax' search
![Page 31: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/31.jpg)
Search 31
Copyright P. Doerschuk
'minimax' search cont.
example: tic-tac-toeevaluation function measures the
number of rows/columns/diagonals open to the player versus the opponent:
E(s) = H(s) = (rX + cX + dX) - (ro + co + do)
![Page 32: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/32.jpg)
Search 32
Copyright P. Doerschuk
'minimax' search cont.
alpha beta pruning prunes branches which are not needed
lower bound alpha is the largest current value of all the MAX ancestors of the node
upper bound beta is the smallest current value of all its MIN ancestors
X tries to maximize alpha at each MAX level; O tries to minimize beta at each MIN level
![Page 33: 1 Problem Solving Using Search Brute-force search Heuristic search Competitive search](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649ccf5503460f9499b603/html5/thumbnails/33.jpg)
Search 33
Copyright P. Doerschuk
Summary
Search methods unguided
depth first, breadth first
guidedhill climbingbest firstA*
competitiveminimax