Upload
collin-cannon
View
220
Download
0
Embed Size (px)
DESCRIPTION
Heuristically Informed Searches Explore the promising choices first Using external information saves work
Citation preview
CSCI 4310Lecture 4: Search 2 – Including A*
Book Winston Chapters 4,5,6
Heuristically Informed Searches Explore the promising choices
first
Using external information saves work
Branch-and-Bound Searching for a path from S to G We know the path S-G has
minimum distance 14. Stop expanding W
S
A C R
VQF WRE
4 3
5
92 3 4 1 7
Branch and Bound Underestimate remaining distance at
each step Book uses straight-line distance
between cities as underestimate of highway distance
Knowing this optimal solution enables bounded tree branches
Heuristic:length total path =length traveled + estimate remaining distance
Redundancy Checks Requires storing partial paths Stop expansion of S-A-E
S
A C E
VQF WRE
4 35
92 3 4 1 7
One caveat This works for episodic traversal If S-E-Q does not influence paths
from Q to the goal ie. If there is a tripwire on link E-
Q that blows the bridge from Q-R, it’s back to the drawing board
Branch & Bound + Redundancy
S
A D3 4
Total path cost
Branch & Bound + Redundancy
S
A D
DB7 8
43
Branch & Bound + Redundancy
S
A D
DB7 8 A E
43
9 6
Branch & Bound + Redundancy
S
A D
DB7 8 A E
43
9 6
C E B F1211 11 10
A* Search
Adding techniques A* includes a heuristic for
remaining distance Measure of cost to reach the goal
A* Search A* algorithm maintains 2 lists OPEN = nodes that need to be
expanded CLOSED = expanded nodes Initial Lists
OPEN = {START NODE} CLOSED = { }
A* Search f (n) = g (n) + h (n)
f(n): cost from n to goal g(n): cost to get to n h(n): estimate of least cost path
from n to goal f(n) must be maintained by each
node
Using an estimate of remaining distance and dynamic programming
Search algorithm properties Complete:
The algorithm is guaranteed to find a solution when there is one
Optimal: The algorithm finds the path with
the least cost
A* properties If h(n) never over-estimates the
cost to reach the goal from the present position
h(n) is an admissible heuristic Also sometimes called an optimistic
heuristic If h(n) is admissible, A* is
complete and optimal
A* Pathfinding Navigation Obstacle Avoidance More non-intuitive applications
8-puzzle
Heuristics for 8-puzzle h1: number of misplaced tiles
Any tile out of place must be moved at least once
h2: sum of the orthogonal distances of the tiles from goal position No tile can move diagonally city block or Manhattan distance “1” is 3 from its goal position
1 23 4 56 7 8
7 2 45 68 3 1
Heuristics for 8-puzzle h1: number of misplaced tiles h2: sum of the orthogonal distances of
the tiles from goal position
Are both heuristics admissible?
Yes1 2
3 4 56 7 8
7 2 45 68 3 1
A* search algorithmadapted from Bryan Stout, gamasutra
priorityQueue Open, list ClosedAStarSearch
// s is the start nodes.g = 0; s.h = GoalDistEstimate( s ); s.f = s.g + s.h; s.parent = null;
push s on Openwhile Open is not empty {pop node n from Open // n has the lowest fif n is a goal node construct path and return success
for each successor n' of n { // n' is a child of n in the treenewg = n.g + cost(n,n')if n' is in Open or Closed AND n'.g <= newgskipn'.parent = n; n'.g = newg;n'.h = GoalDistEstimate( n' ); n'.f = n'.g + n'.hif n' is in Closedremove it from Closedif n' is not yet in Openpush n' on Open}push n onto Closed}return failure // if no path found
When path finding goes wrong
Example path finding with A*1 2 3 4 5 6 7
8 13 14
15 16 17 18 20 21
22 27 28
29 30 31 32 33 34 35
start
goal
Example1 2 3 4 5 6 7
8 13 14
15 16 18 20 21
22 27 28
29 30 31 32 33 34
S
G
17
18 161,4 = 5 1,6 = 7
Assumptions (simplifications):
Costs 1 to move to any squareNo diagonal movesHeuristic is minimum number of orthogonal moves
OPEN = 17CLOSED =
Example1 2 3 4 5 6 7
8 13 14
15 16 17 18 20 21
22 27 28
29 30 31 32 33 34
S
G
17
18 161,4 = 5 1,6 = 7
172,5 = 7
We would not actually move hereRemember, path from S to G is not returned until the termination of the algorithm
Nodes already in open or closed list
OPEN = 18,16CLOSED = 17
Example1 2 3 4 5 6 7
8 13 14
15 16 17 18 20 21
22 27 28
29 30 31 32 33 34
S
G
17
18 161,4 = 5 1,6 = 7
172,5 = 7
15 172,7 = 9
Nodes already in open or closed list
Example1 2 3 4 5 6 7
8 13 14
15 16 17 18 20 21
22 27 28
29 30 31 32 33 34
S
G
17
18 161,4 = 5 1,6 = 7
172,5 = 7
15 172,7 = 9
8 22163,6 = 93,8 = 11
With multiple choices from 15, follow the path with theleast f value (22). Recall f is the sum of cost and heuristic
Nodes already in open or closed list
Example1 2 3 4 5 6 7
8 13 14
15 16 17 18 20 21
22 27 28
29 30 31 32 33 34
S
G
17
18 161,4 = 5 1,6 = 7
172,5 = 7
15 172,7 = 9
8 22163,6 = 93,8 = 11
15 29
4,6 = 104,7 = 11
Nodes already in open or closed list
Example1 2 3 4 5 6 7
8 13 14
15 16 17 18 20 21
22 27 28
29 30 31 32 33 34S G
17
18 161,4 = 5
Now a straight shot to the goal
1,6 = 7
172,5 = 7
15 172,7 = 9
8 22163,6 = 93,8 = 11
15 29
4,6 = 104,7 = 11
Nodes already in open or closed list
Game situations more complex
Game situations more complex May have real-time constraints Estimate (heuristic) function will
have more factors Uneven terrain Coming under enemy guns or entering
dangerous areas Weather Shortest is not always the best Go slightly longer but avoid minefield
A* performs well in these situations
Why heuristic underestimates Overestimates can cause us to
miss good paths We can wander away from good
paths permanently, as we believe they are worse than they actually are
Why heuristic underestimates Estimating every path as 0 is an
underestimate, but… This is just breadth-first search We do not gain any performance
Why heuristic underestimates Admissible heuristics just
guarantee optimality We would also like performance
improvement
A* Considerations Problem is much harder in a
continuous environment Optimizations almost always find a
way to reduce the continuous space into a few discrete choices for consideration
Reduce the branching factor Limit the number of choices you have
at each decision step
Improvements Transforming the Search Space
Usually easier to clean up your search space than tweak your algorithm
Have a scripted opening sequence This is very common in Chess Reduce the space by following a
known good opening
Improvements Transforming the Search Space
Increase granularity in pathfinding
Ex: rather than step-by-step from an address in Denton to an address in Brazil
First country by country